예제 #1
0
 /**
  * Prepare and inject a named factory
  *
  * Takes a string indicating a factory class name (or a concrete instance), try first to instantiates the class
  * by pulling it from service manager, and injects the factory instance into the fieldset.
  *
  * @param  string|array|Factory      $factoryOrName
  * @param  FieldsetInterface         $fieldset
  * @param  string                    $method
  * @return void
  * @throws Exception\DomainException If $factoryOrName is not a string, does not resolve to a known class, or
  *                                   the class does not extend Form\Factory
  */
 protected function prepareAndInjectFactory($factoryOrName, FieldsetInterface $fieldset, $method)
 {
     if (is_array($factoryOrName)) {
         if (!isset($factoryOrName['type'])) {
             throw new Exception\DomainException(sprintf('%s expects array specification to have a type value', $method));
         }
         $factoryOrName = $factoryOrName['type'];
     }
     if (is_string($factoryOrName)) {
         $factoryOrName = $this->getFactoryFromName($factoryOrName);
     }
     if (!$factoryOrName instanceof Factory) {
         throw new Exception\DomainException(sprintf('%s expects a valid extention of Zend\\Form\\Factory; received "%s"', $method, $factoryOrName));
     }
     $fieldset->setFormFactory($factoryOrName);
 }