/**
  * @param HydratorPluginManager $hydratorPluginManager
  * @return DoctrineObject
  */
 public function __invoke(HydratorPluginManager $hydratorPluginManager)
 {
     $serviceLocator = $hydratorPluginManager->getServiceLocator();
     /** @var DocumentManager $documentManager */
     $documentManager = $serviceLocator->get('doctrine.documentmanager.odm_default');
     return new DoctrineObject($documentManager);
 }
Пример #2
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;
 }
Пример #4
0
    /**
     * @param HydratorPluginManager $hydratorPluginManager
     * @return IdentifierHydrator
     */
    public function __invoke(HydratorPluginManager $hydratorPluginManager)
    {
        /** @var ServiceManager $serviceManager */
        $serviceManager = $hydratorPluginManager->getServiceLocator();

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

        return new IdentifierHydrator($objectManager);
    }
Пример #5
0
 /**
  * Set up
  */
 public function setUp()
 {
     $config = (require __DIR__ . '/../../config/module.config.php');
     $config['mongodb']['Mongo\\Db']['hosts'] = 'mongo:27017';
     $configSm = ArrayUtils::merge($this->config, $config['service_manager']);
     $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfig($configSm));
     $sm->setService('Config', $config);
     $hydratorManager = new HydratorPluginManager();
     $hydratorManager->setService('Strapieno\\User\\Model\\Hydrator\\Mongo\\UserModelMongoHydrator', new UserModelMongoHydrator());
     $sm->setService('HydratorManager', $hydratorManager);
 }
Пример #6
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
        );
    }
Пример #7
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;
    }
 /**
  * @test
  */
 public function it_should_be_possible_to_configure_a_custom_hydrator()
 {
     $this->serviceConfig['doctrine-hydrator']['custom-hydrator']['hydrator'] = 'custom.hydrator';
     $this->serviceManager->setService('Config', $this->serviceConfig);
     $this->hydratorManager->expects($this->once())->method('get')->with('custom.hydrator')->will($this->returnValue($this->getMock('Zend\\Stdlib\\Hydrator\\ArraySerializable')));
     $hydrator = $this->createOrmHydrator();
     $this->assertInstanceOf('Zend\\Stdlib\\Hydrator\\ArraySerializable', $hydrator->getHydrateService());
     $this->assertInstanceOf('Zend\\Stdlib\\Hydrator\\ArraySerializable', $hydrator->getExtractService());
 }
Пример #9
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;
 }
 public function setUp()
 {
     $services = $this->services = new ServiceManager();
     $elements = new FormElementManager();
     $filters = new FilterPluginManager();
     $hydrators = new HydratorPluginManager();
     $inputFilters = new InputFilterPluginManager();
     $validators = new ValidatorPluginManager();
     $elements->setServiceLocator($services);
     $filters->setServiceLocator($services);
     $hydrators->setServiceLocator($services);
     $inputFilters->setServiceLocator($services);
     $validators->setServiceLocator($services);
     $services->setService('FilterManager', $filters);
     $services->setService('FormElementManager', $elements);
     $services->setService('HydratorManager', $hydrators);
     $services->setService('InputFilterManager', $inputFilters);
     $services->setService('ValidatorManager', $validators);
     $inputFilters->setInvokableClass('FooInputFilter', 'Zend\\InputFilter\\InputFilter');
     $forms = $this->forms = new FormAbstractServiceFactory();
     $services->addAbstractFactory($forms);
 }
Пример #11
0
 public function testLoadingInvalidElementRaisesException()
 {
     $this->manager->setInvokableClass('test', get_class($this));
     $this->setExpectedException('Zend\\Stdlib\\Exception\\RuntimeException');
     $this->manager->get('test');
 }
 /**
  * @depends testCanCreateService
  * @return void
  */
 public function testCreateServiceWithOptionalManagers()
 {
     $serviceLocator = $this->serviceManager;
     //Test with optional managers
     $hydrator = new ObjectProperty();
     $hydratorManager = new HydratorPluginManager();
     $hydratorManager->setService('Zend\\Stdlib\\Hydrator\\ObjectProperty', $hydrator);
     $serviceLocator->setService('HydratorManager', $hydratorManager);
     $inputFilter = new InputFilter();
     $inputFilterManager = new InputFilterPluginManager();
     $inputFilterManager->setService('Zend\\InputFilter\\InputFilter', $inputFilter);
     $serviceLocator->setService('InputFilterManager', $inputFilterManager);
     $objectFull = $serviceLocator->get('MyObject\\Full');
     $this->assertSame($hydrator, $objectFull->getHydrator());
     $this->assertSame($inputFilter, $objectFull->getInputFilter());
 }
 /**
  * @depends testCanCreateService
  * @return void
  */
 public function testCreateServiceWithOptionalManagers()
 {
     $serviceLocator = $this->serviceManager;
     //Test with optional managers
     $hydrator = new ObjectProperty();
     $hydratorManager = new HydratorPluginManager();
     $hydratorManager->setService('Zend\\Stdlib\\Hydrator\\ObjectProperty', $hydrator);
     $serviceLocator->setService('HydratorManager', $hydratorManager);
     $inputFilter = new InputFilter();
     $inputFilterManager = new InputFilterPluginManager();
     $inputFilterManager->setService('Zend\\InputFilter\\InputFilter', $inputFilter);
     $serviceLocator->setService('InputFilterManager', $inputFilterManager);
     $domainObject = new DomainObject();
     $objectManager = new ObjectManager();
     $objectManager->setService('DomainObject', $domainObject);
     $serviceLocator->setService('Matryoshka\\Model\\Object\\ObjectManager', $objectManager);
     $modelFull = $serviceLocator->get('MyModel\\Full');
     $this->assertSame($hydrator, $modelFull->getHydrator());
     $this->assertSame($inputFilter, $modelFull->getInputFilter());
     $this->assertSame($domainObject, $modelFull->getObjectPrototype());
     $listenerAggregate = $this->getMockForAbstractClass('Zend\\EventManager\\ListenerAggregateInterface', ['attach']);
     $listenerAggregate = $serviceLocator->get('ListenerAggregateMockedAsset');
     $listenerAggregate->expects($this->atLeastOnce())->method('attach')->with($this->isInstanceOf('Zend\\EventManager\\EventManagerInterface'));
     $listenerManager = new ListenerManager();
     $listenerManager->setService('ListenerAggregateMockedAsset', $listenerAggregate);
     $serviceLocator->setService('Matryoshka\\Model\\Listener\\ListenerManager', $listenerManager);
     /* @var $myModelOL \Matryoshka\Model\ObservableModel */
     $myModelOL = $serviceLocator->get('MyModel\\OL');
 }
Пример #14
0
 public function testCanCreateFormsAndSpecifyHydratorManagedByHydratorManager()
 {
     $hydrators = new HydratorPluginManager();
     $services = $this->factory->getFormElementManager()->getServiceLocator();
     $hydrators->setServiceLocator($services);
     $services->setService('HydratorManager', new HydratorPluginManager());
     $form = $this->factory->createForm(array('name' => 'foo', 'hydrator' => 'ObjectProperty'));
     $this->assertInstanceOf('Zend\\Form\\FormInterface', $form);
     $hydrator = $form->getHydrator();
     $this->assertInstanceOf('Zend\\Stdlib\\Hydrator\\ObjectProperty', $hydrator);
 }