load routes from path

被加载的文件必须以: 类名.php的形式命名
@param string $fromPath
@param string $namespace
@param string[] $hooks
@return void
500116
public function loadRoutesFromPath($fromPath, $namespace = '', $hooks=[])
    {
        $dir = @dir($fromPath) or abort("dir $fromPath not exist");

        $getEach = function () use ($dir) {
            $name = $dir->read();
            if (!$name) {
                return $name;
            }
            return $name;
        };

        while (!!($entry = $getEach())) {
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            $path = $fromPath . '/' . str_replace('\\', '/', $entry);
            if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) {
                $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4);
                $this->loadRoutesFromClass($class_name, $hooks);
            } else {
                //\Log::debug($path.' ignored');
            }
        }
    }
47657
public function loadFile($directory, $namespace, $closure)
    {
        $files = $this->getFiles($directory);

        $classes = [];

        $files->map(function($file) use($closure, $namespace, &$classes, &$files){


            $namespace = str_replace(base_path()."/src", "", $file);
            $namespace = dirname($namespace);
            $namespace = str_replace("/", "\\", $namespace)."\\";


            if (!is_dir($file)) {

                $class = $this->getClassByBasename(basename($file), $namespace);
                $classes[] = $class;
                $files[] = $file;
            }
        });

        foreach ($classes as $class) {

            $closure($class);
        }

    }
448280
public static function namespace($key, $path){
        if(!array_key_exists($key, self::$namespaces))
            self::$namespaces[$key] = $path;
    }
101181
public function addPath(string $path, string $namespace = null): void
    {
        $namespace = $namespace ?: FileViewFinder::DEFAULT_NAMESPACE;
        $this->finder->addPath($path, $namespace);
    }
465377
public function remove($fromSource, $paths): bool
    {
        $paths = (array)$paths;
        $fromSource = $this->cleanSource($fromSource);
        list($alias) = $this->parse($fromSource);

        $return = false;

        foreach ($paths as $origPath) {
            $path = $this->cleanPathInternal($this->cleanPath($origPath));

            $key = array_search($path, $this->paths[$alias], true);
            if (false !== $key) {
                unset($this->paths[$alias][$key]);
                $return = true;
            }
        }

        return $return;
    }
552235
public function copy(string $fromPath, string $toPath): array
    {
        $parameters = [
            'from_path' => $this->normalizePath($fromPath),
            'to_path' => $this->normalizePath($toPath),
        ];

        return $this->rpcEndpointRequest('files/copy_v2', $parameters);
    }
203080
def load_from_path(self, filepath, container, **opts):
        
        root = ET.parse(filepath).getroot()
        nspaces = _namespaces_from_file(filepath)
        return root_to_container(root, container=container,
                                 nspaces=nspaces, **opts)
871884
public function load(string $path, string ...$paths): void
    {
        array_unshift($paths, $path);
        foreach ($paths as $path) {
            if (!is_readable($path) || is_dir($path) || ($contents = parse_ini_file($path, false)) === false) {
                throw new InvalidArgumentException("{$path} is not a readable file.");
            }
            $this->populate($contents);
        }
    }
137983
def _path_hooks(cls, path):  # from importlib.PathFinder
        """"""
        if sys.path_hooks is not None and not sys.path_hooks:
            warnings.warn('sys.path_hooks is empty', ImportWarning)
        for hook in sys.path_hooks:
            try:
                return hook(path)
            except ImportError:
                continue
        else:
            return None
804526
static function load($namespace,$folder = ''){
	
		if(!isset(self::$files[$namespace])){
			$ns = self::getName($namespace,$folder);
			
			if(!file_exists($ns->path)){
				Exceptions::showError('Server Error','Missing File '.$ns->path.' Not Found');
				exit;
			}
			
			require_once $ns->path;
			self::$files[$namespace] = $ns;
		}
	}
1365714
public function addPath(string $path, string $namespace = self::DEFAULT_NAMESPACE)
    {
        // invalidate the cache
        $this->cache = $this->errorCache = [];

        $this->paths[$namespace][] = rtrim($path, '/\\');
    }
