/** * {@inheritDoc} */ public function apply(Request $request, ConfigurationInterface $configuration) { $options = (array) $configuration->getOptions(); if (isset($options['deserializationContext']) && is_array($options['deserializationContext'])) { $context = array_merge($this->context, $options['deserializationContext']); } else { $context = $this->context; } if ($this->serializer instanceof SerializerInterface) { $context = $this->configureDeserializationContext($this->getDeserializationContext(), $context); } try { $object = $this->serializer->deserialize($request->getContent(), $configuration->getClass(), $request->getContentType(), $context); } catch (UnsupportedFormatException $e) { throw new HttpException(Codes::HTTP_UNSUPPORTED_MEDIA_TYPE, $e->getMessage()); } catch (JMSSerializerException $e) { throw new HttpException(Codes::HTTP_BAD_REQUEST, $e->getMessage()); } catch (SymfonySerializerException $e) { throw new HttpException(Codes::HTTP_BAD_REQUEST, $e->getMessage()); } $request->attributes->set($configuration->getName(), $object); if (null !== $this->validator) { $validatorOptions = $this->getValidatorOptions($options); $request->attributes->set($this->validationErrorsArgument, $this->validator->validate($object, $validatorOptions['groups'], $validatorOptions['traverse'], $validatorOptions['deep'])); } return true; }
/** * @param Request $request * @param ConfigurationInterface $configuration * * @return bool * * @throws \LogicException * @throws NotFoundHttpException * @throws \Exception */ public function apply(Request $request, ConfigurationInterface $configuration) { $classQuery = $configuration->getClass() . 'Query'; $classPeer = $configuration->getClass() . 'Peer'; $this->filters = array(); $this->exclude = array(); if (!class_exists($classQuery)) { throw new \Exception(sprintf('The %s Query class does not exist', $classQuery)); } $tableMap = $classPeer::getTableMap(); $pkColumns = $tableMap->getPrimaryKeyColumns(); if (count($pkColumns) == 1) { $this->pk = strtolower($pkColumns[0]->getName()); } $options = $configuration->getOptions(); // Check route options for converter options, if there are non provided. if (empty($options) && $request->attributes->has('_route') && $this->router && $configuration instanceof ParamConverter) { $converterOption = $this->router->getRouteCollection()->get($request->attributes->get('_route'))->getOption('propel_converter'); if (!empty($converterOption[$configuration->getName()])) { $options = $converterOption[$configuration->getName()]; } } if (isset($options['mapping'])) { // We use the mapping for calling findPk or filterBy foreach ($options['mapping'] as $routeParam => $column) { if ($request->attributes->has($routeParam)) { if ($this->pk === $column) { $this->pk = $routeParam; } else { $this->filters[$column] = $request->attributes->get($routeParam); } } } } else { $this->exclude = isset($options['exclude']) ? $options['exclude'] : array(); $this->filters = $request->attributes->all(); } $this->withs = isset($options['with']) ? is_array($options['with']) ? $options['with'] : array($options['with']) : array(); // find by Pk if (false === ($object = $this->findPk($classQuery, $request))) { // find by criteria if (false === ($object = $this->findOneBy($classQuery, $request))) { if ($configuration->isOptional()) { //we find nothing but the object is optional $object = null; } else { throw new \LogicException('Unable to guess how to get a Propel object from the request information.'); } } } if (null === $object && false === $configuration->isOptional()) { throw new NotFoundHttpException(sprintf('%s object not found.', $configuration->getClass())); } $request->attributes->set($configuration->getName(), $object); return true; }
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); }
public function apply(Request $request, ConfigurationInterface $configuration) { $param = $configuration->getName(); if (!$request->attributes->has($param)) { return false; } $options = $configuration->getOptions(); $value = $request->attributes->get($param); $date = isset($options['format']) ? DateTime::createFromFormat($options['format'], $value) : new DateTime($value); if (!$date) { throw new NotFoundHttpException('Invalid date given.'); } $request->attributes->set($param, $date); 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); }
public function apply(Request $request, ConfigurationInterface $configuration) { $classQuery = $configuration->getClass() . 'Query'; if (!class_exists($classQuery)) { throw new \Exception(sprintf('The %s Query class does not exist', $classQuery)); } $options = $configuration->getOptions(); $exclude = isset($options['exclude']) ? $options['exclude'] : array(); // find by Pk if (in_array('id', $exclude) || false === ($object = $this->findPk($classQuery, $request))) { // find by criteria if (false === ($object = $this->findOneBy($classQuery, $request, $exclude))) { throw new \LogicException('Unable to guess how to get a Propel object from the request information.'); } } if (null === $object && false === $configuration->isOptional()) { throw new NotFoundHttpException(sprintf('%s object not found.', $configuration->getClass())); } $request->attributes->set($configuration->getName(), $object); }
protected function getOptions(ConfigurationInterface $configuration) { return array_replace(array('entity_manager' => null, 'exclude' => array(), 'mapping' => array()), $configuration->getOptions()); }
/** * @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()); }
protected function getOptions(ConfigurationInterface $configuration) { return array_replace(array('entity_manager' => null), $configuration->getOptions()); }