Get classes that implements the Command interface

@param string $namespace
@param string $path

@return array
507765
protected function getClasses($namespace, $path)
    {
        $classes = [];
        $path = "$path/Console/Command";
        if (!is_dir($path)) {
            return $classes;
        }

        $dir = new \DirectoryIterator($path);
        $classFiles = new \RegexIterator($dir, '/[a-z_]*\.php/i');
        foreach ($classFiles as $file) {
            $classes[] = str_replace('.php', '', "{$namespace}Console\\Command\\{$file}");
        }
        return $classes;
    }
1107418
protected function getNamespaceFromModuleJson($path)
    {
        $moduleProperties = $this->parseModuleJson($path);

        if (!isset($moduleProperties->module->namespace)) {
            throw new Exception('The namespace is not set in the module properties for the module in "' . $path . '".');
        }
        
        return Framework::prepareNamespace($moduleProperties->module->namespace);
    }
656641
private function parseFile(string $path): array
    {
        $json = json_decode(file_get_contents($path), true);
        $root = dirname($path);

        $namespaces = array_merge(
            iterator_to_array($this->parseNamespaces($json['autoload']['psr-4'] ?: [], $root)),
            iterator_to_array($this->parseNamespaces($json['autoload-dev']['psr-4'] ?: [], $root))
        );
        return $namespaces;
    }
1320114
protected static function selectClasses(string $path, string $classOrInterface): iterable
    {
        $selectedFiles = [];

        $flags = GlobIterator::SKIP_DOTS | GlobIterator::CURRENT_AS_PATHNAME;
        foreach (new GlobIterator($path, $flags) as $filePath) {
            if (is_file($filePath) === true) {
                $filePath = realpath($filePath);
                try {
                    /** @noinspection PhpIncludeInspection */
                    require_once $filePath;
                } catch (Exception $ex) {
                    // Files might have syntax errors and etc.
                    // For the purposes of this method it doesn't matter so just skip it.
                    continue;
                }
                $selectedFiles[$filePath] = true;
            }
        }

        foreach (get_declared_classes() as $class) {
            // if class actually implements requested one and ...
            if ($class === $classOrInterface || static::classInherits($class, $classOrInterface) === true) {
                // ... it was loaded from a file we've selected then...
                $reflectionClass = new ReflectionClass($class);
                if ($reflectionClass->isInstantiable() === true &&
                    ($classFileName = $reflectionClass->getFileName()) !== false &&
                    array_key_exists($classFileName, $selectedFiles) === true
                ) {
                    // ... that's what we need.
                    yield $class;
                }
            }
        }
    }
897616
protected function loadConfigurationFiles($path, $namespace)
	{
		foreach ($this->getConfigurationFiles($path) as $key => $file)
		{
			$configs = require $file;
			$this->setConfigsInNamespace($configs, $key, $namespace);
		}
	}
471041
protected function getMiddleware(ResourcePath $path)
    {
        $classMiddleware = $this->getClassMiddlewareForPath($path)->all();

        return array_merge($classMiddleware, array_get($this->middleware, $path->method, []));
    }
711971
protected function searchModulePath($namespace)
    {
        $targetPath = false;
        
        // Iterate trough the module directories
        foreach ($this->moduleDirectories as $directory => $excludePattern) {
            $recursiveDirectoryIterator = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
            $iterator = new \RecursiveIteratorIterator($recursiveDirectoryIterator);
            $regexIterator = new \RegexIterator($iterator, '/^.+\/Module\.json$/i');

            foreach ($regexIterator as $item) {
                // Ignore modules which are located inside a tests directory
                if ($excludePattern !== false && preg_match($excludePattern, $item->getPath())) {
                    continue;
                }
                
                $moduleNamespace = $this->getNamespaceFromModuleJson($item->getPath());
                
                if ($moduleNamespace === $namespace) {
                    $targetPath = $item->getPath();
                    break 2;
                }
            }
        }
        
        return $targetPath;
    }
1159757
private function getClassNameByPath($path)
	{
		foreach ($this->map as $key => $value) {
			if ($value === $path) {
				return $key;
			}
		}
		
		return null;
	}
416978
protected function getClassMiddlewareForPath(AbstractPath $path)
    {
        return Collection::make($this->classMiddleware)->filter(function ($m) {
            return $this->middlewareAppliesToMethod($this->method, $m);
        })
        ->map(function ($m) {
            return $m['name'];
        });
    }
