/** * Set the hydrator to use when binding an object to the element * * @param HydratorInterface $hydrator * @return FieldsetInterface */ public function setHydrator(HydratorInterface $hydrator) { if ($this->baseFieldset !== null) { $this->baseFieldset->setHydrator($hydrator); } return parent::setHydrator($hydrator); }
/** * Prepare and inject a named hydrator * * Takes a string indicating a hydrator class name (or a concrete instance), instantiates the class * by that name, and injects the hydrator instance into the form. * * @param string $hydratorOrName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException If $hydratorOrName is not a string, does not resolve to a known class, or * the class does not implement Hydrator\HydratorInterface */ protected function prepareAndInjectHydrator($hydratorOrName, FieldsetInterface $fieldset, $method) { if (is_object($hydratorOrName) && $hydratorOrName instanceof Hydrator\HydratorInterface) { $fieldset->setHydrator($hydratorOrName); return; } if (!is_string($hydratorOrName)) { throw new Exception\DomainException(sprintf('%s expects string hydrator class name; received "%s"', $method, is_object($hydratorOrName) ? get_class($hydratorOrName) : gettype($hydratorOrName))); } $sm = $this->getServiceManager(); if ($sm->has($hydratorOrName)) { $hydrator = $sm->get($hydratorOrName); } else { if (class_exists($hydratorOrName)) { $hydrator = new $hydratorOrName(); } else { throw new Exception\DomainException(sprintf('%s expects string hydrator name to be a valid class name or service; received "%s"', $method, $hydratorOrName)); } } if (!$hydrator instanceof Hydrator\HydratorInterface) { throw new Exception\DomainException(sprintf('%s expects a valid implementation of Zend\\Form\\Hydrator\\HydratorInterface; received "%s"', $method, $hydratorOrName)); } $fieldset->setHydrator($hydrator); }
/** * Prepare and inject a named hydrator * * Takes a string indicating a hydrator class name (or a concrete instance), try first to instantiates the class * by pulling it from service manager, and injects the hydrator instance into the form. * * @param string|array|Hydrator\HydratorInterface $hydratorOrName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException If $hydratorOrName is not a string, does not resolve to a known class, or * the class does not implement Hydrator\HydratorInterface */ protected function prepareAndInjectHydrator($hydratorOrName, FieldsetInterface $fieldset, $method) { if ($hydratorOrName instanceof Hydrator\HydratorInterface) { $fieldset->setHydrator($hydratorOrName); return; } if (is_array($hydratorOrName)) { if (!isset($hydratorOrName['type'])) { throw new Exception\DomainException(sprintf('%s expects array specification to have a type value', $method)); } $hydratorOptions = isset($hydratorOrName['options']) ? $hydratorOrName['options'] : array(); $hydratorOrName = $hydratorOrName['type']; } else { $hydratorOptions = array(); } if (is_string($hydratorOrName)) { $hydrator = $this->getHydratorFromName($hydratorOrName); } if (!$hydrator instanceof Hydrator\HydratorInterface) { throw new Exception\DomainException(sprintf('%s expects a valid implementation of Zend\\Form\\Hydrator\\HydratorInterface; received "%s"', $method, $hydratorOrName)); } if (!empty($hydratorOptions) && $hydrator instanceof Hydrator\HydratorOptionsInterface) { $hydrator->setOptions($hydratorOptions); } $fieldset->setHydrator($hydrator); }
/** * Prepare and inject a named hydrator * * Takes a string indicating a hydrator class name, instantiates the class * by that name, and injects the hydrator instance into the form. * * @param string $hydratorName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException if $hydratorName is not a string, does not resolve to a known class, or the class does not implement Hydrator\HydratorInterface */ protected function prepareAndInjectHydrator($hydratorName, FieldsetInterface $fieldset, $method) { if (!is_string($hydratorName)) { throw new Exception\DomainException(sprintf('%s expects string hydrator class name; received "%s"', $method, is_object($hydratorName) ? get_class($hydratorName) : gettype($hydratorName))); } if (!class_exists($hydratorName)) { throw new Exception\DomainException(sprintf('%s expects string hydrator name to be a valid class name; received "%s"', $method, $hydratorName)); } $hydrator = new $hydratorName(); if (!$hydrator instanceof Hydrator\HydratorInterface) { throw new Exception\DomainException(sprintf('%s expects a valid implementation of Zend\\Form\\Hydrator\\HydratorInterface; received "%s"', $method, $hydratorName)); } $fieldset->setHydrator($hydrator); }