Use ICollections instead of arrays

2.x 1.1.1
Julien Rosset 2 years ago
parent d4353cb500
commit 1f5216a340

@ -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": {

@ -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<IAutoDiscoverySpot> 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<IAutoDiscoverySpot> 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;
}
/**

@ -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<IAutoPrefixManager> 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<IAutoPrefixManager> 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;
}
/**

@ -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();
}
}
Loading…
Cancel
Save