public function __invoke(DocTagInterface $tag, ReflectionMethod $method, RepositoryAbstract $repository) { $cacheKey = $method->getDeclaringClass()->getName() . $method->getName() . $tag->getValue(); if (!isset(self::$cache[$cacheKey])) { self::$cache[$cacheKey] = $this->generateCacheDriverInfo($tag->getValue()); } if (!self::$cache[$cacheKey]['driver']) { return; } if (!$repository->hasCacheDriver(self::$cache[$cacheKey]['driver'])) { throw new InvalidArgumentException(sprintf('Cannot apply cache driver "%s" to method "%s" in repository "%s" using the doc tag "%s" because that cache driver was not set.', self::$cache[$cacheKey]['driver'], $method->getName(), get_class($repository), $tag->getName())); } $repository->setCacheDriverFor($method->getName(), self::$cache[$cacheKey]['driver'], self::$cache[$cacheKey]['lifetime']); }
public function __invoke(DocTagInterface $tag, ReflectionClass $class, Entity $entity) { $parts = explode(' ', $tag->getValue(), 2); $validator = $this->resolveValidator($parts[0], $entity); $message = isset($parts[1]) ? $parts[1] : null; $message = $message ?: 'Entity "' . $class->getName() . '" is not valid.'; $entity->addValidator($message, $validator); }
public function __invoke(DocTagInterface $tag, ReflectionProperty $property, Entity $entity) { $configurator = $tag->getValue(); if (!class_exists($configurator)) { throw new InvalidArgumentException(sprintf('Cannot configure property "%s" for entity "%s" because the configuration class "%s" does not exist.', $property->getName(), get_class($entity), $configurator)); } $configurator = new $configurator(); $configurator->__invoke($entity); }
public function __invoke(DocTagInterface $tag, ReflectionClass $class, Entity $entity) { $info = $this->parseFilterInformation($tag->getValue()); if ($info['direction'] === 'to') { $entity->addExportFilter($info['name'], new $info['class']()); } else { $entity->addImportFilter($info['name'], new $info['class']()); } }
public function __invoke(DocTagInterface $tag, ReflectionMethod $method, RepositoryAbstract $repository) { $cacheKey = $method->getDeclaringClass()->getName() . $method->getName(); if (!isset(self::$cache[$cacheKey])) { self::$cache[$cacheKey] = $this->generateFilter($tag->getValue(), $repository); } if (is_callable(self::$cache[$cacheKey])) { $repository->setReturnValueFilter($method->getName(), self::$cache[$cacheKey]); } }
private function generateClass(DocTagInterface $tag, Entity $entity) { $parts = preg_split('/\\s+/', $tag->getValue(), 2); $class = function () use($parts) { if (isset($parts[1])) { $class = eval('return new ' . $parts[0] . '(' . $parts[1] . ');'); } else { $class = new $parts[0](); } return $class; }; $class = $class->bindTo($entity); $class = $class(); return $class; }
public function __invoke(DocTagInterface $tag, ReflectionClass $class, Entity $entity) { $parts = explode(' ', $tag->getValue()); $name = array_shift($parts); $key = $class->getName() . $name; if (isset(self::$cache[$key])) { $entity->setMapper($name, self::$cache[$key]); return; } $mapArr = new MapperArray(); foreach ($parts as $class) { if ($class = trim($class)) { $mapArr->add(new $class()); } } $entity->setMapper($name, $mapArr); self::$cache[$key] = $mapArr; }
public function __invoke(DocTagInterface $tag, ReflectionProperty $property, Entity $entity) { $entity->setAutoloader($property->getName(), $tag->getValue()); }