当前位置: 首页>>代码示例>>PHP>>正文


PHP ParamConverter::isOptional方法代码示例

本文整理汇总了PHP中Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter::isOptional方法的典型用法代码示例。如果您正苦于以下问题:PHP ParamConverter::isOptional方法的具体用法?PHP ParamConverter::isOptional怎么用?PHP ParamConverter::isOptional使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter的用法示例。


在下文中一共展示了ParamConverter::isOptional方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: apply

 /**
  * @{inheritDoc}
  *
  * @throws InvalidConfigurationException if the parameter name, class or id option are missing
  * @throws NotFoundHttpException         if the id doesn't matche an existing entity
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     if (null === ($parameter = $configuration->getName())) {
         throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_NAME);
     }
     if (null === ($entityClass = $configuration->getClass())) {
         throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_CLASS);
     }
     $options = $configuration->getOptions();
     if (!isset($options['id'])) {
         throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_ID);
     }
     if ($request->attributes->has($options['id'])) {
         if (null !== ($id = $request->attributes->get($options['id']))) {
             if (null !== ($entity = $this->em->getRepository($entityClass)->find($id))) {
                 $request->attributes->set($parameter, $entity);
                 return true;
             }
         }
         if (!$configuration->isOptional()) {
             throw new NotFoundHttpException();
         }
     }
     return false;
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:31,代码来源:StrictIdConverter.php

示例2: apply

 /**
  * {@inheritdoc}
  *
  * @throws NotFoundHttpException When invalid date given
  */
 public function apply(Request $request, ParamConverter $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;
     }
     if (isset($options['format'])) {
         $date = DateTime::createFromFormat($options['format'], $value);
         if (!$date) {
             throw new NotFoundHttpException('Invalid date given.');
         }
     } else {
         if (false === strtotime($value)) {
             throw new NotFoundHttpException('Invalid date given.');
         }
         $date = new DateTime($value);
     }
     $request->attributes->set($param, $date);
     return true;
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:30,代码来源:DateTimeParamConverter.php

示例3: apply

 public function apply(Request $request, ParamConverter $configuration)
 {
     $entity = $this->findByRequestParameter($request);
     if (!$configuration->isOptional() && null === $entity) {
         throw new NotFoundHttpException(sprintf('Entity of type "%s" was not found', $configuration->getClass()));
     }
     $param = $configuration->getName();
     $request->attributes->set($param, $entity);
     return true;
 }
开发者ID:WellCommerce,项目名称:CoreBundle,代码行数:10,代码来源:AbstractEntityParamConverter.php

示例4: getOptions

 private function getOptions(ParamConverter $configuration)
 {
     $options = array_replace(['model' => $configuration->getClass() . 'Model'], $configuration->getOptions());
     if (isset($options['connection'])) {
         $options['session'] = $this->pomm[$options['session']];
     } else {
         $options['session'] = $this->pomm->getDefaultSession();
     }
     $options["optional"] = $configuration->isOptional();
     return $options;
 }
开发者ID:pomm-project,项目名称:pomm-bundle,代码行数:11,代码来源:EntityParamConverter.php

