/** * * @param String $filename réal path of the php file to scan ex: /home/project/src/org/foo/bar.php * @param String $namespace the name space of this file ex: org\foo * @return void * @throws IocException */ protected function scanFile($filename, $namespace) { if (!is_file($filename)) { \org\equinox\utils\Logger::error("({$filename}) is not a file!"); throw new IocException("({$filename}) is not a file!"); } include_once $filename; $name = basename($filename); $className = $namespace . '\\' . substr($name, 0, strpos($name, '.')); if (class_exists($className)) { $ref = new \ReflectionAnnotatedClass($className); $listAnnotation = $ref->getAllAnnotations(); if (empty($listAnnotation)) { return; // this class is not a Component ! } $bean = new BeanDefinition(); $bean->setClassName($className); foreach ($listAnnotation as $annotation) { if ($annotation instanceof annotations\ClassAnnotation) { $annotation->doBean($bean, $className); } } if ($bean->getId() == null) { throw new IocException("Equinox annotation found but no @Component annotation found (mandatory) in {$className}"); } $listProperties = $ref->getProperties(); foreach ($listProperties as $property) { $this->doProperty($bean, $property); } $listMethod = $ref->getMethods(); foreach ($listMethod as $method) { $this->doMethod($bean, $method); } $this->context->addBeanDefinition($bean); } }
protected function addBean(\SimpleXMLElement $node, $xmlFile) { $bean = new BeanDefinition(); $id = trim((string) $node['id']); if ($id == '') { throw new IocException("A bean without id has been found! In file ({$xmlFile})"); } $bean->setId($id); $className = trim((string) $node['class']); if ($className == '') { throw new IocException("Bean ({$id}) must have a class attribute in file ({$xmlFile})"); } $bean->setClassName($className); $scope = trim((string) $node['scope']); if ($scope == '') { $scope = BeanDefinition::SCOPE_SINGLETON; } $bean->setScope($scope); foreach ($node->property as $property) { $bean->addProperty($this->doProperty($property, $xmlFile)); } $bean->setInitMethod(trim((string) $node['init-method'])); $lazyInit = trim((string) $node['lazy-init']); if ($lazyInit == 'false') { $bean->setLazyInit(false); } $this->applicationContext->addBeanDefinition($bean); }