Exemplo n.º 1
0
 /**
  * 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;
 }
 /**
  * Setup the service manager.
  */
 protected function setUp()
 {
     $this->serviceConfig = (require TEST_BASE_PATH . '/config/module.config.php');
     $this->serviceManager = new ServiceManager();
     $this->serviceManager->setAllowOverride(true);
     $this->serviceManager->setService('config', $this->serviceConfig);
     $this->serviceManager->setService('custom.strategy', $this->getMock('Zend\\Hydrator\\Strategy\\StrategyInterface'));
     $this->serviceManager->setService('custom.filter', $this->getMock('Zend\\Hydrator\\Filter\\FilterInterface'));
     $this->serviceManager->setService('custom.naming_strategy', $this->getMock('Zend\\Hydrator\\NamingStrategy\\NamingStrategyInterface'));
     $this->hydratorManager = $this->getMockBuilder(HydratorPluginManager::class)->disableOriginalConstructor()->getMock();
     $this->hydratorManager->expects($this->any())->method('getServiceLocator')->will($this->returnValue($this->serviceManager));
 }
Exemplo n.º 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\\Hydrator\\ExtractionInterface; received "%s"', $type));
     }
     $this->hydrator = $hydrator;
     return $this;
 }