From 714b31aa0c0d48cd4653f869c7b3a823d93a8d60 Mon Sep 17 00:00:00 2001 From: butschster Date: Mon, 30 May 2022 16:40:51 +0400 Subject: [PATCH] Adds support for Spiral Framework 3.0 --- composer.json | 8 +++----- src/Bootloader/ArrayRegistry.php | 5 +++-- src/Bootloader/BootloaderRegistryInterface.php | 5 +++-- src/Bootloader/BootloadersDiscoverer.php | 3 ++- src/Bootloader/ComposerRegistry.php | 2 +- src/Composer.php | 13 ++++++++----- src/Config/DiscovererConfig.php | 9 ++++++++- src/Discoverer.php | 2 +- src/Tokenizer/ComposerRegistry.php | 6 +++--- 9 files changed, 32 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 60f2e9f..5f7dc20 100644 --- a/composer.json +++ b/composer.json @@ -16,13 +16,11 @@ } ], "require": { - "php": "^8.0", - "spiral/framework": "^2.9" + "php": "^8.1", + "spiral/framework": "^3.0" }, "require-dev": { - "mockery/mockery": "^1.5", - "phpunit/phpunit": "^9.5", - "spiral/testing": "^1.0", + "spiral/testing": "^2.0", "vimeo/psalm": "^4.9" }, "autoload": { diff --git a/src/Bootloader/ArrayRegistry.php b/src/Bootloader/ArrayRegistry.php index bc136a2..ddfc42d 100644 --- a/src/Bootloader/ArrayRegistry.php +++ b/src/Bootloader/ArrayRegistry.php @@ -4,13 +4,14 @@ namespace Spiral\Discoverer\Bootloader; +use Spiral\Boot\Bootloader\BootloaderInterface; use Spiral\Core\Container; final class ArrayRegistry implements BootloaderRegistryInterface { /** - * @param array> $bootloaders - * @param array $ignorableBootloaders + * @param array, array> $bootloaders + * @param array> $ignorableBootloaders */ public function __construct( private array $bootloaders, diff --git a/src/Bootloader/BootloaderRegistryInterface.php b/src/Bootloader/BootloaderRegistryInterface.php index 118b3f3..a217129 100644 --- a/src/Bootloader/BootloaderRegistryInterface.php +++ b/src/Bootloader/BootloaderRegistryInterface.php @@ -4,17 +4,18 @@ namespace Spiral\Discoverer\Bootloader; +use Spiral\Boot\Bootloader\BootloaderInterface; use Spiral\Discoverer\RegistryInterface; interface BootloaderRegistryInterface extends RegistryInterface { /** - * @return array|array> + * @return array>|array, array> */ public function getBootloaders(): array; /** - * @return array + * @return array> */ public function getIgnoredBootloaders(): array; } diff --git a/src/Bootloader/BootloadersDiscoverer.php b/src/Bootloader/BootloadersDiscoverer.php index 3b99663..b7db3ec 100644 --- a/src/Bootloader/BootloadersDiscoverer.php +++ b/src/Bootloader/BootloadersDiscoverer.php @@ -4,6 +4,7 @@ namespace Spiral\Discoverer\Bootloader; +use Spiral\Boot\Bootloader\BootloaderInterface; use Spiral\Core\Container; use Spiral\Discoverer\DiscovererRegistryInterface; @@ -54,7 +55,7 @@ public function discover(): array } /** - * @return array + * @return array> */ private function getIgnoredBootloaders(): array { diff --git a/src/Bootloader/ComposerRegistry.php b/src/Bootloader/ComposerRegistry.php index 5e94865..4abb3f3 100644 --- a/src/Bootloader/ComposerRegistry.php +++ b/src/Bootloader/ComposerRegistry.php @@ -29,7 +29,7 @@ public function getIgnoredBootloaders(): array $ignore = $this->getComposer()->getComposerExtra('dont-discover', []); foreach ($this->getComposer()->getPackages() as $extra) { - $ignore = array_merge( + $ignore = \array_merge( $ignore, (array)($extra['dont-discover'] ?? []) ); diff --git a/src/Composer.php b/src/Composer.php index f6e26d5..00196d9 100644 --- a/src/Composer.php +++ b/src/Composer.php @@ -13,9 +13,12 @@ final class Composer private array $packageDirs = []; private array $composerExtra; - public function __construct(FilesInterface $files, private string $rootDir, string $extraKey = 'spiral') - { - $this->vendorDir = rtrim($rootDir, '\/').'/vendor'; + public function __construct( + FilesInterface $files, + private readonly string $rootDir, + string $extraKey = 'spiral' + ) { + $this->vendorDir = \rtrim($rootDir, '\/').'/vendor'; if ($files->exists($path = $this->vendorDir.'/composer/installed.json')) { $installed = \json_decode($files->read($path), true); @@ -35,7 +38,7 @@ public function __construct(FilesInterface $files, private string $rootDir, stri if ($files->isFile($composerPath = $this->rootDir.'/composer.json')) { $data = \json_decode( - file_get_contents($composerPath), + \file_get_contents($composerPath), true ); @@ -69,7 +72,7 @@ public function getPackageExtra(string $package, array $default = null): ?array private function formatPackageName(string $name): string { - return str_replace($this->vendorDir.'/', '', $name); + return \str_replace($this->vendorDir.'/', '', $name); } public function getPackages(): array diff --git a/src/Config/DiscovererConfig.php b/src/Config/DiscovererConfig.php index da92703..eaf59ea 100644 --- a/src/Config/DiscovererConfig.php +++ b/src/Config/DiscovererConfig.php @@ -4,21 +4,28 @@ namespace Spiral\Discoverer\Config; +use Spiral\Boot\Bootloader\BootloaderInterface; use Spiral\Core\InjectableConfig; final class DiscovererConfig extends InjectableConfig { public const CONFIG = 'discoverer'; - protected $config = [ + protected array $config = [ 'bootloaders' => [], 'ignoredBootloaders' => [], ]; + /** + * @return array>|array, array> + */ public function getBootloaders(): array { return (array)($this->config['bootloaders'] ?? []); } + /** + * @return array> + */ public function getIgnoredBootloaders(): array { return (array)($this->config['ignoredBootloaders'] ?? []); diff --git a/src/Discoverer.php b/src/Discoverer.php index d84ebfe..6a4242f 100644 --- a/src/Discoverer.php +++ b/src/Discoverer.php @@ -11,7 +11,7 @@ final class Discoverer implements DiscovererInterface private array $registries; public function __construct( - private Container $container, + Container $container, DiscovererRegistryInterface ...$registries ) { foreach ($registries as $registry) { diff --git a/src/Tokenizer/ComposerRegistry.php b/src/Tokenizer/ComposerRegistry.php index 4fc88bf..131bbe6 100644 --- a/src/Tokenizer/ComposerRegistry.php +++ b/src/Tokenizer/ComposerRegistry.php @@ -18,20 +18,20 @@ public function getDirectories(): array $dirs = \array_merge( $dirs, \array_map(function (string $dir) use ($package, $extra) { - return $this->getComposer()->getPackagePath($package).'/'.ltrim($dir, '\/'); + return $this->getComposer()->getPackagePath($package).'/'.\ltrim($dir, '\/'); }, $extra['directories'] ?? []) ); } foreach ($this->getComposer()->getComposerExtra('directories', []) as $package => $packageDirs) { if (\is_int($package) || $package === 'self') { - $packagePath = rtrim($this->getComposer()->getRootDir(), '\/'); + $packagePath = \rtrim($this->getComposer()->getRootDir(), '\/'); } else if (! $packagePath = $this->getComposer()->getPackagePath($package)) { continue; } foreach ((array)$packageDirs as $dir) { - $dirs[] = $packagePath.'/'.ltrim($dir, '\/'); + $dirs[] = $packagePath.'/'.\ltrim($dir, '\/'); } }