コード例 #1
0
 public function testApplyWithNoIdAndData()
 {
     $request = new Request();
     $config = $this->createConfiguration(null, array());
     $objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->manager->expects($this->never())->method('find');
     $this->manager->expects($this->once())->method('getManager')->will($this->returnValue($objectManager));
     $this->setExpectedException('LogicException');
     $this->converter->apply($request, $config);
 }
コード例 #2
0
 /**
  * Stores the object in the request.
  *
  * @param Request        $request       The request
  * @param ParamConverter $configuration Contains the name, class and options of the object
  *
  * @return bool    True if the object has been successfully set, else false
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $class = $configuration->getClass();
     $site = $this->siteManager->getSite();
     if (!$site) {
         throw new NotFoundHttpException(sprintf('%s object not found.', $class));
     }
     if ($request->attributes->get($name, false) === null) {
         return false;
     }
     if ($name !== 'site') {
         $request->attributes->set('site', $site->getId());
     }
     if (parent::apply($request, $configuration) === false) {
         return false;
     }
     $object = $request->attributes->get($name);
     if (!$object) {
         throw new NotFoundHttpException(sprintf('%s object not found.', $class));
     }
     if (!$object instanceof SiteBoundInterface) {
         return false;
     }
     if ($object instanceof SiteBoundInterface && !$object->checkSite($site)) {
         throw new NotFoundHttpException(sprintf('%s object not found.', $class));
     }
     return true;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  *
  * @throws \LogicException       When unable to guess how to get a Doctrine instance from the request information
  * @throws NotFoundHttpException When object not found
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     try {
         return parent::apply($request, $configuration);
     } catch (NotFoundHttpException $e) {
         throw new NotFoundHttpException('Product does not exists');
     }
 }
コード例 #4
0
 public function apply(Request $request, ParamConverter $configuration)
 {
     if ($request->isMethod('POST') && !empty($configuration->getOptions()['request_path'])) {
         $requestPath = $configuration->getOptions()['request_path'];
         $request->attributes->set($requestPath, $request->request->get($requestPath));
     } elseif ($request->isMethod('GET') && !empty($configuration->getOptions()['query_path'])) {
         $queryPath = $configuration->getOptions()['query_path'];
         $request->attributes->set($queryPath, $request->query->get($queryPath));
     }
     return parent::apply($request, $configuration);
 }
コード例 #5
0
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Repository method "Sensio\Bundle\FrameworkExtraBundle\Tests\Request\ParamConverter\TestUserRepository::findByFullName" requires that you provide a value for the "$lastName" argument.
  */
 public function testApplyWithRepositoryMethodAndMapMethodSignatureException()
 {
     $request = new Request();
     $request->attributes->set('first_name', 'Fabien');
     $request->attributes->set('last_name', 'Potencier');
     $config = $this->createConfiguration('stdClass', array('repository_method' => 'findByFullName', 'mapping' => array('first_name' => 'firstName', 'last_name' => 'lastNameXxx'), 'map_method_signature' => true), 'arg');
     $objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $objectRepository = new TestUserRepository();
     $metadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $objectManager->expects($this->once())->method('getRepository')->with('stdClass')->will($this->returnValue($objectRepository));
     $this->registry->expects($this->once())->method('getManagerForClass')->will($this->returnValue($objectManager));
     $objectManager->expects($this->once())->method('getClassMetadata')->will($this->returnValue($metadata));
     $this->converter->apply($request, $config);
 }
