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


PHP ParamConverter::getName方法代码示例

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


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

示例1: getMappingOptions

 /**
  * @param Request        $request
  * @param ParamConverter $configuration
  * @param string         $mapToField
  *
  * @return array
  */
 private function getMappingOptions(Request $request, ParamConverter $configuration, $mapToField)
 {
     $routeParams = $request->attributes->get('_route_params');
     if (isset($routeParams[$configuration->getName()])) {
         return ['mapping' => [$configuration->getName() => $mapToField]];
     }
     return [];
 }
开发者ID:nass59,项目名称:Lab,代码行数:15,代码来源:APIParamConverter.php

示例2: 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

示例3: apply

 public function apply(Request $request, ParamConverter $configuration)
 {
     $result = null;
     if ($configuration->getClass() == 'Symfony\\Component\\HttpFoundation\\File\\UploadedFile') {
         $result = $this->parseFile($configuration->getName(), $request);
     } else {
         $result = $this->parser->parseClass($configuration->getClass(), $request->getContent());
     }
     $request->attributes->set($configuration->getName(), $result);
     return true;
 }
开发者ID:freefair,项目名称:rest-bundle,代码行数:11,代码来源:RequestBodyConverter.php

示例4: apply

 /**
  * 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)
 {
     if (!$request->attributes->has($configuration->getName())) {
         return false;
     }
     $id = $request->attributes->get($configuration->getName());
     $conversation = $this->repository->getConversation($id);
     if (!$conversation) {
         throw new NotFoundHttpException();
     }
     $request->attributes->set($configuration->getName(), $conversation);
     return true;
 }
开发者ID:maennchen,项目名称:engelsystem,代码行数:21,代码来源:ConversationParamConverter.php

示例5: apply

 /**
  * 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;
 }
开发者ID:scaytrase,项目名称:symfony-multisite-bundle,代码行数:37,代码来源:SiteParamConverter.php

示例6: apply

 public function apply(Request $request, ParamConverter $configuration)
 {
     //$options = $this->getOptions($configuration);
     //echo $options['test'];
     $ownerNameCanonical = $request->attributes->get('owner');
     $modId = $request->attributes->get('mod');
     $branchId = $request->attributes->get('branch');
     if ($branchId == 'default') {
         $branchId = null;
     }
     $version = $request->attributes->get('build');
     if (!($version == 'current')) {
         list($versionRest, $versionMetadata) = array_pad(explode('+', $version, 2), 2, null);
         list($versionMain, $versionPreRelease) = array_pad(explode('-', $versionRest, 2), 2, null);
         list($versionMajor, $versionMinor, $versionPatch) = explode('.', $versionMain);
     } else {
         $versionMajor = null;
         $versionMinor = null;
         $versionPatch = null;
         $versionPreRelease = null;
         $versionMetadata = null;
     }
     $build = $this->repository->findSingleBuild($ownerNameCanonical, $modId, $branchId, $versionMajor, $versionMinor, $versionPatch, $versionPreRelease, $versionMetadata);
     if (null === $build) {
         throw new NotFoundHttpException("Build not found.");
     }
     $request->attributes->set($configuration->getName(), $build);
     return true;
 }
开发者ID:ngld,项目名称:hlp-nebula,代码行数:29,代码来源:BuildConverter.php

示例7: apply

 /**
  * 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)
 {
     $slug = $request->get('slug', null);
     $username = $request->get('username', null);
     $id = $request->get('id', null);
     $name = $request->get('name', null);
     if ($slug) {
         $searchArray = array('slug' => $slug);
     } elseif ($username) {
         $searchArray = array('username' => $username);
     } elseif ($id) {
         $searchArray = array('id' => $id);
     } elseif ($id) {
         $searchArray = array('name' => $name);
     } else {
         throw new \InvalidArgumentException('Route attribute is missing');
     }
     $class = $this->targetEntitiesArray[$configuration->getClass()];
     $repository = $this->doctrine->getRepository($class);
     $object = $repository->findOneBy($searchArray);
     if (!$object) {
         throw new NotFoundHttpException($name);
     }
     $request->attributes->set($configuration->getName(), $object);
 }
开发者ID:NegMozzie,项目名称:tapha,代码行数:33,代码来源:AbstractConverter.php

示例8: supports

 function supports(ParamConverter $configuration)
 {
     if ('json' !== $configuration->getName()) {
         return false;
     }
     return true;
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:7,代码来源:JsonParamConverter.php

示例9: 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

示例10: apply

 /**
  * {@inheritdoc}
  *
  * @throws InvalidConfigurationException if the name or class parameters are missing
  * @throws NotFoundHttpException         if one or more entities cannot be retreived
  * @throws BadRequestHttpException       if there is no "ids" array parameter in the query string
  */
 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();
     $paramName = isset($options['name']) ? $options['name'] : 'ids';
     if ($request->query->has($paramName)) {
         if (is_array($ids = $request->query->get($paramName))) {
             try {
                 $entities = $this->om->findByIds($entityClass, $ids);
                 $request->attributes->set($parameter, $entities);
                 return true;
             } catch (MissingObjectException $ex) {
                 throw new NotFoundHttpException($ex->getMessage());
             }
         }
         throw new BadRequestHttpException();
     }
     $request->attributes->set($parameter, []);
     return true;
 }
