/**
  * @param ClassFinderAdapter $adapter
  * @param array $prefixes
  */
 protected function addMultipleWithTargetDir($adapter, array $prefixes)
 {
     $default_behavior = new DefaultDirectoryBehavior();
     $psr0_behavior = new Psr0DirectoryBehavior();
     $namespace_map = array();
     $prefix_map = array();
     $target_dir_strlen = strlen($this->targetDir);
     foreach ($prefixes as $prefix => $paths) {
         if (FALSE === strpos($prefix, '\\')) {
             $logical_base_path = Util::prefixLogicalPath($prefix);
             foreach ((array) $paths as $root_path) {
                 $deep_path = strlen($root_path) ? rtrim($root_path, '/') . '/' . $logical_base_path : $logical_base_path;
                 if (0 !== strpos($deep_path, $this->targetDir)) {
                     continue;
                 }
                 $deep_path = $this->pathPrefix . substr($deep_path, $target_dir_strlen);
                 $prefix_map[$logical_base_path][$deep_path] = $default_behavior;
             }
         }
         $logical_base_path = Util::namespaceLogicalPath($prefix);
         foreach ((array) $paths as $root_path) {
             $deep_path = strlen($root_path) ? rtrim($root_path, '/') . '/' . $logical_base_path : $logical_base_path;
             if (0 !== strpos($deep_path, $this->targetDir)) {
                 continue;
             }
             $deep_path = $this->pathPrefix . substr($deep_path, $target_dir_strlen);
             $namespace_map[$logical_base_path][$deep_path] = $psr0_behavior;
         }
     }
     if (!empty($prefix_map)) {
         $adapter->getPrefixMap()->registerDeepPaths($prefix_map);
     }
     $adapter->getNamespaceMap()->registerDeepPaths($namespace_map);
 }
Ejemplo n.º 2
0
 /**
  * @param ClassFinderAdapter $adapter
  */
 function writeToAdapter($adapter)
 {
     // PSR-0 namespaces / prefixes
     if (is_file($this->dir . '/autoload_namespaces.php')) {
         $prefixes = (require $this->dir . '/autoload_namespaces.php');
         if (!empty($prefixes)) {
             $adapter->addMultiplePsr0($prefixes);
         }
     }
     // PSR-4 namespaces
     if (is_file($this->dir . '/autoload_psr4.php')) {
         $map = (require $this->dir . '/autoload_psr4.php');
         if (!empty($map)) {
             $adapter->addMultiplePsr4($map);
         }
     }
     // Class map
     if (is_file($this->dir . '/autoload_classmap.php')) {
         $class_map = (require $this->dir . '/autoload_classmap.php');
         if (!empty($class_map)) {
             $adapter->addClassMap($class_map);
         }
     }
     // Include path
     if (is_file($this->dir . '/include_paths.php')) {
         $include_paths = (require $this->dir . '/include_paths.php');
         if (!empty($include_paths)) {
             array_push($include_paths, get_include_path());
             set_include_path(join(PATH_SEPARATOR, $include_paths));
         }
     }
     // Include files
     if (is_file($this->dir . '/autoload_files.php')) {
         $include_files = (require $this->dir . '/autoload_files.php');
         foreach ($include_files as $file) {
             require $file;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param ClassFinderAdapter $adapter
  * @param string[] $sources_raw
  *   Array of files and folders to scan for class implementations.
  */
 protected function addClassmapSources($adapter, array $sources_raw)
 {
     foreach ($sources_raw as &$path) {
         $path = $this->pathPrefix . $path;
     }
     $adapter->addClassmapSources($sources_raw);
 }
 /**
  * Adds a prefix similar to PEAR, but with flat directories.
  *
  * This will assume with no further checks that $prefix contains no namespace
  * separator.
  *
  * @param string $prefix
  *   The prefix, e.g. 'Acme_FooPackage_'
  * @param string|string[] $paths
  *   An array of paths, or one specific path.
  *   E.g. 'lib' for $relative = TRUE,
  *   or 'sites/all/libraries/AcmeFooPackage/lib' for $relative = FALSE.
  * @param bool $relative
  *   If TRUE, the paths will be relative to $this->localDirectory.
  */
 function addPearFlat($prefix, $paths, $relative = TRUE) {
   $relative && $this->prependToPaths($paths);
   $this->master->addPearFlat($prefix, $paths);
 }
Ejemplo n.º 5
0
 /**
  * @param ExtendedClassFinderInterface $finder
  *   The class finder object.
  * @param string $localDirectory
  *
  * @return self
  */
 static function create($finder, $localDirectory)
 {
     $adapter = ClassFinderAdapter::create($finder);
     return new self($adapter, $localDirectory);
 }