示例5: apply

 /**
  * @param Request $request
  * @param ParamConverter $configuration
  *
  * @return bool
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     if (!$request->attributes->has($this->getPropertyName())) {
         return false;
     }
     $valueObjectId = $request->attributes->get($this->getPropertyName());
     if (!$valueObjectId && $configuration->isOptional()) {
         return false;
     }
     $request->attributes->set($configuration->getName(), $this->loadValueObject($valueObjectId));
     return true;
 }
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:18,代码来源:RepositoryParamConverter.php

示例6: apply

 /**
  * Reads the 'q' attribute of the request and returns a menu item array..
  *
  * @param Request        $request       The request
  * @param ParamConverter $configuration Contains the name, class and options of the object
  *
  * @throws NotFoundHttpException
  *
  * @return bool True if the object has been successfully set, else false
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     if (!$request->attributes->has('q')) {
         return false;
     }
     $value = $request->attributes->get('q');
     if (!$value && $configuration->isOptional()) {
         return false;
     }
     $router_item = menu_get_item($value);
     if (!$router_item) {
         throw new NotFoundHttpException('Entity not found.');
     }
     $param = $configuration->getName();
     $request->attributes->set($param, $router_item);
     return true;
 }
开发者ID:bangpound,项目名称:drupal-bridge,代码行数:27,代码来源:RouterItemConverter.php

示例7: apply

 /**
  * @param Request $request
  * @param ParamConverter $configuration
  *
  * @throws NotFoundHttpException if value object was not found
  * @throws AccessDeniedHttpException if user is not allowed to load the value object
  *
  * @return bool
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     if (!$request->attributes->has($this->getPropertyName())) {
         return false;
     }
     $valueObjectId = $request->attributes->get($this->getPropertyName());
     if (!$valueObjectId && $configuration->isOptional()) {
         return false;
     }
     try {
         $request->attributes->set($configuration->getName(), $this->loadValueObject($valueObjectId));
         return true;
     } catch (NotFoundException $e) {
         throw new NotFoundHttpException('Requested values not found', $e);
     } catch (UnauthorizedException $e) {
         throw new AccessDeniedHttpException('Access to values denied', $e);
     }
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:27,代码来源:RepositoryParamConverter.php

示例8: apply

 /**
  * {@inheritdoc}
  *
  * @throws NotFoundHttpException When invalid uuid given
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $param = $configuration->getName();
     if (!$request->attributes->has($param)) {
         return false;
     }
     $value = $request->attributes->get($param);
     if (!$value && $configuration->isOptional()) {
         return false;
     }
     try {
         $uuid = Uuid::fromString($value);
         $request->attributes->set($param, $uuid);
         return true;
     } catch (\InvalidArgumentException $e) {
         throw new NotFoundHttpException('Invalid uuid given');
     }
 }
开发者ID:mcfedr,项目名称:uuid-paramconverter,代码行数:23,代码来源:UuidParamConverter.php

示例9: apply

 /**
  * {@inheritDoc}
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $param = $configuration->getName();
     if (!$request->attributes->has($param) || !$request->attributes->has('entity_type')) {
         return false;
     }
     $entityType = $request->attributes->get('entity_type');
     $value = $request->attributes->get($param);
     if (!$value && $configuration->isOptional()) {
         return false;
     }
     $entities = entity_load($entityType, array($value));
     $entity = reset($entities);
     if (empty($entity)) {
         throw new NotFoundHttpException('Entity not found.');
     }
     $request->attributes->set($param, $entity);
     return true;
 }
开发者ID:bangpound,项目名称:drupal-bundle,代码行数:22,代码来源:EntityParamConverter.php

示例10: apply

 /**
  * {@inheritdoc}
  *
  * @throws InvalidArgumentException Thrown, when parameter has been already parsed to array or object.
  */
 public function apply(Request $request, ParamConverter $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;
     }
     if (is_object($value) || is_array($value)) {
         throw new InvalidArgumentException('Parameter already parsed to object or array.');
     }
     if (!empty($options['delimiter'])) {
         $delimiter = $options['delimiter'];
     } else {
         $delimiter = ',';
     }
     $array = $this->getArrayObject($delimiter, $value);
     $request->attributes->set($param, $array);
     return true;
 }
开发者ID:Gendoria,项目名称:param-converter-bundle,代码行数:28,代码来源:ArrayObjectParamConverter.php

示例11: apply

 /**
  * {@inheritdoc}
  *
  * @throws NotFoundHttpException When invalid date given
  */
 public function apply(Request $request, ParamConverter $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;
     }
     $invalidDateMessage = 'Invalid date given.';
     try {
         $date = isset($options['format']) ? Date::createFromFormat($options['format'], $value) : new Date($value);
     } catch (Exception $e) {
         throw new NotFoundHttpException($invalidDateMessage);
     }
     if (!$date) {
         throw new NotFoundHttpException($invalidDateMessage);
     }
     $request->attributes->set($param, $date);
     return true;
 }
开发者ID:hmlb,项目名称:date-bundle,代码行数:28,代码来源:DateParamConverter.php

示例12: apply

 /**
  * @param Request                $request
  * @param ParamConverter $configuration
  *
  * @return bool
  *
  * @throws \LogicException
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function apply(Request $request, ParamConverter $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;
 }
开发者ID:ChazalFlorian,项目名称:enjoyPangolin,代码行数:66,代码来源:PropelParamConverter.php


注:本文中的Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter::isOptional方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。