diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
new file mode 100644
index 0000000..c592f27
--- /dev/null
+++ b/.github/workflows/phpunit.yml
@@ -0,0 +1,17 @@
+on:
+ push:
+ branches:
+ - master
+
+name: phpunit
+
+jobs:
+ phpunit:
+ uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
+ with:
+ os: >-
+ ['ubuntu-latest']
+ php: >-
+ ['8.1', '8.2']
+ stability: >-
+ ['prefer-stable']
diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml
new file mode 100644
index 0000000..75c416b
--- /dev/null
+++ b/.github/workflows/psalm.yml
@@ -0,0 +1,15 @@
+on:
+ push:
+ branches:
+ - master
+
+name: static analysis
+
+jobs:
+ psalm:
+ uses: spiral/gh-actions/.github/workflows/psalm.yml@master
+ with:
+ os: >-
+ ['ubuntu-latest']
+ php: >-
+ ['8.1']
diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
deleted file mode 100644
index cf9486e..0000000
--- a/.github/workflows/run-tests.yml
+++ /dev/null
@@ -1,53 +0,0 @@
-name: run-tests
-
-on:
- push:
- branches: [ master ]
- pull_request:
- branches: [ master ]
-
-jobs:
- test:
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: true
- matrix:
- os: [ ubuntu-latest ]
- php: [ 8.0, 8.1 ]
- stability: [ prefer-lowest, prefer-stable ]
-
- name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
-
- steps:
- - name: Checkout code
- uses: actions/checkout@v3
-
- - name: Setup PHP
- uses: shivammathur/setup-php@v2
- with:
- php-version: ${{ matrix.php }}
- coverage: none
-
- - name: Validate Composer
- run: composer validate
-
- - name: Get Composer Cache Directory
- id: composer-cache
- run: echo "::set-output name=dir::$(composer config cache-files-dir)"
-
- - name: Restore Composer Cache
- uses: actions/cache@v3
- with:
- path: ${{ steps.composer-cache.outputs.dir }}
- key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer-${{ hashFiles('**/composer.json') }}
- restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer
-
- - name: Install Dependencies
- uses: nick-invision/retry@v2.8.1
- with:
- timeout_minutes: 5
- max_attempts: 5
- command: composer update --prefer-dist --no-interaction --no-progress
-
- - name: Execute tests
- run: vendor/bin/phpunit
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
deleted file mode 100644
index 217114a..0000000
--- a/.github/workflows/static-analysis.yml
+++ /dev/null
@@ -1,51 +0,0 @@
-name: run-tests
-
-on:
- push:
- branches: [ master ]
- pull_request:
- branches: [ master ]
-
-jobs:
- static-analysis:
- name: Psalm
- runs-on: ${{ matrix.os }}
-
- strategy:
- fail-fast: false
- matrix:
- php: [ 8.0 ]
- os: [ ubuntu-latest ]
-
- steps:
- - name: Checkout
- uses: actions/checkout@v3
-
- - name: Setup PHP ${{ matrix.php }}
- uses: shivammathur/setup-php@v2
- with:
- php-version: ${{ matrix.php }}
-
- - name: Validate Composer
- run: composer validate
-
- - name: Get Composer Cache Directory
- id: composer-cache
- run: echo "::set-output name=dir::$(composer config cache-files-dir)"
-
- - name: Restore Composer Cache
- uses: actions/cache@v3
- with:
- path: ${{ steps.composer-cache.outputs.dir }}
- key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
- restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer
-
- - name: Install Dependencies
- uses: nick-invision/retry@v2.8.1
- with:
- timeout_minutes: 5
- max_attempts: 5
- command: composer update --prefer-dist --no-interaction --no-progress
-
- - name: Static Analysis
- run: vendor/bin/psalm --no-cache
diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml
deleted file mode 100644
index b20f3b6..0000000
--- a/.github/workflows/update-changelog.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-name: "Update Changelog"
-
-on:
- release:
- types: [released]
-
-jobs:
- update:
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout code
- uses: actions/checkout@v3
- with:
- ref: main
-
- - name: Update Changelog
- uses: stefanzweifel/changelog-updater-action@v1
- with:
- latest-version: ${{ github.event.release.name }}
- release-notes: ${{ github.event.release.body }}
-
- - name: Commit updated CHANGELOG
- uses: stefanzweifel/git-auto-commit-action@v4
- with:
- branch: main
- commit_message: Update CHANGELOG
- file_pattern: CHANGELOG.md
diff --git a/README.md b/README.md
index 0e27c1f..e8702b6 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,10 @@
# Discoverer for Spiral Framework
-[![PHP](https://img.shields.io/packagist/php-v/spiral-packages/discoverer.svg?style=flat-square)](https://packagist.org/packages/spiral-packages/discoverer)
-[![Latest Version on Packagist](https://img.shields.io/packagist/v/spiral-packages/discoverer.svg?style=flat-square)](https://packagist.org/packages/spiral-packages/discoverer)
-[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/spiral-packages/discoverer/run-tests?label=tests)](https://github.com/spiral-packages/discoverer/actions?query=workflow%3Arun-tests+branch%3Amain)
-[![Total Downloads](https://img.shields.io/packagist/dt/spiral-packages/discoverer.svg?style=flat-square)](https://packagist.org/packages/spiral-packages/discoverer)
+[![PHP Version Require](https://poser.pugx.org/spiral-packages/discoverer/require/php)](https://packagist.org/packages/spiral-packages/discoverer)
+[![Latest Stable Version](https://poser.pugx.org/spiral-packages/discoverer/v/stable)](https://packagist.org/packages/spiral-packages/discoverer)
+[![phpunit](https://github.com/spiral-packages/discoverer/actions/workflows/phpunit.yml/badge.svg)](https://github.com/spiral-packages/discoverer/actions)
+[![psalm](https://github.com/spiral-packages/discoverer/actions/workflows/psalm.yml/badge.svg)](https://github.com/spiral-packages/discoverer/actions)
+[![Total Downloads](https://poser.pugx.org/spiral-packages/discoverer/downloads)](https://packagist.org/spiral-packages/discoverer/phpunit)
## Requirements
@@ -36,7 +37,7 @@ kernel.
use Spiral\Discoverer\WithDiscovering;
use Spiral\Framework\Kernel;
-class App extends Kernel
+class App extends Kernel
{
use WithDiscovering;
}
@@ -75,14 +76,16 @@ $app = App::create([
]);
$app->discover(
+ // Bootloaders sources
new \Spiral\Discoverer\Bootloader\BootloadersDiscoverer(
new \Spiral\Discoverer\Bootloader\ComposerRegistry(),
new \Spiral\Discoverer\Bootloader\ArrayRegistry(...),
- new \Spiral\Discoverer\Bootloader\ConfigRegistry()
+ new \Spiral\Discoverer\Bootloader\ConfigRegistry()
),
-
+
+ // Tokenizer directories
new \Spiral\Discoverer\Tokenizer\DirectoriesDiscoverer(
- new \Spiral\Discoverer\Tokenizer\ComposerRegistry(),
+ new \Spiral\Discoverer\Tokenizer\ComposerRegistry(),
)
);
@@ -147,7 +150,7 @@ Will register bootloaders from the passed array
new \Spiral\Discoverer\Bootloader\ArrayRegistry([
// Application specific logs
Bootloader\LoggingBootloader::class,
-
+
// ...
]),
```
@@ -196,12 +199,12 @@ final class JsonRegistry implements BootloaderRegistryInterface
{
private array $bootloaders = [];
private array $ignorableBootloaders = [];
-
+
public function __construct(
private string $jsonPath
) {
}
-
+
public function init(Container $container): void
{
// json structure
@@ -212,10 +215,10 @@ final class JsonRegistry implements BootloaderRegistryInterface
// ],
// "ignored_bootloaders": []
//}
-
+
$files = $container->get(FilesInterface::class);
$data = \json_decode($files->read($this->jsonPath), true);
-
+
$this->bootloaders = $data['bootloaders'] ?? [];
$this->ignorableBootloaders = $data['ignored_bootloaders'] ?? [];
}
@@ -277,7 +280,7 @@ Will register directories from application `composer.json` and from other instal
```
```php
-new \Spiral\Discoverer\Tokenizer\ComposerRegistry(),
+new \Spiral\Discoverer\Tokenizer\ComposerRegistry(),
```
#### Custom Directory registry
@@ -293,12 +296,12 @@ use Spiral\Files\FilesInterface;
final class JsonRegistry implements DirectoryRegistryInterface
{
private array $directories = [];
-
+
public function __construct(
private string $jsonPath
) {
}
-
+
public function init(Container $container): void
{
// json structure
@@ -308,12 +311,12 @@ final class JsonRegistry implements DirectoryRegistryInterface
// "src/Entities"
// ]
// }
-
+
$root = $container->get(\Spiral\Boot\DirectoriesInterface::class)->get('root');
-
+
$files = $container->get(FilesInterface::class);
$data = \json_decode($files->read($this->jsonPath), true);
-
+
$this->directories = \array_map(function (string $dir) use($root) {
return $root . $dir;
}, $data['directories'] ?? []);
diff --git a/composer.json b/composer.json
index 5f7dc20..31755e2 100644
--- a/composer.json
+++ b/composer.json
@@ -1,56 +1,58 @@
{
- "name": "spiral-packages/discoverer",
- "description": "Discoverer for Spiral Framework",
- "keywords": [
- "spiral-packages",
- "spiral",
- "discoverer"
- ],
- "homepage": "https://github.com/spiral-packages/bootloaders-discover",
- "license": "MIT",
- "authors": [
- {
- "name": "butschster",
- "email": "butschster@gmail.com",
- "role": "Developer"
- }
- ],
- "require": {
- "php": "^8.1",
- "spiral/framework": "^3.0"
- },
- "require-dev": {
- "spiral/testing": "^2.0",
- "vimeo/psalm": "^4.9"
- },
- "autoload": {
- "psr-4": {
- "Spiral\\Discoverer\\": "src"
- }
- },
- "autoload-dev": {
- "psr-4": {
- "Spiral\\Discoverer\\Tests\\App\\": "tests/app",
- "Spiral\\Discoverer\\Tests\\": "tests/src"
- }
- },
- "extra": {
- "spiral": {
- "bootloaders": [
- "Spiral\\Discoverer\\DiscovererBootloader"
- ]
- }
- },
- "scripts": {
- "test": "vendor/bin/phpunit",
- "psalm": "vendor/bin/psalm --config=psalm.xml ./src"
- },
- "config": {
- "sort-packages": true,
- "allow-plugins": {
- "spiral/composer-publish-plugin": true
- }
- },
- "minimum-stability": "dev",
- "prefer-stable": true
+ "name": "spiral-packages/discoverer",
+ "description": "Discoverer for Spiral Framework",
+ "keywords": [
+ "spiral-packages",
+ "spiral",
+ "discoverer"
+ ],
+ "homepage": "https://github.com/spiral-packages/bootloaders-discover",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "butschster",
+ "email": "butschster@gmail.com",
+ "role": "Developer"
+ }
+ ],
+ "require": {
+ "php": "^8.1",
+ "spiral/boot": "^3.0",
+ "spiral/core": "^3.0"
+ },
+ "require-dev": {
+ "spiral/framework": "^3.0",
+ "spiral/testing": "^2.0",
+ "vimeo/psalm": "^4.9"
+ },
+ "autoload": {
+ "psr-4": {
+ "Spiral\\Discoverer\\": "src"
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Spiral\\Discoverer\\Tests\\App\\": "tests/app",
+ "Spiral\\Discoverer\\Tests\\": "tests/src"
+ }
+ },
+ "extra": {
+ "spiral": {
+ "bootloaders": [
+ "Spiral\\Discoverer\\DiscovererBootloader"
+ ]
+ }
+ },
+ "scripts": {
+ "test": "vendor/bin/phpunit",
+ "psalm": "vendor/bin/psalm --config=psalm.xml ./src"
+ },
+ "config": {
+ "sort-packages": true,
+ "allow-plugins": {
+ "spiral/composer-publish-plugin": true
+ }
+ },
+ "minimum-stability": "dev",
+ "prefer-stable": true
}
diff --git a/psalm.xml b/psalm.xml
index 3cae6e6..86611f6 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,21 +1,11 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Bootloader/ArrayRegistry.php b/src/Bootloader/ArrayRegistry.php
index ddfc42d..0878a4b 100644
--- a/src/Bootloader/ArrayRegistry.php
+++ b/src/Bootloader/ArrayRegistry.php
@@ -4,22 +4,25 @@
namespace Spiral\Discoverer\Bootloader;
-use Spiral\Boot\Bootloader\BootloaderInterface;
-use Spiral\Core\Container;
+use Psr\Container\ContainerInterface;
+use Spiral\Boot\BootloadManagerInterface;
+/**
+ * @psalm-import-type TClass from BootloadManagerInterface
+ */
final class ArrayRegistry implements BootloaderRegistryInterface
{
/**
- * @param array, array> $bootloaders
- * @param array> $ignorableBootloaders
+ * @param array> $bootloaders
+ * @param TClass[] $ignorableBootloaders
*/
public function __construct(
- private array $bootloaders,
- private array $ignorableBootloaders = []
+ private readonly array $bootloaders,
+ private readonly array $ignorableBootloaders = []
) {
}
- public function init(Container $container): void
+ public function init(ContainerInterface $container): void
{
}
diff --git a/src/Bootloader/BootloaderRegistryInterface.php b/src/Bootloader/BootloaderRegistryInterface.php
index a217129..1e6df14 100644
--- a/src/Bootloader/BootloaderRegistryInterface.php
+++ b/src/Bootloader/BootloaderRegistryInterface.php
@@ -4,18 +4,21 @@
namespace Spiral\Discoverer\Bootloader;
-use Spiral\Boot\Bootloader\BootloaderInterface;
+use Spiral\Boot\BootloadManagerInterface;
use Spiral\Discoverer\RegistryInterface;
+/**
+ * @psalm-import-type TClass from BootloadManagerInterface
+ */
interface BootloaderRegistryInterface extends RegistryInterface
{
/**
- * @return array>|array, array>
+ * @return TClass[]|array>
*/
public function getBootloaders(): array;
/**
- * @return array>
+ * @return TClass[]
*/
public function getIgnoredBootloaders(): array;
}
diff --git a/src/Bootloader/BootloadersDiscoverer.php b/src/Bootloader/BootloadersDiscoverer.php
index b7db3ec..69654bb 100644
--- a/src/Bootloader/BootloadersDiscoverer.php
+++ b/src/Bootloader/BootloadersDiscoverer.php
@@ -4,15 +4,17 @@
namespace Spiral\Discoverer\Bootloader;
+use Psr\Container\ContainerInterface;
use Spiral\Boot\Bootloader\BootloaderInterface;
-use Spiral\Core\Container;
+use Spiral\Boot\BootloadManagerInterface;
use Spiral\Discoverer\DiscovererRegistryInterface;
+/**
+ * @psalm-import-type TClass from BootloadManagerInterface
+ */
class BootloadersDiscoverer implements DiscovererRegistryInterface
{
- /**
- * @var BootloaderRegistryInterface[]
- */
+ /** @var BootloaderRegistryInterface[] */
private array $registries;
public function __construct(BootloaderRegistryInterface ...$registry)
@@ -25,6 +27,9 @@ public static function getName(): string
return 'bootloaders';
}
+ /**
+ * @return array, array>
+ */
public function discover(): array
{
$bootloaders = [];
@@ -55,11 +60,10 @@ public function discover(): array
}
/**
- * @return array>
+ * @return TClass[]
*/
private function getIgnoredBootloaders(): array
{
- /** @var array $ignorableBootloaders */
$ignorableBootloaders = [];
foreach ($this->registries as $registry) {
if (! $registry instanceof BootloaderRegistryInterface) {
@@ -75,7 +79,7 @@ private function getIgnoredBootloaders(): array
return \array_unique($ignorableBootloaders);
}
- public function init(Container $container): void
+ public function init(ContainerInterface $container): void
{
foreach ($this->registries as $registry) {
$registry->init($container);
diff --git a/src/Bootloader/ConfigRegistry.php b/src/Bootloader/ConfigRegistry.php
index ab1569a..5c79546 100644
--- a/src/Bootloader/ConfigRegistry.php
+++ b/src/Bootloader/ConfigRegistry.php
@@ -4,25 +4,30 @@
namespace Spiral\Discoverer\Bootloader;
-use Spiral\Core\Container;
+use Psr\Container\ContainerInterface;
use Spiral\Discoverer\Config\DiscovererConfig;
final class ConfigRegistry implements BootloaderRegistryInterface
{
- private DiscovererConfig $config;
+ private ?DiscovererConfig $config = null;
- public function init(Container $container): void
+ /**
+ * @throws \Psr\Container\ContainerExceptionInterface
+ * @throws \Psr\Container\NotFoundExceptionInterface
+ */
+ public function init(ContainerInterface $container): void
{
$this->config = $container->get(DiscovererConfig::class);
+ \assert($this->config instanceof DiscovererConfig);
}
public function getBootloaders(): array
{
- return $this->config->getBootloaders();
+ return $this->config !== null ? $this->config->getBootloaders() : [];
}
public function getIgnoredBootloaders(): array
{
- return $this->config->getIgnoredBootloaders();
+ return $this->config !== null ? $this->config->getIgnoredBootloaders() : [];
}
}
diff --git a/src/Composer.php b/src/Composer.php
index 00196d9..405b81c 100644
--- a/src/Composer.php
+++ b/src/Composer.php
@@ -11,7 +11,7 @@ final class Composer
private string $vendorDir;
private array $packages = [];
private array $packageDirs = [];
- private array $composerExtra;
+ private array $composerExtra = [];
public function __construct(
FilesInterface $files,
@@ -46,7 +46,7 @@ public function __construct(
}
}
- public function getComposerExtra(string $key, $default = null)
+ public function getComposerExtra(string $key, mixed $default = null): mixed
{
return $this->composerExtra[$key] ?? $default;
}
diff --git a/src/Config/DiscovererConfig.php b/src/Config/DiscovererConfig.php
index eaf59ea..7db41dd 100644
--- a/src/Config/DiscovererConfig.php
+++ b/src/Config/DiscovererConfig.php
@@ -5,8 +5,12 @@
namespace Spiral\Discoverer\Config;
use Spiral\Boot\Bootloader\BootloaderInterface;
+use Spiral\Boot\BootloadManagerInterface;
use Spiral\Core\InjectableConfig;
+/**
+ * @psalm-import-type TClass from BootloadManagerInterface
+ */
final class DiscovererConfig extends InjectableConfig
{
public const CONFIG = 'discoverer';
@@ -16,18 +20,18 @@ final class DiscovererConfig extends InjectableConfig
];
/**
- * @return array>|array, array>
+ * @return TClass[]|array>
*/
public function getBootloaders(): array
{
- return (array)($this->config['bootloaders'] ?? []);
+ return (array)$this->config['bootloaders'];
}
/**
- * @return array>
+ * @return TClass[]
*/
public function getIgnoredBootloaders(): array
{
- return (array)($this->config['ignoredBootloaders'] ?? []);
+ return (array)$this->config['ignoredBootloaders'];
}
}
diff --git a/src/Discoverer.php b/src/Discoverer.php
index 6a4242f..47442df 100644
--- a/src/Discoverer.php
+++ b/src/Discoverer.php
@@ -2,16 +2,16 @@
namespace Spiral\Discoverer;
-use Spiral\Core\Container;
+use Psr\Container\ContainerInterface;
use Spiral\Discoverer\Exception\DiscovererRegistryException;
final class Discoverer implements DiscovererInterface
{
/** @var DiscovererRegistryInterface[] */
- private array $registries;
+ private array $registries = [];
public function __construct(
- Container $container,
+ ContainerInterface $container,
DiscovererRegistryInterface ...$registries
) {
foreach ($registries as $registry) {
diff --git a/src/DiscovererBootloader.php b/src/DiscovererBootloader.php
index c21e2c5..d1c92ed 100644
--- a/src/DiscovererBootloader.php
+++ b/src/DiscovererBootloader.php
@@ -4,8 +4,8 @@
namespace Spiral\Discoverer;
+use Psr\Container\ContainerInterface;
use Spiral\Boot\Bootloader\Bootloader;
-use Spiral\Core\Container;
use Spiral\Discoverer\Tokenizer\DirectoriesDiscoverer;
use Spiral\Tokenizer\Bootloader\TokenizerBootloader;
@@ -15,17 +15,26 @@ final class DiscovererBootloader extends Bootloader
TokenizerBootloader::class,
];
- public function boot(
- Container $container,
+ /**
+ * @throws Exception\DiscovererRegistryException
+ * @throws \Psr\Container\ContainerExceptionInterface
+ * @throws \Psr\Container\NotFoundExceptionInterface
+ */
+ public function init(
+ ContainerInterface $container,
TokenizerBootloader $tokenizerBootloader
- ) {
- if ($container->has(DiscovererInterface::class)) {
- $discoverer = $container->get(DiscovererInterface::class);
- if ($discoverer->has(DirectoriesDiscoverer::getName())) {
- foreach ($discoverer->discover(DirectoriesDiscoverer::getName()) as $directory) {
- $tokenizerBootloader->addDirectory($directory);
- }
- };
+ ): void {
+ if (!$container->has(DiscovererInterface::class)) {
+ return;
}
+
+ $discoverer = $container->get(DiscovererInterface::class);
+ \assert($discoverer instanceof DiscovererInterface);
+
+ if ($discoverer->has(DirectoriesDiscoverer::getName())) {
+ foreach ($discoverer->discover(DirectoriesDiscoverer::getName()) as $directory) {
+ $tokenizerBootloader->addDirectory($directory);
+ }
+ };
}
}
diff --git a/src/DiscovererRegistryInterface.php b/src/DiscovererRegistryInterface.php
index d1b6555..bba7050 100644
--- a/src/DiscovererRegistryInterface.php
+++ b/src/DiscovererRegistryInterface.php
@@ -7,5 +7,6 @@
interface DiscovererRegistryInterface extends RegistryInterface
{
public static function getName(): string;
+
public function discover(): array;
}
diff --git a/src/RegistryInterface.php b/src/RegistryInterface.php
index fa92ea3..1862b05 100644
--- a/src/RegistryInterface.php
+++ b/src/RegistryInterface.php
@@ -4,9 +4,9 @@
namespace Spiral\Discoverer;
-use Spiral\Core\Container;
+use Psr\Container\ContainerInterface;
interface RegistryInterface
{
- public function init(Container $container): void;
+ public function init(ContainerInterface $container): void;
}
diff --git a/src/Tokenizer/DirectoriesDiscoverer.php b/src/Tokenizer/DirectoriesDiscoverer.php
index 1314d7b..adb487d 100644
--- a/src/Tokenizer/DirectoriesDiscoverer.php
+++ b/src/Tokenizer/DirectoriesDiscoverer.php
@@ -4,14 +4,12 @@
namespace Spiral\Discoverer\Tokenizer;
-use Spiral\Core\Container;
+use Psr\Container\ContainerInterface;
use Spiral\Discoverer\DiscovererRegistryInterface;
final class DirectoriesDiscoverer implements DiscovererRegistryInterface
{
- /**
- * @var DirectoryRegistryInterface[]
- */
+ /** @var DirectoryRegistryInterface[] */
private array $registries;
public function __construct(DirectoryRegistryInterface ...$registry)
@@ -24,6 +22,9 @@ public static function getName(): string
return 'directories';
}
+ /**
+ * @return non-empty-string[]
+ */
public function discover(): array
{
$dirs = [];
@@ -35,7 +36,7 @@ public function discover(): array
return \array_values(\array_unique(\array_filter($dirs)));
}
- public function init(Container $container): void
+ public function init(ContainerInterface $container): void
{
foreach ($this->registries as $registry) {
$registry->init($container);
diff --git a/src/Tokenizer/DirectoryRegistryInterface.php b/src/Tokenizer/DirectoryRegistryInterface.php
index a55a31f..eb78bf8 100644
--- a/src/Tokenizer/DirectoryRegistryInterface.php
+++ b/src/Tokenizer/DirectoryRegistryInterface.php
@@ -8,5 +8,8 @@
interface DirectoryRegistryInterface extends RegistryInterface
{
+ /**
+ * @return non-empty-string[]
+ */
public function getDirectories(): array;
}
diff --git a/src/Traits/WithComposerPackages.php b/src/Traits/WithComposerPackages.php
index 0b3710b..f8e0bde 100644
--- a/src/Traits/WithComposerPackages.php
+++ b/src/Traits/WithComposerPackages.php
@@ -4,8 +4,8 @@
namespace Spiral\Discoverer\Traits;
+use Psr\Container\ContainerInterface;
use Spiral\Boot\DirectoriesInterface;
-use Spiral\Core\Container;
use Spiral\Discoverer\Composer;
use Spiral\Files\FilesInterface;
@@ -13,14 +13,17 @@ trait WithComposerPackages
{
private Composer $composer;
- public function init(Container $container): void
+ /**
+ * @throws \Psr\Container\ContainerExceptionInterface
+ * @throws \Psr\Container\NotFoundExceptionInterface
+ */
+ public function init(ContainerInterface $container): void
{
$dirs = $container->get(DirectoriesInterface::class);
+ $files = $container->get(FilesInterface::class);
+ \assert($files instanceof FilesInterface);
- $this->composer = new Composer(
- $container->get(FilesInterface::class),
- $dirs->get('root')
- );
+ $this->composer = new Composer($files, $dirs->get('root'));
}
public function getComposer(): Composer
diff --git a/src/WithDiscovering.php b/src/WithDiscovering.php
index e3d59a9..a4f05a5 100644
--- a/src/WithDiscovering.php
+++ b/src/WithDiscovering.php
@@ -22,10 +22,10 @@ public function discover(DiscovererRegistryInterface ...$registry): void
protected function defineBootloaders(): array
{
- if (! $this->discoverer) {
+ if ($this->discoverer === null) {
return parent::defineBootloaders();
}
- return $this->discoverer->discover(BootloadersDiscoverer::getName());
+ return parent::defineBootloaders() + $this->discoverer->discover(BootloadersDiscoverer::getName());
}
}