public function apply(Request $request, ConfigurationInterface $configuration)
 {
     if ($request->attributes->has($configuration->getName())) {
         return;
     }
     $class = $configuration->getClass();
     if (false === ($object = $this->find($class, $request))) {
         if (false === ($object = $this->findOneBy($class, $request))) {
             throw new \LogicException('Unable to guess how to get a Doctrine instance from the request information.');
         }
     }
     if (null === $object && false === $configuration->isOptional()) {
         throw new NotFoundHttpException(sprintf('%s object not found.', $class));
     }
     $request->attributes->set($configuration->getName(), $object);
 }
 /**
  * {@inheritdoc}
  *
  * @throws NotFoundHttpException When invalid date given
  */
 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);
     if (!$value && $configuration->isOptional()) {
         return false;
     }
     $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)
 {
     $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);
 }
 /**
  * @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;
 }