public function testSupports()
 {
     $config = $this->createConfiguration('stdClass', array());
     $metadataFactory = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadataFactory');
     $metadataFactory->expects($this->once())->method('isTransient')->with($this->equalTo('stdClass'))->will($this->returnValue(false));
     $objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $objectManager->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metadataFactory));
     $this->manager->expects($this->once())->method('getManager')->with($this->equalTo('default'))->will($this->returnValue($objectManager));
     $ret = $this->converter->supports($config);
     $this->assertTrue($ret, "Should be supported");
 }
 /**
  * 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;
 }
Ejemplo n.º 3
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);
 }
 /**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     $original_class = $configuration->getClass();
     // Replace the class with our resolved class
     $configuration->setClass($this->resolveClass($original_class));
     if (parent::supports($configuration)) {
         return true;
     } else {
         // Reset our changes
         $configuration->setClass($original_class);
         return false;
     }
 }
 /**
  * @param ParamConverter $configuration
  *
  * @return bool
  */
 public function supports(ParamConverter $configuration)
 {
     if ("kunstmaan_extra.page" !== $configuration->getConverter()) {
         return false;
     }
     $options = $this->getOptions($configuration);
     if ($options['type_field']) {
         // we will guess the class name later in the `apply` method
         // for now assume it is supported
         return true;
     }
     $configuration->setClass($this->contentType->getContentTypeClass($configuration->getName()));
     return parent::supports($configuration);
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
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;
 }
 /**
  * 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;
 }
Ejemplo n.º 9
0
 public function __construct(ManagerRegistry $managerRegistry, AccountManager $accountManager)
 {
     parent::__construct($managerRegistry);
     $this->accountManager = $accountManager;
 }
Ejemplo n.º 10
0
 /**
  * @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);
 }
Ejemplo n.º 11
0
 public function supports(ParamConverter $configuration)
 {
     return $configuration->getClass() === Product::class && parent::supports($configuration);
 }
Ejemplo n.º 12
0
 /**
  * Get options
  *
  * @param  ParamConverter  $configuration
  * @return array
  */
 protected function getOptions(ParamConverter $configuration)
 {
     return array_replace(array('error_message' => 'Not Found'), parent::getOptions($configuration));
 }
Ejemplo n.º 13
0
 public function supports(ParamConverter $configuration)
 {
     //return true;
     return parent::supports($configuration);
 }