php Sensio-Bundle-FrameworkExtraBundle-Configuration-ParamConverter类(方法)实例源码

下面列出了php Sensio-Bundle-FrameworkExtraBundle-Configuration-ParamConverter 类(方法)源码代码实例,从而了解它的用法。

作者:bangpoun    项目:drupal-bridg   
/**
  * Checks if the object is supported.
  *
  * @param ParamConverter $configuration Should be an instance of ParamConverter
  *
  * @return bool True if the object is supported, else false
  */
 public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getConverter()) {
         return false;
     }
     return 'drupal.router_item' === $configuration->getConverter();
 }

作者:alexjob    项目:Aise   
/**
  * execute
  *
  * @param Request              $request
  * @param SensioParamConverter $configuration
  *
  * @return bool|mixed
  */
 public function execute(Request $request, SensioParamConverter $configuration)
 {
     $id = $request->attributes->get('id');
     $locale = $request->attributes->get('locale');
     $url = $request->attributes->get('url');
     $name = $configuration->getName();
     $options = $configuration->getOptions();
     $resolvedClass = $configuration->getClass();
     $method = $request->getMethod();
     $rawPayload = $request->getContent();
     switch (true) {
         case 'GET' === $method:
             $convertedValue = $this->loadEntity($resolvedClass, $id, $locale, $url);
             break;
         case 'DELETE' === $method:
             $convertedValue = $this->loadEntity($resolvedClass, $id, $locale, $url);
             break;
         case 'PUT' === $method:
             $payload = array_merge(array('id' => $id), json_decode($rawPayload, true));
             $convertedValue = $this->updateEntity($resolvedClass, json_encode($payload));
             break;
         case 'POST' === $method:
             $convertedValue = $this->updateEntity($resolvedClass, $rawPayload);
             break;
     }
     return $convertedValue;
 }

作者:ibrow    项目:rest-bundl   
/**
  * @param ParamConverter $configuration
  * @return bool
  */
 protected function checkFailureOnValidationError(ParamConverter $configuration)
 {
     if (isset($configuration->getOptions()['fail_on_validation_error'])) {
         return $configuration->getOptions()['fail_on_validation_error'];
     }
     return $this->failOnValidationError;
 }

作者:qpautra    项目:woohoolabs-yin-bundl   
public function it_should_support(ParamConverter $configuration)
 {
     $configuration->getClass()->willReturn(JsonApi::class);
     $this->supports($configuration)->shouldReturn(true);
     $configuration->getClass()->willReturn(stdClass::class);
     $this->supports($configuration)->shouldReturn(false);
 }

作者:sungvada    项目:Symfon   
function supports(ParamConverter $configuration)
 {
     if ('json' !== $configuration->getNAme()) {
         return false;
     }
     return true;
 }

作者:RuntyCybi    项目:csymfon   
/**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     return isset(self::$supportedTypes[$configuration->getClass()]);
 }

作者:jcar    项目:framework-extra-bundl   
/**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     if (!$configuration->getClass()) {
         return false;
     }
     return true;
 }

作者:kario    项目:mydrink   
/**
  * Checks if the object is supported.
  *
  * @param ParamConverter $configuration Should be an instance of ParamConverter
  *
  * @return bool True if the object is supported, else false
  */
 public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     return $configuration->getClass() === Category::class;
 }

