Ideally, I would like to do something like this ....
$formElement->addValidator ( (new RegexValidator('/[az]/') )->setErrorMessage('Error') // setErrorMessage() returns $this );
Of course, PHP will not allow this, so I agree to this ...
$formElement->addValidator ( RegexValidator::create('/[az]/')->setErrorMessage('Error') );
And the code in the base class ....
static public function create( $value ) { return new static( $value ); }
I would like to take one more step and do something like this ...
static public function create() { return call_user_func_array( 'static::__construct', func_get_args() ); }
Again, PHP won't let me do this. I could code individual "create" methods for each validator, but I want it to be a little smoother.
Any suggestions please?
source share