Пример #1
0
 /**
  * Fetch the hydrator and hydrate the object using the given values
  *
  * @param  string $hydratorName
  * @param  object $object
  * @param  array  $values
  * @return object
  */
 public function __invoke($hydratorName, $object, array $values)
 {
     /** @var \Zend\Stdlib\Hydrator\HydratorInterface $hydrator */
     $hydrator = $this->hydratorPluginManager->get($hydratorName);
     $object = $hydrator->hydrate($values, $object);
     return $object;
 }
 /**
  * Map an entity class to a specific hydrator instance
  *
  * @param  string $class
  * @param  ExtractionInterface $hydrator
  * @return self
  */
 public function addHydrator($class, $hydrator)
 {
     if (!$hydrator instanceof ExtractionInterface) {
         $hydrator = $this->hydrators->get($hydrator);
     }
     $filteredClass = strtolower($class);
     $this->hydratorMap[$filteredClass] = $hydrator;
     return $this;
 }
Пример #3
0
    /**
     * Set the hydrator to use with this class
     *
     * @param  string|ExtractionInterface $hydrator
     * @return self
     * @throws Exception\InvalidArgumentException if the class or hydrator does not implement ExtractionInterface
     */
    public function setHydrator($hydrator)
    {

        if (is_string($hydrator)) {
            if (null !== $this->hydrators
                && $this->hydrators->has($hydrator)
            ) {
                $hydrator = $this->hydrators->get($hydrator);
            } elseif (class_exists($hydrator)) {
                $hydrator = new $hydrator();
            }
        }
        
        if (!$hydrator instanceof ExtractionInterface) {
            if (is_object($hydrator)) {
                $type = get_class($hydrator);
            } elseif (is_string($hydrator)) {
                $type = $hydrator;
            } else {
                $type = gettype($hydrator);
            }
            throw new Exception\InvalidArgumentException(sprintf(
                'Hydrator class must implement Zend\Stdlib\Extractor\ExtractionInterface; received "%s"',
                $type
            ));
        }
        $this->hydrator = $hydrator;
        return $this;
    }
Пример #4
0
 /**
  * Map a resource class to a specific hydrator instance
  *
  * @param  string $class
  * @param  HydratorInterface $hydrator
  * @return RestfulJsonRenderer
  */
 public function addHydrator($class, $hydrator)
 {
     if (!$hydrator instanceof HydratorInterface) {
         if (!$this->hydrators->has((string) $hydrator)) {
             throw new Exception\InvalidArgumentException(sprintf('Invalid hydrator instance or name provided; received "%s"', is_object($hydrator) ? get_class($hydrator) : (is_string($hydrator) ? $hydrator : gettype($hydrator))));
         }
         $hydrator = $this->hydrators->get($hydrator);
     }
     $class = strtolower($class);
     $this->hydratorMap[$class] = $hydrator;
     return $this;
 }
Пример #5
0
    /**
     * @param HydratorPluginManager $hydratorPluginManager
     * @return FacilityHydrator
     */
    public function __invoke(HydratorPluginManager $hydratorPluginManager)
    {
        /** @var BaseHydrator $baseHydrator */
        $baseHydrator = $hydratorPluginManager->get('NcpBase\Hydrator\Model\Base');

        /** @var ServiceManager $serviceManager */
        $serviceManager = $hydratorPluginManager->getServiceLocator();

        /** @var ObjectManager $objectManager */
        $objectManager = $serviceManager->get('doctrine.entitymanager.ormdefault');

        return new FacilityHydrator(
            $baseHydrator,
            $objectManager
        );
    }
Пример #6
0
 public function testLoadingInvalidElementRaisesException()
 {
     $this->manager->setInvokableClass('test', get_class($this));
     $this->setExpectedException('Zend\\Stdlib\\Exception\\RuntimeException');
     $this->manager->get('test');
 }