コード例 #1
0
ファイル: Metadata.php プロジェクト: jbarentsen/drb
    /**
     * 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;
    }
コード例 #2
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;
 }