1212314
public function namespaced($namespace, Closure $block)
    {
        $this->paths[]      = $namespace;
        $this->modules[]    = $namespace;
        $this->routeNames[] = $namespace;
        $block();
        array_pop($this->paths);
        array_pop($this->modules);
        array_pop($this->routeNames);
    }
1352217
public static function load(string $path = null, array $paths = []): self
    {
        if (null === $path) {
            $config = [];
        } else {
            if (false === (new Filesystem())->isAbsolutePath($path)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to load to be an absolute path, got "%s" '
                        .'instead',
                        $path
                    )
                );
            }

            if (false === file_exists($path)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to exists but the file "%s" could not be '
                        .'found',
                        $path
                    )
                );
            }

            if (false === is_file($path) && false === (is_link($path) && is_file(readlink($path)))) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected the path of the configuration file to be a file but "%s" appears to be a '
                        .'directory.',
                        $path
                    )
                );
            }

            $config = include $path;

            if (false === is_array($config)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Expected configuration to be an array, found "%s" instead.',
                        gettype($config)
                    )
                );
            }
        }

        self::validateConfigKeys($config);

        $prefix = self::retrievePrefix($config);

        $whitelistedFiles = null === $path ? [] : self::retrieveWhitelistedFiles(dirname($path), $config);

        $patchers = self::retrievePatchers($config);

        array_unshift($patchers, new SymfonyPatcher());

        $whitelist = self::retrieveWhitelist($config);

        $finders = self::retrieveFinders($config);
        $filesFromPaths = self::retrieveFilesFromPaths($paths);
        $filesWithContents = self::retrieveFilesWithContents(chain($filesFromPaths, ...$finders));

        return new self($path, $prefix, $filesWithContents, $patchers, $whitelist, $whitelistedFiles);
    }
1113559
protected function classMapFromPath($subPath, $namespace = null)
    {
        $messages = array();
        $classMap = $this->generator->scan($subPath, null, $namespace, $messages);

        if ($messages) {
            foreach ($messages as $message) {
                $this->report->warn(new GenericViolation($message));
            }
        }

        foreach ($classMap as $class => $file) {
            try {
                $this->classMap->add($class, $file);
            } catch (ClassAlreadyRegisteredException $exception) {
                $this->report->append(
                    new ClassAddedMoreThanOnceViolation(
                        $this->getName(),
                        $class,
                        array(
                            $exception->getFileName(),
                            $file
                        )
                    )
                );
            }
        }

        return $classMap;
    }
1202699
public static function resolveRelatedPath($from, $to)
    {
        $from_parts = array_filter( explode('/', $from) );
        $to_parts = array_filter( explode('/', $to) );
        foreach($from_parts as $i=>$path) {
            if (in_array($path, $to_parts)) {
                $from_parts[$i] = null;
                $to_parts[$i] = null;
            }
        }
        $from_parts = array_filter($from_parts);
        $to_parts = array_filter($to_parts);
        for($i=0; $i<count($from_parts); $i++) {
            array_unshift($to_parts, '..');
        }
/*
        foreach($from_parts as $path) {
            array_unshift($to_parts, $path);
        }
*/
        return join('/', $to_parts);
    }
857157
protected function loadConstantsFrom($path, $namespace = null)
    {
        $constants = require $path;
        $prefix = $namespace ? "$namespace" : '';

        foreach ($constants as $constant => $value) {
            define(strtoupper("{$prefix}{$constant}"), $value);
        }
    }
486497
public function browse(Request $request, $namespace, $path)
    {
        $directory = $this->filesystem()->getDir("$namespace://$path");
        $listing = new Listing($directory);
        $showHidden = $this->isAllowed('files:hidden');

        try {
            $directories = $listing->getDirectories($showHidden);
            $files = $listing->getFiles($showHidden);
        } catch (IOException $e) {
            $this->logException(Trans::__('page.file-management.message.folder-not-found', ['%s' => $path]), $e);
            $directories = [];
            $files = [];
        }

        $context = [
            'directory'   => $directory,
            'directories' => $directories,
            'files'       => $files,
            'multiselect' => $request->query->getBoolean('multiselect'),
        ];

        return $this->render('@bolt/async/browse.twig', ['context' => $context]);
    }