[fw-core] Testing if a Zend_Form instance is bound.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[fw-core] Testing if a Zend_Form instance is bound.

Carlton Gibson-2
I have a Service which accepts a Zend_Form instance as a parameter. Here $form is meant to have been validated prior to being passed to Service class. This basically looks like this:

$form = new MyForm();
if ($request->isPost() && $form->isValid($request->getPost())) {
    $service = new MyService($form);

What I'd like to do is check this precondition within the MyService constructor. e.g. perhaps:

    public function __construct(Zend_Form $form)
         if (!$form->isValid()) {
                throw new Exception('Passed form must be bound with valid data');
         $this->_form = $form;

However, Zend_Form::isValid() expects a single parameter -- it can't be used to check against already set data.

-- What I don't was to do is inject the form's data source into the Service class, so my current thinking is to subclass Zend_Form to provide the check I need, but I'm wondering if anyone has any good thoughts on the matter?

List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]