Skip to content

Commit

Permalink
Adds support for Spiral Framework 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed May 30, 2022
1 parent 7cffc15 commit 714b31a
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions src/Bootloader/ArrayRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

namespace Spiral\Discoverer\Bootloader;

use Spiral\Boot\Bootloader\BootloaderInterface;
use Spiral\Core\Container;

final class ArrayRegistry implements BootloaderRegistryInterface
{
/**
* @param array<class-string, array<non-empty-string, mixed>> $bootloaders
* @param array<class-string> $ignorableBootloaders
* @param array<class-string<BootloaderInterface>, array<non-empty-string, mixed>> $bootloaders
* @param array<class-string<BootloaderInterface>> $ignorableBootloaders
*/
public function __construct(
private array $bootloaders,
Expand Down
5 changes: 3 additions & 2 deletions src/Bootloader/BootloaderRegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace Spiral\Discoverer\Bootloader;

use Spiral\Boot\Bootloader\BootloaderInterface;
use Spiral\Discoverer\RegistryInterface;

interface BootloaderRegistryInterface extends RegistryInterface
{
/**
* @return array<class-string>|array<class-string, array<non-empty-string, mixed>>
* @return array<class-string<BootloaderInterface>>|array<class-string<BootloaderInterface>, array<non-empty-string, mixed>>
*/
public function getBootloaders(): array;

/**
* @return array<class-string>
* @return array<class-string<BootloaderInterface>>
*/
public function getIgnoredBootloaders(): array;
}
3 changes: 2 additions & 1 deletion src/Bootloader/BootloadersDiscoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Spiral\Discoverer\Bootloader;

use Spiral\Boot\Bootloader\BootloaderInterface;
use Spiral\Core\Container;
use Spiral\Discoverer\DiscovererRegistryInterface;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function discover(): array
}

/**
* @return array<class-string>
* @return array<class-string<BootloaderInterface>>
*/
private function getIgnoredBootloaders(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bootloader/ComposerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? [])
);
Expand Down
13 changes: 8 additions & 5 deletions src/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
);

Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/Config/DiscovererConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<class-string<BootloaderInterface>>|array<class-string<BootloaderInterface>, array<non-empty-string, mixed>>
*/
public function getBootloaders(): array
{
return (array)($this->config['bootloaders'] ?? []);
}

/**
* @return array<class-string<BootloaderInterface>>
*/
public function getIgnoredBootloaders(): array
{
return (array)($this->config['ignoredBootloaders'] ?? []);
Expand Down
2 changes: 1 addition & 1 deletion src/Discoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Tokenizer/ComposerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '\/');
}
}

Expand Down

0 comments on commit 714b31a

Please sign in to comment.