Example #1
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;
 }