/**
  * {@inheritdoc}
  */
 public function supports(ConfigurationInterface $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     return "DateTime" === $configuration->getClass();
 }
 public function apply(Request $request, ConfigurationInterface $configuration)
 {
     $options = $configuration->getOptions($configuration);
     $typeEntity = $request->attributes->get($options['typeEntity']);
     $commentModel = CommentModelFactory::createByType($typeEntity);
     if (!$commentModel instanceof CommentModelInterface) {
         throw new NotFoundHttpException('Not found');
     }
     $request->attributes->set($configuration->getName(), $commentModel);
 }
示例#3
0
 function apply(Request $request, ConfigurationInterface $configuration)
 {
     // On récupère l'entité Site correspondante
     $site = $this->repository->findOneByHostname($request->getHost());
     // On définit ensuite un attribut de requête du nom de $conf->getName()
     // et contenant notre entité Site
     $request->attributes->set($configuration->getName(), $site);
     // On retourne true pour qu'aucun autre ParamConverter ne soit utilisé sur cet argument
     // Je pense notamment au ParamConverter de Doctrine qui risque de vouloir s'appliquer !
     return true;
 }
 public function supports(ConfigurationInterface $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     try {
         $this->dm->getClassMetadata($configuration->getClass());
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
 public function supports(ConfigurationInterface $configuration)
 {
     if (null === ($classname = $configuration->getClass())) {
         return false;
     }
     if (!class_exists($classname)) {
         return false;
     }
     // Propel Class?
     $class = new \ReflectionClass($configuration->getClass());
     if ($class->isSubclassOf('BaseObject')) {
         return true;
     }
     return false;
 }
示例#6
0
 /**
  * Apply the converter
  *
  * @param  \Symfony\Component\HttpFoundation\Request                                $request
  * @param  \Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface $configuration
  * @return boolean
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function apply(Request $request, ConfigurationInterface $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));
     }
     return true;
 }
 public function apply(Request $request, ConfigurationInterface $configuration)
 {
     $options = $configuration->getOptions($configuration);
     $typeEntity = $request->attributes->get($options['typeEntity']);
     $entityId = $request->attributes->get($options['entityId']);
     $answerModel = AnswerModelFactory::createByType($typeEntity);
     if (!$answerModel instanceof AnswerModelInterface) {
         throw new NotFoundHttpException('Not found');
     }
     $entityForAnswer = $this->entityManager->getRepository($answerModel->getPollClass())->findOneById($entityId);
     if (!$entityForAnswer) {
         throw new NotFoundHttpException('Not found');
     }
     $answerModel->setPollEntity($entityForAnswer);
     $request->attributes->set($configuration->getName(), $answerModel);
 }
 function apply(Request $request, ConfigurationInterface $configuration)
 {
     if ($configuration->getClass() == 'Amisure\\P4SApiBundle\\Entity\\User\\BeneficiaryUser') {
         $user = $this->accessor->getBeneficiaryProfile($request->get('beneficiaryId'));
         if (null == $user) {
             throw new NotFoundResourceException('BeneficiaryUser[id=' . $request->get('beneficiaryId') . '] inexistant');
         }
     } else {
         $user = $this->em->getRepository('Amisure\\P4SApiBundle\\Entity\\User\\SessionUser')->findOneBy(array('username' => $request->get('beneficiaryId')));
         if (null == $user) {
             throw new NotFoundResourceException('SessionUser[id=' . $request->get('beneficiaryId') . '] inexistant');
         }
     }
     $request->attributes->set($configuration->getName(), $user);
     return true;
     // Don't use an other ParamConverter after this one
 }
 public function supports(ConfigurationInterface $configuration)
 {
     if (null === $this->manager) {
         return false;
     }
     if (null === $configuration->getClass()) {
         return false;
     }
     // Doctrine Entity?
     try {
         $this->manager->getClassMetadata($configuration->getClass());
         return true;
     } catch (MappingException $e) {
         return false;
     } catch (MongoDBException $e) {
         return false;
     }
 }
示例#10
0
 /**
  * Apply converter on request based on the given configuration.
  *
  * @param Request                $request
  * @param ConfigurationInterface $configuration
  */
 protected function applyConverter(Request $request, ConfigurationInterface $configuration)
 {
     $value = $request->attributes->get($configuration->getName());
     $className = $configuration->getClass();
     // If the value is already an instance of the class we are trying to convert it into
     // we should continue as no conversion is required
     if (is_object($value) && $value instanceof $className) {
         return;
     }
     if ($converterName = $configuration->getConverter()) {
         if (!isset($this->namedConverters[$converterName])) {
             throw new \RuntimeException(sprintf("No converter named '%s' found for conversion of parameter '%s'.", $converterName, $configuration->getName()));
         }
         $converter = $this->namedConverters[$converterName];
         if (!$converter->supports($configuration)) {
             throw new \RuntimeException(sprintf("Converter '%s' does not support conversion of parameter '%s'.", $converterName, $configuration->getName()));
         }
         $converter->apply($request, $configuration);
         return;
     }
     foreach ($this->all() as $converter) {
         if ($converter->supports($configuration)) {
             if ($converter->apply($request, $configuration)) {
                 return;
             }
         }
     }
 }
 protected function getOptions(ConfigurationInterface $configuration)
 {
     return array_replace(array('entity_manager' => null, 'exclude' => array(), 'mapping' => array()), $configuration->getOptions());
 }
 /**
  * Get a proper class name for the encapsulated paramConverter
  *
  * @param ConfigurationInterface $configuration
  *
  * @return ConfigurationInterface
  */
 protected function getProperConfiguration(ConfigurationInterface $configuration)
 {
     $properConfiguration = clone $configuration;
     $properConfiguration->setClass($this->container->getParameter($configuration->getClass()));
     return $properConfiguration;
 }
示例#13
0
 /**
  * @param ConfigurationInterface $configuration
  *
  * @return array
  */
 protected function getOptions(ConfigurationInterface $configuration)
 {
     return array_replace(array('resource_manager' => null, 'exclude' => array(), 'mapping' => array(), 'strip_null' => false), $configuration->getOptions());
 }
示例#14
0
 protected function getOptions(ConfigurationInterface $configuration)
 {
     return array_replace(array('entity_manager' => null), $configuration->getOptions());
 }
 /**
  * {@inheritdoc}
  */
 public function supports(ConfigurationInterface $configuration)
 {
     return null !== $configuration->getClass();
 }