作者:thesoftwarefactoryu    项目:SenNetwor   
/**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     if (!($class = $configuration->getClass())) {
         return false;
     }
     return 'DTO' === strtoupper(substr($class, -3));
 }

作者:joan16    项目:symfony2_tes   
/**
  * Modifies the ParamConverterManager instance.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $configurations = array();
     if ($configuration = $request->attributes->get('_converters')) {
         foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
             $configurations[$configuration->getName()] = $configuration;
         }
     }
     if (is_array($controller)) {
         $r = new \ReflectionMethod($controller[0], $controller[1]);
     } else {
         $r = new \ReflectionFunction($controller);
     }
     // automatically apply conversion for non-configured objects
     foreach ($r->getParameters() as $param) {
         if (!$param->getClass() || $param->getClass()->isInstance($request)) {
             continue;
         }
         $name = $param->getName();
         if (!isset($configurations[$name])) {
             $configuration = new ParamConverter(array());
             $configuration->setName($name);
             $configuration->setClass($param->getClass()->getName());
             $configurations[$name] = $configuration;
         } elseif (null === $configurations[$name]->getClass()) {
             $configurations[$name]->setClass($param->getClass()->getName());
         }
         $configurations[$name]->setIsOptional($param->isOptional());
     }
     $this->manager->apply($request, $configurations);
 }

作者:neteasy-wor    项目:hkgbf_cr   
/**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     return "DateTime" === $configuration->getClass();
 }

作者:rfc148    项目:symfon   
/**
  * Modifies the ParamConverterManager instance.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onCoreController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     $request = $event->getRequest();
     $configurations = array();
     if ($configuration = $request->attributes->get('_converters')) {
         $configurations = is_array($configuration) ? $configuration : array($configuration);
     }
     if (is_array($controller)) {
         $r = new \ReflectionMethod($controller[0], $controller[1]);
     } else {
         $r = new \ReflectionFunction($controller);
     }
     // automatically apply conversion for non-configured objects
     foreach ($r->getParameters() as $param) {
         if ($param->getClass() && !$request->attributes->get($param->getName())) {
             $configuration = new ParamConverter(array());
             $configuration->setName($param->getName());
             $configuration->setClass($param->getClass()->getName());
             $configuration->setIsOptional($param->isOptional());
             $configurations[] = $configuration;
         }
     }
     $this->manager->apply($request, $configurations);
 }

作者:WellCommerc    项目:CoreBundl   
public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     return in_array($configuration->getClass(), $this->supportedTypes);
 }

作者:ci-tro    项目:ci-tro   
/**
  * @param ParamConverter $configuration
  * @return bool
  */
 public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     return 'CiTron\\Project\\Entity\\Project' === $configuration->getClass();
 }

作者:ygeneration66    项目:m   
/**
  * Stores the object in the request.
  *
  * @param Request        $request       The request
  * @param ParamConverter $configuration Contains the name, class and options of the object
  *
  * @return boolean True if the object has been successfully set, else false
  *
  * @throws UnsupportedMediaTypeHttpException
  * @throws BadRequestHttpException
  */
 protected function execute(Request $request, ParamConverter $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 UnsupportedMediaTypeHttpException($e->getMessage());
     } catch (JMSSerializerException $e) {
         throw new BadRequestHttpException($e->getMessage());
     } catch (SymfonySerializerException $e) {
         throw new BadRequestHttpException($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;
 }

作者:clarolin    项目:distributio   
/**
  * {@inheritdoc}
  */
 public function supports(ParamConverter $configuration)
 {
     $options = $configuration->getOptions();
     if (isset($options['allowAnonymous'])) {
         return is_bool($options['allowAnonymous']) ? true : false;
     }
     return true;
 }

作者:nicolasdutreil    项目:Symfon   
function supports(ParamConverter $configuration)
 {
     // Si le nom de l'argument du contrôleur n'est pas "json", on n'applique pas le convertisseur
     if ('json' !== $configuration->getName()) {
         return false;
     }
     return true;
 }

作者:VincentChalno    项目:SidusEAVModelBundl   
/**
  * @param Request        $request
  * @param ParamConverter $configuration
  * @return string
  */
 protected function getRequestAttributeName(Request $request, ParamConverter $configuration)
 {
     $param = $configuration->getName();
     if (array_key_exists('id', $configuration->getOptions())) {
         $param = $configuration->getOptions()['id'];
     }
     return $param;
 }

作者:WellCommerc    项目:SearchBundl   
public function supports(ParamConverter $configuration)
 {
     if (null === $configuration->getClass()) {
         return false;
     }
     $supportedTypes = [SearchRequest::class, SearchRequestInterface::class];
     return in_array($configuration->getClass(), $supportedTypes);
 }

作者:jcar    项目:framework-extra-bundl   
private function createModel(ParamConverter $configuration)
 {
     $class = $configuration->getClass();
     if (!class_exists($class)) {
         throw new \InvalidArgumentException(sprintf('Failed to load model class [%s]', $class));
     }
     return new $class();
 }


问题


面经


文章

微信
公众号

扫码关注公众号