diff --git a/composer.json b/composer.json index 1381bc0..f0be500 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,9 @@ "minimum-stability": "stable", "require": { "php": "^7.4 || ^8.0", + "symfony/console": "^5.4 || ^6.0", "jrosset/betterphptoken": "^1.0", - "symfony/console": "^5.4 || ^6.0" + "jrosset/collections": "^2.3" }, "autoload": { "psr-4": { diff --git a/src/CliProgram/TAutoDiscoveryApplication.php b/src/CliProgram/TAutoDiscoveryApplication.php index a91ca1d..4635e90 100644 --- a/src/CliProgram/TAutoDiscoveryApplication.php +++ b/src/CliProgram/TAutoDiscoveryApplication.php @@ -2,48 +2,28 @@ namespace jrosset\CliProgram; +use jrosset\Collections\Collection; +use jrosset\Collections\ICollection; + /** * An application with command auto discovery */ trait TAutoDiscoveryApplication { /** - * @var IAutoDiscoverySpot[] The list of discovery spots + * @var ICollection The list of discovery spots */ - private array $autoDiscoverySpots = []; + private ICollection $autoDiscoverySpots; /** * The list of discovery spots * - * @return IAutoDiscoverySpot[] The list of discovery spots + * @return ICollection The list of discovery spots */ - public function getAutoDiscoverySpots (): array { - return $this->autoDiscoverySpots; - } - /** - * Set the list of discovery spots - * - * @param IAutoDiscoverySpot[] $autoDiscoverySpots The list of discovery spots - * - * @return $this - */ - public function setAutoDiscoverySpots (array $autoDiscoverySpots): self { - $this->autoDiscoverySpots = $autoDiscoverySpots; - return $this; - } - /** - * Add a discovery spot - * - * @param IAutoDiscoverySpot $spot The discovery spot - * @param IAutoDiscoverySpot ...$extraSpots Extra discovery spots to add - * - * @return $this - */ - public function addAutoDiscoverySpots (IAutoDiscoverySpot $spot, IAutoDiscoverySpot ...$extraSpots): self { - $this->autoDiscoverySpots[] = $spot; - foreach ($extraSpots as $extraSpot) { - $this->autoDiscoverySpots[] = $extraSpot; + public function getAutoDiscoverySpots (): ICollection { + if (!isset($this->autoDiscoverySpots)) { + $this->autoDiscoverySpots = new Collection(); } - return $this; + return $this->autoDiscoverySpots; } /** diff --git a/src/CliProgram/TAutoPrefixManagement.php b/src/CliProgram/TAutoPrefixManagement.php index f264941..5a0e487 100644 --- a/src/CliProgram/TAutoPrefixManagement.php +++ b/src/CliProgram/TAutoPrefixManagement.php @@ -2,6 +2,8 @@ namespace jrosset\CliProgram; +use jrosset\Collections\Collection; +use jrosset\Collections\ICollection; use Symfony\Component\Console\Command\Command; /** @@ -9,43 +11,20 @@ use Symfony\Component\Console\Command\Command; */ trait TAutoPrefixManagement { /** - * @var IAutoPrefixManager[] The lists of manager for commands auto prefix + * @var ICollection The lists of manager for commands auto prefix */ - private array $autoPrefixManagers; + private ICollection $autoPrefixManagers; /** * The lists of manager for commands auto prefix * - * @return IAutoPrefixManager[] The lists of manager for commands auto prefix + * @return ICollection The lists of manager for commands auto prefix */ - public function getAutoPrefixManagers (): array { - return $this->autoPrefixManagers; - } - /** - * Set The lists of manager for commands auto prefix - * - * @param IAutoPrefixManager[] $autoPrefixManagers The lists of manager for commands auto prefix - * - * @return $this - */ - public function setAutoPrefixManagers (array $autoPrefixManagers): self { - $this->autoPrefixManagers = $autoPrefixManagers; - return $this; - } - /** - * Add a manager for commands auto prefix - * - * @param IAutoPrefixManager $manager The manager - * @param IAutoPrefixManager ...$extraManagers Extra managers to add - * - * @return $this - */ - public function addAutoPrefixManagers (IAutoPrefixManager $manager, IAutoPrefixManager ...$extraManagers): self { - $this->autoPrefixManagers[] = $manager; - foreach ($extraManagers as $extraNamespace) { - $this->autoPrefixManagers[] = $extraNamespace; + public function getAutoPrefixManagers (): ICollection { + if (!isset($this->autoPrefixManagers)) { + $this->autoPrefixManagers = new Collection(); } - return $this; + return $this->autoPrefixManagers; } /** diff --git a/tests/Application.php b/tests/Application.php index 88d0e4c..8b32fa9 100644 --- a/tests/Application.php +++ b/tests/Application.php @@ -12,10 +12,10 @@ class Application extends \Symfony\Component\Console\Application { public function __construct (string $name = 'UNKNOWN', string $version = 'UNKNOWN') { parent::__construct($name, $version); - $this->addAutoDiscoverySpots( - (new AutoDiscoveryDirectory(__DIR__ . '/Commands')) - ->addAutoPrefixManagers(new AutoPrefixNamespaceManager('\\jrosset\\Tests\\Commands', 'test')) - ); + $spot = new AutoDiscoveryDirectory(__DIR__ . '/Commands'); + $spot->getAutoPrefixManagers()->prepend(new AutoPrefixNamespaceManager('\\jrosset\\Tests\\Commands', 'test')); + + $this->getAutoDiscoverySpots()->prepend($spot); $this->addAutoDiscoveredCommands(); } } \ No newline at end of file