for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Quantum PHP Framework
*
* An open source software development framework for PHP
* @package Quantum
* @author Arman Ag. <[email protected]>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.9
*/
namespace Quantum\Console;
use ReflectionException;
use ReflectionClass;
* Class CommandDiscovery
* @package Quantum\Console
class CommandDiscovery
{
* @param string $directory
* @param string $namespace
* @return array
* @throws ReflectionException
public static function discover(string $directory, string $namespace): array
$commands = [];
foreach (get_directory_classes($directory) as $className) {
$commandClass = $namespace . $className;
if (!class_exists($commandClass)) {
continue;
}
$commandReflection = new ReflectionClass($commandClass);
if (!$commandReflection->isInstantiable() || !$commandReflection->isSubclassOf(QtCommand::class)) {
$instance = $commandReflection->newInstance();
$commands[] = [
'class' => $commandClass,
'name' => $instance->getName(),
'description' => $instance->getDescription(),
'help' => $instance->getHelp(),
];
return $commands;