コード例 #6
0
 /**
  * Apply the converter
  *
  * @param  Request                $request
  * @param  ParamConverter         $configuration
  * @return boolean
  * @throws NotFoundHttpException
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $options = $this->getOptions($configuration);
     $id = $this->getIdentifier($request, $options, $name);
     if (is_array($id)) {
         $id = implode(":", $id);
     }
     try {
         return parent::apply($request, $configuration);
     } catch (NotFoundHttpException $exeption) {
         throw new NotFoundHttpException(sprintf($options['error_message'], $id));
     }
 }
コード例 #7
0
 /**
  * Stores the object in the request.
  *
  * @param Request $request The request
  * @param ParamConverter $configuration Contains the name, class and options of the object
  * @return bool True if the object has been successfully set, else false
  * @throws NotFoundHttpException
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $fullClass = $this->rm->getFullClass($configuration->getClass());
     $name = $configuration->getName();
     $resourceData = json_encode($request->request->all());
     try {
         parent::apply($request, $configuration);
         $this->deserializeResource($request, $fullClass, $resourceData, $name);
         return true;
     } catch (\LogicException $e) {
         return $this->treatDoctrineException($request, $fullClass, $resourceData, $name);
     } catch (NotFoundHttpException $e) {
         return $this->treatDoctrineException($request, $fullClass, $resourceData, $name);
     }
 }
コード例 #8
0
 /**
  * @param Request        $request
  * @param ParamConverter $configuration
  *
  * @return bool
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $fieldName = $this->getOptions($configuration)['type_field'];
     if ($fieldName) {
         $value = $request->attributes->get($fieldName);
         if (!$value) {
             throw new NotFoundHttpException(sprintf('Expected to have `%s` attribute present', $fieldName));
         }
         $className = $this->contentType->getContentTypeClass($value);
         if (null === $className) {
             throw new NotFoundHttpException(sprintf('Cannot guess page type from request: %s', $value));
         }
         $configuration->setClass($className);
     }
     return parent::apply($request, $configuration);
 }
 public function testApplyWithRepositoryMethodAndMapping()
 {
     $request = new Request();
     $request->attributes->set('id', 1);
     $config = $this->createConfiguration('stdClass', array('repository_method' => 'getClassName', 'mapping' => array('foo' => 'Foo')), 'arg');
     $objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $metadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $this->manager->expects($this->once())->method('getManager')->will($this->returnValue($objectManager));
     $objectManager->expects($this->once())->method('getClassMetadata')->will($this->returnValue($metadata));
     $metadata->expects($this->once())->method('hasField')->with($this->equalTo('Foo'))->will($this->returnValue(true));
     $objectRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $this->manager->expects($this->once())->method('getRepository')->will($this->returnValue($objectRepository));
     $objectRepository->expects($this->once())->method('getClassName')->will($this->returnValue($className = 'ObjectRepository'));
     $ret = $this->converter->apply($request, $config);
     $this->assertTrue($ret);
     $this->assertSame($className, $request->attributes->get('arg'));
 }
コード例 #10
0
ファイル: AppParamConverter.php プロジェクト: 24eme/aurouze
 public function apply(Request $request, ParamConverter $configuration)
 {
     $return = parent::apply($request, $configuration);
     if (!$return) {
         return $return;
     }
     $object = $request->attributes->get($configuration->getName());
     if ($object instanceof DocumentEtablissementInterface) {
         $request->attributes->set('etablissement', $object->getEtablissement());
     }
     if ($object instanceof DocumentSocieteInterface) {
         $request->attributes->set('societe', $object->getSociete());
     }
     if ($request->attributes->get('societe') && $request->attributes->get('societe') instanceof Societe && !$request->attributes->get('etablissement')) {
         $request->attributes->set('etablissement', $request->attributes->get('societe')->getEtablissements()->first());
     }
     return $return;
 }
コード例 #11
0
 /**
  * Stores the object in the request.
  *
  * @param Request                $request
  * @param ConfigurationInterface $configuration
  * @return bool
  * @throws AccessDeniedException When User doesn't have permission to the object
  */
 public function apply(Request $request, ConfigurationInterface $configuration)
 {
     $request->attributes->set('_oro_access_checked', false);
     $isSet = parent::apply($request, $configuration);
     if ($this->securityFacade && $isSet) {
         $object = $request->attributes->get($configuration->getName());
         if ($object) {
             $granted = $this->securityFacade->isRequestObjectIsGranted($request, $object);
             if ($granted === -1) {
                 $acl = $this->securityFacade->getRequestAcl($request);
                 throw new AccessDeniedException('You do not get ' . $acl->getPermission() . ' permission for this object');
             } elseif ($granted === 1) {
                 $request->attributes->set('_oro_access_checked', true);
             }
         }
     }
     return $isSet;
 }
コード例 #12
0
 public function testApplyWithMappingAndExclude()
 {
     $request = new Request();
     $request->attributes->set('foo', 1);
     $request->attributes->set('bar', 2);
     $config = $this->createConfiguration('stdClass', array('mapping' => array('foo' => 'Foo'), 'exclude' => array('bar')), 'arg');
     $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $metadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $this->registry->expects($this->once())->method('getManagerForClass')->with('stdClass')->will($this->returnValue($manager));
     $manager->expects($this->once())->method('getClassMetadata')->with('stdClass')->will($this->returnValue($metadata));
     $manager->expects($this->once())->method('getRepository')->with('stdClass')->will($this->returnValue($repository));
     $metadata->expects($this->once())->method('hasField')->with($this->equalTo('Foo'))->will($this->returnValue(true));
     $repository->expects($this->once())->method('findOneBy')->with($this->equalTo(array('Foo' => 1)))->will($this->returnValue($object = new \stdClass()));
     $ret = $this->converter->apply($request, $config);
     $this->assertTrue($ret);
     $this->assertSame($object, $request->attributes->get('arg'));
 }
コード例 #13
0
 /**
  * Stores the object in the request.
  *
  * @param Request $request
  * @param ConfigurationInterface $configuration
  * @return bool
  * @throws AccessDeniedException When User doesn't have permission to the object
  * @throws NotFoundHttpException When object not found
  * @throws \LogicException       When unable to guess how to get a Doctrine instance from the request information
  */
 public function apply(Request $request, ConfigurationInterface $configuration)
 {
     $request->attributes->set('_oro_access_checked', false);
     $isSet = parent::apply($request, $configuration);
     if ($isSet) {
         $object = $request->attributes->get($configuration->getName());
         $controller = $request->attributes->get('_controller');
         if ($object && strpos($controller, '::') !== false) {
             $controllerData = explode('::', $controller);
             $permission = $this->securityFacade->getClassMethodAnnotationPermission($controllerData[0], $controllerData[1]);
             if ($permission) {
                 if (!$this->securityFacade->isGranted($permission, $object)) {
                     throw new AccessDeniedException('You do not get ' . $permission . ' permission for this object');
                 } else {
                     $request->attributes->set('_oro_access_checked', true);
                 }
             }
         }
     }
     return $isSet;
 }
コード例 #14
0
ファイル: APIParamConverter.php プロジェクト: nass59/Lab
 /**
  * @param Request           $request
  * @param ParamConverter    $configuration
  *
  * @return bool
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $this->setMappingOptions($request, $configuration, 'slug');
     return parent::apply($request, $configuration);
 }