开发者ID:claroline,项目名称:distribution,代码行数:32,代码来源:MultipleIdsConverter.php

示例11: apply

 /**
  * {@inheritdoc}
  *
  * @throws InvalidConfigurationException if the parameter name is missing
  * @throws AccessDeniedException         if the current request is anonymous
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     if (null === ($parameter = $configuration->getName())) {
         throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_NAME);
     }
     $options = $configuration->getOptions();
     if ($options['authenticatedUser'] === true) {
         if (($user = $this->tokenStorage->getToken()->getUser()) instanceof User) {
             $request->attributes->set($parameter, $user);
             return true;
         } else {
             if (array_key_exists('messageEnabled', $options) && $options['messageEnabled'] === true) {
                 $messageType = 'warning';
                 if (array_key_exists('messageType', $options)) {
                     $messageType = $options['messageType'];
                 }
                 $messageTranslationKey = 'this_page_requires_authentication';
                 $messageTranslationDomain = 'platform';
                 if (array_key_exists('messageTranslationKey', $options)) {
                     $messageTranslationKey = $options['messageTranslationKey'];
                     if (array_key_exists('messageTranslationDomain', $options)) {
                         $messageTranslationDomain = $options['messageTranslationDomain'];
                     }
                 }
                 $request->getSession()->getFlashBag()->add($messageType, $this->translator->trans($messageTranslationKey, [], $messageTranslationDomain));
             }
             throw new AccessDeniedException();
         }
     } else {
         $request->attributes->set($parameter, $user = $this->tokenStorage->getToken()->getUser());
     }
 }
开发者ID:claroline,项目名称:distribution,代码行数:38,代码来源:AuthenticatedUserConverter.php

示例12: 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

示例13: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $options = (array) $configuration->getOptions();
     if (isset($options['deserializationContext']) && is_array($options['deserializationContext'])) {
         $arrayContext = array_merge($this->context, $options['deserializationContext']);
     } else {
         $arrayContext = $this->context;
     }
     $this->configureContext($context = new Context(), $arrayContext);
     try {
         $object = $this->serializer->deserialize($request->getContent(), $configuration->getClass(), $request->getContentType(), $context);
     } catch (UnsupportedFormatException $e) {
         throw new UnsupportedMediaTypeHttpException($e->getMessage(), $e);
     } catch (JMSSerializerException $e) {
         throw new BadRequestHttpException($e->getMessage(), $e);
     } catch (SymfonySerializerException $e) {
         throw new BadRequestHttpException($e->getMessage(), $e);
     }
     $request->attributes->set($configuration->getName(), $object);
     if (null !== $this->validator) {
         $validatorOptions = $this->getValidatorOptions($options);
         $errors = $this->validator->validate($object, null, $validatorOptions['groups']);
         $request->attributes->set($this->validationErrorsArgument, $errors);
     }
     return true;
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:29,代码来源:RequestBodyParamConverter.php

示例14: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Request $request, ParamConverter $configuration) : bool
 {
     $class = $configuration->getClass();
     $constant = sprintf('%s::EMPTY_PROPERTIES', $class);
     $propertiesToBeSkipped = [];
     $instance = new $class();
     $declaredProperties = array_filter((new \ReflectionClass($class))->getProperties(), function (ReflectionProperty $property) use($class) {
         return $property->getDeclaringClass()->name === $class;
     });
     // fetch result properties that are optional and to be skipped as those must not be processed
     if (defined($constant)) {
         $propertiesToBeSkipped = constant($constant);
     }
     /** @var ReflectionProperty $property */
     foreach ($declaredProperties as $property) {
         $propertyName = $property->getName();
         if (in_array($propertyName, $propertiesToBeSkipped, true)) {
             continue;
         }
         // non-writable properties cause issues with the DTO creation
         if (!$this->propertyAccess->isWritable($instance, $propertyName)) {
             throw new \RuntimeException($this->getInvalidPropertyExceptionMessage($class, $propertyName));
         }
         $this->propertyAccess->setValue($instance, $propertyName, $this->findAttributeInRequest($request, $property, $this->propertyAccess->getValue($instance, $propertyName)));
     }
     $request->attributes->set($configuration->getName(), $instance);
     return true;
 }
开发者ID:sententiaregum,项目名称:sententiaregum,代码行数:31,代码来源:DTOConverter.php

示例15: apply

 /**
  * {@inheritdoc}
  *
  * @throws \LogicException       When unable to guess how to get a Doctrine instance from the request information
  * @throws NotFoundHttpException When object not found
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $class = $configuration->getClass();
     $options = $this->getOptions($configuration);
     if (null === $request->attributes->get($name, false)) {
         $configuration->setIsOptional(true);
     }
     // find by identifier?
     if (false === ($object = $this->find($class, $request, $options, $name))) {
         // find by criteria
         if (false === ($object = $this->findOneBy($class, $request, $options))) {
             if ($configuration->isOptional()) {
                 $object = null;
             } else {
                 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($name, $object);
     return true;
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:31,代码来源:DoctrineParamConverter.php


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