/** * @TODO utilisation d'une interface ? RoutableInterface ou un truc comme ça * @TODO utilisation de PropertyPath * @TODO Gestion de la datetime et slugify (voir invenio) (setUrlizeStrategy ?) * Renvoi les paramètres de la route en fonction de l'objet $objet. (Utilisation de toArray ?) * Si le paramètre n'existe pas sur l'objet il est ignoré * * @param array $keys * @param object $object * * @return array */ protected function getParametersFromObject(array $keys, $object) { $parameters = []; foreach ($keys as $key) { $set = false; if (strpos($key, '_') !== false) { $value = $object; foreach (explode('_', $key) as $segment) { $method = 'get' . Parser::camelize($segment); if (method_exists($value, $method)) { $value = $value->{$method}(); $set = true; } else { $set = false; break; } } } else { $method = 'get' . Parser::camelize($key); if (method_exists($object, $method)) { $value = $object->{$method}(); $set = true; } } if ($set) { $parameters[$key] = $value; } } return $parameters; }
/** * @param array $viewOptions * @param array $constraints */ private function addViewOptionsFromConstraint(array &$viewOptions, $constraints) { if (array_key_exists('Range', $constraints)) { $attr = isset($viewOptions['attr']) ? $viewOptions['attr'] : []; $viewOptions['attr'] = array_merge($attr, Parser::filterArrayByKeys($constraints['Range'], ['min', 'max'])); } }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if ($value->getStatus() === $constraint->status) { foreach ($constraint->required_fields as $field) { $getter = 'get' . Parser::camelize($field); if (!$value->{$getter}()) { $this->context->buildViolation($this->getConstraintMessage($value, $field, $constraint))->atPath($field)->addViolation(); } } } }
/** * @param object $object * @param string $field * * @return mixed */ public function field($object, $field) { //@TODO refactoring with routing system $buffer = strpos($field, '_') === false ? [$field] : explode('_', $field); $value = $object; foreach ($buffer as $segment) { $getter = 'get' . Parser::camelize($segment); $value = $value->{$getter}(); } return $value; }
/** * @param QueryBuilder $qb * @param string $alias * @param array $criteria */ protected function parseCriteria(QueryBuilder $qb, $alias, array $criteria) { $criteria = Parser::cleanArray($criteria); foreach ($criteria as $key => $value) { if (is_array($value)) { $qb->andWhere($this->arrayToClause($alias, $key, $value)); } else { $qb->andWhere($this->generateWherePart($alias, $key, null, $this->getWhereOperator($value))); $qb->setParameter($alias . '_' . $key, $this->getWhereValue($value)); } } }
/** * @param string $format * * @return string */ public function getResourceLocation($format = 'bundle') { $reflection = new \ReflectionClass(get_class($this)); $namespace = $reflection->getNamespaceName(); switch ($format) { case 'bundle': return Parser::getBundleClass($namespace); break; case 'namespace': return $namespace; break; } }
public function prePersist(LifecycleEventArgs $eventArgs) { $entity = $eventArgs->getObject(); if ($entity instanceof SortableInterface) { $em = $eventArgs->getEntityManager(); $repo = $em->getRepository($em->getClassMetadata(get_class($entity))->getName()); $config = $repo->getSortableConfiguration(); $setter = 'set' . Parser::camelize($config['position']); $getter = 'get' . Parser::camelize($config['position']); if ($entity->{$getter}() === null) { $entity->{$setter}($repo->getNewOrder($entity, 'sort')); } } }
/** * @param object $entity * @param string $alias * * @return object|null */ public function getPreviousEntity($entity, $alias) { $qb = $this->getOrderableQuery($entity, $alias); $qb->select($alias); $qb->andWhere($alias . '.' . $this->config['position'] . ' < :position'); $getter = 'get' . Parser::camelize($this->config['position']); $qb->setParameter('position', $entity->{$getter}()); $qb->orderBy($alias . '.order', 'DESC'); $qb->setMaxResults(1); return $qb->getQuery()->getOneOrNullResult(); }
public function cleanArrayData(FormEvent $event) { $event->setData(Parser::cleanArray($event->getData(), 'all')); }
/** * @param string $bundle * @param string $filepath * * @return string */ public static function getFilePath($bundle, $filepath) { $bundleclass = Parser::getBundleClass($bundle); $reflection = new \ReflectionClass($bundleclass); return dirname($reflection->getFileName()) . '/' . $filepath; }