本文整理汇总了PHP中Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter类的典型用法代码示例。如果您正苦于以下问题:PHP ParamConverter类的具体用法?PHP ParamConverter怎么用?PHP ParamConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParamConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: supports
/**
* 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();
}
示例2: execute
/**
* 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;
}
示例3: checkFailureOnValidationError
/**
* @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;
}
示例4: it_should_support
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);
}
示例5: supports
function supports(ParamConverter $configuration)
{
if ('json' !== $configuration->getNAme()) {
return false;
}
return true;
}
示例6: supports
/**
* {@inheritdoc}
*/
public function supports(ParamConverter $configuration)
{
if (null === $configuration->getClass()) {
return false;
}
return isset(self::$supportedTypes[$configuration->getClass()]);
}
示例7: supports
/**
* {@inheritdoc}
*/
public function supports(ParamConverter $configuration)
{
if (!$configuration->getClass()) {
return false;
}
return true;
}
示例8: supports
/**
* 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;
}
示例9: supports
/**
* {@inheritdoc}
*/
public function supports(ParamConverter $configuration)
{
if (!($class = $configuration->getClass())) {
return false;
}
return 'DTO' === strtoupper(substr($class, -3));
}
示例10: onKernelController
/**
* 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);
}
示例11: supports
/**
* {@inheritdoc}
*/
public function supports(ParamConverter $configuration)
{
if (null === $configuration->getClass()) {
return false;
}
return "DateTime" === $configuration->getClass();
}
示例12: onCoreController
/**
* 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);
}
示例13: supports
public function supports(ParamConverter $configuration)
{
if (null === $configuration->getClass()) {
return false;
}
return in_array($configuration->getClass(), $this->supportedTypes);
}
示例14: supports
/**
* @param ParamConverter $configuration
* @return bool
*/
public function supports(ParamConverter $configuration)
{
if (null === $configuration->getClass()) {
return false;
}
return 'CiTron\\Project\\Entity\\Project' === $configuration->getClass();
}
示例15: execute
/**
* 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;
}