/** * {@inheritdoc} */ public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } return 'Bluemesa\\Bundle\\CoreBundle\\Entity\\DatePeriod' === $configuration->getClass(); }
/** * {@inheritdoc} */ public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } return isset(self::$supportedTypes[$configuration->getClass()]); }
public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } return in_array($configuration->getClass(), $this->supportedTypes); }
/** * @param ParamConverter $configuration * @return bool */ public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } return 'CiTron\\Project\\Entity\\Project' === $configuration->getClass(); }
/** * {@inheritdoc} */ public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } return 'ArrayObject' === $configuration->getClass(); }
/** * 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; }
/** * {@inheritdoc} */ public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } return "DateTime" === $configuration->getClass(); }
public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } $class = $configuration->getClass(); return $class == 'Staffim\\DTOBundle\\Collection\\Pagination'; }
public function supports(ParamConverter $configuration) { if (null === $configuration->getClass()) { return false; } $supportedTypes = [SearchRequest::class, SearchRequestInterface::class]; return in_array($configuration->getClass(), $supportedTypes); }
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; }
/** * 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; } if (array_key_exists($configuration->getClass(), $this->targetEntitiesArray)) { return true; } else { return false; } }
/** * @inheritdoc */ public function supports(ParamConverter $configuration) { if ($configuration->getClass() === null) { return false; } try { $class = new \ReflectionClass($configuration->getClass()); } catch (\ReflectionException $e) { return false; } return $this->reader->getClassAnnotation($class, RequestAnnotation::class) !== null; }
/** * @inheritdoc */ public function supports(ParamConverter $configuration) { // Check, if option class was set in configuration if (null === $configuration->getClass()) { return false; } // Get the manager for the passed class (by default, the default entity manager) $manager = $this->getDoctrine()->getManagerForClass($configuration->getClass()); // Check that the manager has the correct Class if ('WCS\\CantineBundle\\Entity\\Eleve' !== $manager->getClassMetadata($configuration->getClass())->getName()) { return false; } return true; }
/** * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration * @return bool */ public function supports(ParamConverter $configuration) { if (!$configuration instanceof ParamConverter) { return false; } if (!class_exists($configuration->getClass()) && !interface_exists($configuration->getClass())) { return false; } $implements = class_implements($configuration->getClass()); if (in_array('FSi\\Bundle\\AdminBundle\\Admin\\Element', $implements)) { return true; } return false; }
/** * {@inheritdoc} */ function supports(ParamConverter $configuration) { if (null === $this->registry || !count($this->registry->getManagers())) { return false; } if (null === $configuration->getClass()) { return false; } $em = $this->registry->getManagerForClass($configuration->getClass()); if ('SensorBundle\\Entity\\Measure' !== $em->getClassMetadata($configuration->getClass())->getName()) { return false; } return true; }
/** * {@inheritdoc} */ public function supports(ParamConverter $configuration) { if (!$configuration->getClass()) { return false; } return true; }
/** * {@inheritdoc} */ public function supports(ParamConverter $configuration) { if (!($class = $configuration->getClass())) { return false; } return 'DTO' === strtoupper(substr($class, -3)); }
/** * @{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; }
/** * {@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; }
/** * 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; }
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); }
public function supports(ParamConverter $configuration) { $class = $configuration->getClass(); if (!is_string($class)) { return null; } return is_subclass_of($class, 'Surfnet\\StepupBundle\\Request\\JsonConvertible'); }
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(); }
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(); } return $options; }
public function supports(ParamConverter $configuration) { if (null === $this->container) { return false; } if ($configuration->getClass() !== 'AppBundle\\Model\\Wiki') { return false; } return true; }
/** * {@inheritdoc} * * Applies converting * * @throws \InvalidArgumentException When route attributes are missing * @throws NotFoundHttpException When object not found */ public function apply(Request $request, ParamConverter $configuration) { $username = $request->attributes->get('username'); $rssToken = $request->attributes->get('token'); // Check, if route attributes exists if (null === $username || null === $rssToken) { throw new \InvalidArgumentException('Route attribute is missing'); } // Get actual entity manager for class $em = $this->registry->getManagerForClass($configuration->getClass()); $userRepository = $em->getRepository($configuration->getClass()); // Try to find user by its username and config rss_token $user = $userRepository->findOneByUsernameAndRsstoken($username, $rssToken); if (null === $user || !$user instanceof User) { throw new NotFoundHttpException(sprintf('%s not found.', $configuration->getClass())); } // Map found user to the route's parameter $request->attributes->set($configuration->getName(), $user); }
function it_should_properly_convert_parameter(Request $request, ParamConverter $paramConverter, Project $project, ProjectRepository $projectRepository, ParameterBag $parameterBag) { $parameterBag->has('projectSlug')->willReturn(true); $parameterBag->get('projectSlug')->willReturn('foobar'); $parameterBag->set(Argument::type('string'), Argument::any())->shouldBeCalled(); $request->attributes = $parameterBag; $projectRepository->findOneBy(['slug' => 'foobar'])->willReturn($project); $paramConverter->getClass()->willReturn('CiTron\\Project\\Entity\\Project'); $paramConverter->getName()->willReturn('project'); $this->apply($request, $paramConverter)->shouldReturn(true); }
/** * 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(); $content = json_decode($request->getContent(), true); /** @var Url $model */ $model = $this->deserializeUrl($content, $class); $request->attributes->set($name, $model); $request->attributes->set(Alias::DATA, $name); return true; }
/** * Stores the object in the request. * * @param Request $request The request * @param ParamConverter $configuration Contains the name, class and options of the object * * @throws \InvalidArgumentException * * @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(); $options = $configuration->getOptions(); if (isset($options['query'])) { $content = new \stdClass(); $metadata = $this->serializer->getMetadataFactory()->getMetadataForClass($class); foreach ($metadata->propertyMetadata as $propertyMetadata) { if (!$propertyMetadata->readOnly) { $property = $propertyMetadata->name; $value = $request->query->get($propertyMetadata->name); if (!is_null($value)) { $content->{$property} = $request->query->get($propertyMetadata->name); } } } $content = json_encode($content); } else { $content = $request->getContent(); } if (!class_exists($class)) { throw new \InvalidArgumentException($class . ' class does not exist.'); } $success = false; try { $model = $this->serializer->deserialize($content, $class, 'json'); $success = true; } catch (\Exception $e) { $model = new $class(); } /** * Validate if possible */ if ($model instanceof ValidatableInterface) { $violations = $this->validator->validate($model); $valid = $success && !(bool) $violations->count(); $model->setViolations($violations); $model->setValid($valid); } /** * Adding transformed collection * to request attribute. */ $request->attributes->set($name, $model); /** * Alias to access current collection * Used by exception listener */ $request->attributes->set(Alias::DATA, $name); return true; }
/** * 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(); $contents = json_decode($request->getContent(), true); $collection = new ArrayCollection(); foreach ($contents as $content) { $collection->add($this->deserializeUrl($content, $class)); } $request->attributes->set($name, $collection); $request->attributes->set(Alias::DATA, $name); return true; }