private function &_parseIncludes(__Configuration &$configuration, $basedir)
 {
     $configuration_section = $configuration->getSection('configuration');
     if ($configuration_section != null) {
         //read configuration directives before read other sections:
         $configuration_directives = $configuration_section->getSection('configuration-directives');
         if ($configuration_directives != null) {
             $this->_readConfigurationDirectives($configuration_directives);
         }
         //read the other sections:
         $sections = $configuration_section->getSections();
         foreach ($sections as $section) {
             switch (strtoupper($section->getName())) {
                 case 'INCLUDE':
                     $expression = $section->getProperty('#text')->getContent();
                     //finally, resolve the path:
                     $expression = __PathResolver::resolvePath($expression, $basedir);
                     if (__Lion::getInstance()->getRuntimeDirectives()->getDirective('DEBUG_MODE') && (strpos($expression, '...') !== false || strpos($expression, '*') !== false)) {
                         $this->_configuration_locators[$expression] = $expression;
                     }
                     $files_to_include = __FileResolver::resolveFiles($expression);
                     foreach ($files_to_include as $file_to_include) {
                         $included_configuration = $this->loadConfigurationFile($file_to_include);
                         $configuration->merge($included_configuration);
                         unset($included_configuration);
                     }
                     break;
             }
         }
     }
     return $configuration;
 }
Exemplo n.º 2
0
 /**
  * Load the metadata xml specification
  *
  * @param string The base path to read the xml file from
  * @return boolean (True if all ok, False in other case)
  */
 private function _loadMetadata()
 {
     $return_value = array('mapping' => array(), 'autoloaders' => array(), 'classpaths' => array());
     #by default
     //Find any include path files recursively, under the base directory's lib directories
     if (is_dir($this->_normalized_basedir . DIRECTORY_SEPARATOR . 'libs')) {
         $includepath_files = __FileResolver::resolveFiles($this->_normalized_basedir . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . '...' . DIRECTORY_SEPARATOR . self::INCLUDE_PATH_FILENAME);
     } else {
         $includepath_files = array();
     }
     //Do an explicit check in the baseDir/config directory
     if (is_file($this->_normalized_basedir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . self::INCLUDE_PATH_FILENAME)) {
         $includepath_files[] = $this->_normalized_basedir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . self::INCLUDE_PATH_FILENAME;
     }
     //Go through each include file that we found, and parse the information.
     foreach ($includepath_files as $includepath_file) {
         libxml_use_internal_errors(true);
         $content = file_get_contents($includepath_file);
         $dom = new DomDocument("1.0");
         $dom->loadXml($content);
         if ($dom->documentElement != null) {
             foreach ($dom->documentElement->childNodes as $child) {
                 if ($child->nodeName == 'cluster') {
                     if (substr($child->getAttribute('path'), 0, 1) == '/') {
                         $current_dir = $this->_normalized_basedir . DIRECTORY_SEPARATOR;
                     } else {
                         $current_dir = rtrim(dirname($includepath_file), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
                     }
                     $path = trim($child->getAttribute('path'));
                     $path = preg_replace('/\\/\\.\\.\\.$/', '', $path, 1, $count);
                     if ($count == 1) {
                         $recursive = true;
                     } else {
                         $recursive = false;
                     }
                     $current_dir .= ltrim($path, '/');
                     foreach ($child->childNodes as $class_child) {
                         if ($class_child->nodeName == 'class' || $class_child->nodeName == 'interface') {
                             if (strpos($class_child->getAttribute('name'), '*') !== false) {
                                 $class_data = $this->_loadMetaClassesFromMappingRule($class_child, $current_dir, $recursive);
                                 $return_value['mapping'] = $class_data + $return_value['mapping'];
                             } else {
                                 $class_data = $this->_loadMetaClass($class_child, $current_dir);
                                 $return_value['mapping'][strtoupper($class_child->getAttribute('name'))] = $class_data;
                             }
                         }
                     }
                 } else {
                     if ($child->nodeName == 'autoload') {
                         if ($child->hasAttribute('class') && $child->hasAttribute('method')) {
                             $return_value['autoloaders'][$child->getAttribute('class')] = $child->getAttribute('method');
                         } else {
                             throw new Exception('Missing information to register the autoload method. It was expected a class and a method attribute.');
                         }
                     } else {
                         if ($child->nodeName == 'classpath') {
                             if ($child->hasAttribute('path')) {
                                 $return_value['classpaths'][] = $child->getAttribute('path');
                             } else {
                                 throw new Exception('Missing path attribute.');
                             }
                         }
                     }
                 }
             }
         } else {
             /**
              * @todo extract error loading classes location by ussing libxml_get_errors()
              */
             throw new Exception("Error parsing includepath file: " . $includepath_file);
         }
     }
     return $return_value;
 }