517330
public static function GetControllerClassPath ($route, $namespace) {
		$class_path = "\\". implode("\\", [$namespace, 'app', 'controllers', $route['controller'], Strings::ToUpperCamelCase($route['controller']) . 'Controller']);
		if (!class_exists($class_path)) {
			$class_path = "\\". implode("\\", [__NAMESPACE__, 'app', 'controllers', 'UnkownController']);
		}
		return $class_path;
	}
225548
private static function _parseAdditions(array &$components, $namespace, $path)
    {
        if (!file_exists($path)) {
            return;
        }
        foreach (new \DirectoryIterator($path) as $object) {
            if ($object->isDot() || $object->isDir()) {
                continue;
            }
            $components[$namespace][lcfirst(substr($object->getFilename(), 0, -4))] = substr($object->getFilename(), -3) == 'php' ? 1 : $object->getPathname();
        }
    }
589218
protected function getTransformerProperties($class, $namespace, $storePath)
    {

        // check if class contains additional level
        if (strpos($class, '/') !== false) {
            $additionalLevel = substr($class, 0, strrpos($class, '/'));

            $class = basename($class);

            $namespace = rtrim(str_replace('/', '\\', $namespace."\\{$additionalLevel}"), '\\');

            $storePath = str_replace('//', '/', rtrim($storePath, '/')."/{$additionalLevel}");
        }

        return [
            $class,
            $namespace,
            $storePath,
        ];
    }
1203212
public function getAllCommands(string $namespace = ''): array
	{
		$this->initCommands();

		if ($namespace === '')
		{
			$commands = $this->commands;

			if (!$this->commandLoader)
			{
				return $commands;
			}

			foreach ($this->commandLoader->getNames() as $name)
			{
				if (!isset($commands[$name]))
				{
					$commands[$name] = $this->getCommand($name);
				}
			}

			return $commands;
		}

		$commands = [];

		foreach ($this->commands as $name => $command)
		{
			if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1))
			{
				$commands[$name] = $command;
			}
		}

		if ($this->commandLoader)
		{
			foreach ($this->commandLoader->getNames() as $name)
			{
				if (!isset($commands[$name]) && $namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1))
				{
					$commands[$name] = $this->getCommand($name);
				}
			}
		}

		return $commands;
	}
900272
static function getClass($namespace = '',$config = [],$new = false){
	
		if($namespace == ''){
			return self::$instance;
		}
		
		if($new === false && isset(self::$instance[$namespace])){
			return self::$instance[$namespace];
		}
		
		$ns = self::getName($namespace);
		
		self::$instance[$namespace] = new $ns->namespace($config);
		
		return self::$instance[$namespace] ;
	}
792361
protected function getClassNamesInNamespace($namespace)
    {
        $affectedViewHelperClassNames = [];

        $allViewHelperClassNames = $this->reflectionService->getAllSubClassNamesForClass(AbstractViewHelper::class);
        foreach ($allViewHelperClassNames as $viewHelperClassName) {
            if ($this->reflectionService->isClassAbstract($viewHelperClassName)) {
                continue;
            }
            if (strncmp($namespace, $viewHelperClassName, strlen($namespace)) === 0) {
                $affectedViewHelperClassNames[] = $viewHelperClassName;
            }
        }
        sort($affectedViewHelperClassNames);
        return $affectedViewHelperClassNames;
    }
229386
protected function findExtensions($namespace)
    {
        $this->initializeNamespaces();
        $files = [];
        $old = [];
        $namespaces = [$namespace, 'Staq\Core\Ground'];
        while (array_diff($namespaces, $old)) {
            $extensions = $this->formatExtensionsFromNamespaces($namespaces);
            foreach ($extensions as $extension) {
                $files[] = $extension . '/setting/Application.ini';
            }
            $ini = (new \Pixel418\Iniliq\IniParser)->parse(array_reverse($files));
            $old = $namespaces;
            $namespaces = array_reverse($ini->getAsArray('extension.list'));
            $namespaces = \UArray::reverseMergeUnique($old, $namespaces);
        }
        return $this->formatExtensionsFromNamespaces($namespaces);
    }
748796
public function beforeAfter($command, $path = '', $namespace = '')
    {
        if (! is_null($command)) {
            if (is_array($command)) {
                foreach ($command as $key => $value) {
                    $this->beforeAfter($value, $path, $namespace);
                }
            } elseif (is_string($command)) {
                $controller = $this->resolveClass($command, $path, $namespace);
                if (method_exists($controller, 'handle')) {
                    return call_user_func([$controller, 'handle']);
                }

                return $this->exception('handle() method is not found in <b>'.$command.'</b> class.');
            }
        }

        return;
    }