/** * {@inheritdoc} */ public function getPropertyValue(\ReflectionProperty $property) { $class = $this->reflectionTools->getPropertyClass($property); if ($class == Request::class) { return $this->request; } $name = $property->getName(); if (isset($this->parameters[$name])) { return $this->parameters[$name]; } return $this->fallbackResolver->getPropertyValue($property); }
/** * {@inheritdoc} */ public function getPropertyValue(\ReflectionProperty $property) { // Check if an injection key is available for this property. $key = $this->injectionPolicy->getPropertyKey($property); if ($key !== null) { return $this->container->get($key); } // Try to resolve the property by type. $className = $this->reflectionTools->getPropertyClass($property); if ($className !== null) { if ($this->container->has($className)) { return $this->container->get($className); } } return $this->defaultValueResolver->getPropertyValue($property); }
/** * @param \ReflectionClass $class * @param object $object * * @return void */ private function injectProperties(\ReflectionClass $class, $object) { foreach ($this->reflectionTools->getClassProperties($class) as $property) { if ($this->policy->isPropertyInjected($property)) { $value = $this->resolver->getPropertyValue($property); $property->setAccessible(true); $property->setValue($object, $value); } } }
/** * Finds an annotation on the controller class or method. * * If the annotation is found on both the controller class and method, the method annotation is returned. * If the annotation is found on several classes in the hierarchy of controller classes, * the annotation of the child class is returned. * * This method does not support controller functions outside a class. * * @param \ReflectionFunctionAbstract $controller * @param string $annotationClass * * @return object|null The annotation, or null if not found. */ protected function getControllerAnnotation(\ReflectionFunctionAbstract $controller, string $annotationClass) { if ($controller instanceof \ReflectionMethod) { $annotations = $this->annotationReader->getMethodAnnotations($controller); foreach ($annotations as $annotation) { if ($annotation instanceof $annotationClass) { return $annotation; } } $class = $controller->getDeclaringClass(); $classes = $this->reflectionTools->getClassHierarchy($class); foreach ($classes as $class) { $annotations = $this->annotationReader->getClassAnnotations($class); foreach ($annotations as $annotation) { if ($annotation instanceof $annotationClass) { return $annotation; } } } } return null; }
/** * @param mixed $variable The variable to copy. * @param boolean $pack True to pack, false to unpack. * @param array $visited The visited objects, for recursive calls. * @param int $level The nesting level. * * @return mixed */ private function copy($variable, $pack, array &$visited = [], $level = 0) { if (is_object($variable)) { $hash = spl_object_hash($variable); if (isset($visited[$hash])) { return $visited[$hash]; } $processed = $pack ? $this->objectPacker->pack($variable) : $this->objectPacker->unpack($variable); if ($processed) { return $visited[$hash] = $processed; } $class = new \ReflectionClass($variable); $properties = $this->reflectionTools->getClassProperties($class); if (!$class->isUserDefined()) { if ($class->isCloneable()) { return $visited[$hash] = clone $variable; } else { return $visited[$hash] = $variable; } } $visited[$hash] = $copy = $class->newInstanceWithoutConstructor(); foreach ($properties as $property) { $property->setAccessible(true); $value = $property->getValue($variable); $processed = $this->copy($value, $pack, $visited, $level + 1); $property->setValue($copy, $processed); } return $copy; } if (is_array($variable)) { foreach ($variable as &$value) { $value = $this->copy($value, $pack, $visited, $level + 1); } } return $variable; }
/** * @param string $key * * @return bool */ public function has(string $key) { if (!isset($this->items[$key])) { if (class_exists($key)) { $class = new \ReflectionClass($key); $classes = $this->reflectionTools->getClassHierarchy($class); foreach ($classes as $class) { if ($this->injectionPolicy->isClassInjected($class)) { $this->bind($key); // @todo allow to configure scope (singleton) with annotations break; } } } } return isset($this->items[$key]); }
/** * @dataProvider providerExportFunction * * @param string $method * @param integer $excludeModifiers * @param string $expected */ public function testExportFunction($method, $excludeModifiers, $expected) { $tools = new ReflectionTools(); $function = new \ReflectionMethod(__NAMESPACE__ . '\\Export', $method); $this->assertSame($expected, $tools->exportFunction($function, $excludeModifiers)); }
require __DIR__ . '/vendor/autoload.php'; $classes = []; foreach (glob($proxyDir . '*.php') as $file) { if (basename($file) != 'ProxyInterface.php') { unlink($file); } } foreach (glob($classFiles) as $file) { $classes[] = pathinfo($file, PATHINFO_FILENAME); } $proxyTemplate = file_get_contents($proxyTemplate); $proxyTemplate = preg_replace('|/\\* (.+?) \\*/|', '$1', $proxyTemplate); preg_match('|// BEGIN METHOD TEMPLATE(.+)// END METHOD TEMPLATE|s', $proxyTemplate, $matches); $methodTemplate = $matches[1]; $proxyTemplate = str_replace($matches[0], '// METHODS', $proxyTemplate); $reflectionTools = new ReflectionTools(); foreach ($classes as $class) { $class = new ReflectionClass($classNamespace . '\\' . $class); if ($class->getName() == CoordinateSystem::class) { continue; } $methods = ''; foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->isConstructor() || $method->isStatic()) { continue; } if (strpos($method->getDocComment(), '@noproxy') !== false) { continue; } $methodCode = $methodTemplate; $methodCode = str_replace('function _TEMPLATE_()', $reflectionTools->exportFunction($method, \ReflectionMethod::IS_ABSTRACT), $methodCode);