/** * {@inheritdoc} */ public function getDefinition($name, MergeableDefinition $parentDefinition = null) { // Only merges with class definition if ($parentDefinition && !$parentDefinition instanceof ClassDefinition) { return null; } $className = $parentDefinition ? $parentDefinition->getClassName() : $name; if (!class_exists($className) && !interface_exists($className)) { return null; } $class = new ReflectionClass($className); $definition = new ClassDefinition($name); // Constructor $constructor = $class->getConstructor(); if ($constructor && $constructor->isPublic()) { $definition->setConstructorInjection($this->getConstructorInjection($constructor)); } // Merge with parent if ($parentDefinition) { $definition = $parentDefinition->merge($definition); } return $definition; }
/** * Browse the object's methods looking for annotated methods. * * @param ReflectionClass $class * @param ClassDefinition $classDefinition */ private function readMethods(ReflectionClass $class, ClassDefinition $classDefinition) { // This will look in all the methods, including those of the parent classes foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->isStatic()) { continue; } $methodInjection = $this->getMethodInjection($method); if (!$methodInjection) { continue; } if ($method->isConstructor()) { $classDefinition->setConstructorInjection($methodInjection); } else { $classDefinition->addMethodInjection($methodInjection); } } }