Skip to content

Commit

Permalink
refactor(discovery): extract into a standalone module (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulfheart authored Jan 9, 2025
1 parent a4ab813 commit 58aadc9
Show file tree
Hide file tree
Showing 50 changed files with 135 additions and 74 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"tempest/core": "self.version",
"tempest/database": "self.version",
"tempest/debug": "self.version",
"tempest/discovery": "self.version",
"tempest/event-bus": "self.version",
"tempest/filesystem": "self.version",
"tempest/generation": "self.version",
Expand Down Expand Up @@ -90,6 +91,7 @@
"Tempest\\Core\\": "src/Tempest/Core/src",
"Tempest\\Database\\": "src/Tempest/Database/src",
"Tempest\\Debug\\": "src/Tempest/Debug/src",
"Tempest\\Discovery\\": "src/Tempest/Discovery/src",
"Tempest\\EventBus\\": "src/Tempest/EventBus/src",
"Tempest\\Filesystem\\": "src/Tempest/Filesystem/src",
"Tempest\\Framework\\": "src/Tempest/Framework",
Expand Down Expand Up @@ -129,6 +131,7 @@
"Tempest\\Container\\Tests\\": "src/Tempest/Container/tests",
"Tempest\\Core\\Tests\\": "src/Tempest/Core/tests",
"Tempest\\Database\\Tests\\": "src/Tempest/Database/tests",
"Tempest\\Discovery\\Tests\\": "src/Tempest/Discovery/tests",
"Tempest\\EventBus\\Tests\\": "src/Tempest/EventBus/tests",
"Tempest\\Filesystem\\Tests\\": "src/Tempest/Filesystem/tests",
"Tempest\\Generation\\Tests\\": "src/Tempest/Generation/tests",
Expand Down
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Tempest\Core\DiscoveryLocation;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Router\HttpApplication;

require_once __DIR__ . '/../vendor/autoload.php';
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Auth/src/Install/CreatePermissionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Tempest\Auth\Install;

use Tempest\Core\DoNotDiscover;
use Tempest\Database\DatabaseMigration;
use Tempest\Database\QueryStatements\CreateTableStatement;
use Tempest\Database\QueryStatements\DropTableStatement;
use Tempest\Discovery\DoNotDiscover;

#[DoNotDiscover]
final class CreatePermissionsTable implements DatabaseMigration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Tempest\Auth\Install;

use Tempest\Core\DoNotDiscover;
use Tempest\Database\DatabaseMigration;
use Tempest\Database\QueryStatements\CreateTableStatement;
use Tempest\Database\QueryStatements\DropTableStatement;
use Tempest\Discovery\DoNotDiscover;

#[DoNotDiscover]
final class CreateUserPermissionsTable implements DatabaseMigration
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Auth/src/Install/CreateUsersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Tempest\Auth\Install;

use Tempest\Core\DoNotDiscover;
use Tempest\Database\DatabaseMigration;
use Tempest\Database\QueryStatements\CreateTableStatement;
use Tempest\Database\QueryStatements\DropTableStatement;
use Tempest\Discovery\DoNotDiscover;

#[DoNotDiscover]
final class CreateUsersTable implements DatabaseMigration
Expand Down
6 changes: 3 additions & 3 deletions src/Tempest/Cache/src/CacheDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Tempest\Cache;

use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class CacheDiscovery implements Discovery
Expand Down
6 changes: 3 additions & 3 deletions src/Tempest/CommandBus/src/CommandBusDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Tempest\CommandBus;

use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class CommandBusDiscovery implements Discovery
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Console/src/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
) {
}

/** @param \Tempest\Core\DiscoveryLocation[] $discoveryLocations */
/** @param \Tempest\Discovery\DiscoveryLocation[] $discoveryLocations */
public static function boot(
string $name = 'Tempest',
?string $root = null,
Expand Down
6 changes: 3 additions & 3 deletions src/Tempest/Console/src/Discovery/ConsoleCommandDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Tempest\Console\ConsoleCommand;
use Tempest\Console\ConsoleConfig;
use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class ConsoleCommandDiscovery implements Discovery
Expand Down
6 changes: 3 additions & 3 deletions src/Tempest/Console/src/Discovery/ScheduleDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Tempest\Console\ConsoleCommand;
use Tempest\Console\Schedule;
use Tempest\Console\Scheduler\SchedulerConfig;
use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class ScheduleDiscovery implements Discovery
Expand Down
6 changes: 3 additions & 3 deletions src/Tempest/Container/src/AutowireDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Tempest\Container;

use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Tempest/Container/src/InitializerDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Tempest\Container;

use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Tempest/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"php": "^8.4",
"tempest/container": "dev-main",
"tempest/support": "dev-main",
"tempest/discovery": "dev-main",
"vlucas/phpdotenv": "^5.6",
"filp/whoops": "^2.15"
},
Expand Down
2 changes: 2 additions & 0 deletions src/Tempest/Core/src/DiscoveryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Tempest\Cache\CacheConfig;
use Tempest\Cache\DiscoveryCacheStrategy;
use Tempest\Cache\IsCache;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryItems;
use function Tempest\path;

final class DiscoveryCache implements Cache
Expand Down
3 changes: 3 additions & 0 deletions src/Tempest/Core/src/DiscoveryDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Tempest\Core;

use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class DiscoveryDiscovery implements Discovery
Expand Down
3 changes: 3 additions & 0 deletions src/Tempest/Core/src/InstallerDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Tempest\Core;

use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class InstallerDiscovery implements Discovery
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Core/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Kernel

public function __construct(
public string $root,
/** @var \Tempest\Core\DiscoveryLocation[] $discoveryLocations */
/** @var \Tempest\Discovery\DiscoveryLocation[] $discoveryLocations */
public array $discoveryLocations = [],
?Container $container = null,
) {
Expand Down
10 changes: 5 additions & 5 deletions src/Tempest/Core/src/Kernel/LoadDiscoveryClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
use SplFileInfo;
use Tempest\Cache\DiscoveryCacheStrategy;
use Tempest\Container\Container;
use Tempest\Core\DiscoversPath;
use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryCache;
use Tempest\Core\DiscoveryDiscovery;
use Tempest\Core\DiscoveryItems;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\DoNotDiscover;
use Tempest\Core\Kernel;
use Tempest\Discovery\DiscoversPath;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryItems;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\DoNotDiscover;
use Tempest\Reflection\ClassReflector;
use Throwable;

Expand Down
4 changes: 2 additions & 2 deletions src/Tempest/Core/src/Kernel/LoadDiscoveryLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Tempest\Core\Kernel;

use Tempest\Core\Composer;
use Tempest\Core\DiscoveryException;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\Kernel;
use Tempest\Discovery\DiscoveryException;
use Tempest\Discovery\DiscoveryLocation;
use function Tempest\path;

/** @internal */
Expand Down
1 change: 1 addition & 0 deletions src/Tempest/Core/src/PublishesFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Tempest\Console\Exceptions\ConsoleException;
use Tempest\Console\HasConsole;
use Tempest\Container\Inject;
use Tempest\Discovery\DoNotDiscover;
use Tempest\Generation\ClassManipulator;
use Tempest\Generation\DataObjects\StubFile;
use Tempest\Generation\Enums\StubFileType;
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Core/src/Tempest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
public static function boot(
?string $root = null,
/** @var \Tempest\Core\DiscoveryLocation[] $discoveryLocations */
/** @var \Tempest\Discovery\DiscoveryLocation[] $discoveryLocations */
array $discoveryLocations = [],
): Container {
$root ??= getcwd();
Expand Down
8 changes: 4 additions & 4 deletions src/Tempest/Database/src/MigrationDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Tempest\Database;

use Tempest\Core\DiscoversPath;
use Tempest\Core\Discovery;
use Tempest\Core\DiscoveryLocation;
use Tempest\Core\IsDiscovery;
use Tempest\Discovery\DiscoversPath;
use Tempest\Discovery\Discovery;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Discovery\IsDiscovery;
use Tempest\Reflection\ClassReflector;

final class MigrationDiscovery implements Discovery, DiscoversPath
Expand Down
10 changes: 10 additions & 0 deletions src/Tempest/Discovery/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Exclude build/test files from the release
.github/ export-ignore
tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpunit.xml export-ignore
README.md export-ignore

# Configure diff output for .php and .phar files.
*.php diff=php
9 changes: 9 additions & 0 deletions src/Tempest/Discovery/LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2024 Brent Roose [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions src/Tempest/Discovery/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "tempest/discovery",
"description": "Discover PHP classes and files",
"license": "MIT",
"minimum-stability": "dev",
"require": {
"php": "^8.4",
"tempest/reflection": "dev-main"
},
"autoload": {
"psr-4": {
"Tempest\\Discovery\\": "src"
},
"files": []
}
}
13 changes: 13 additions & 0 deletions src/Tempest/Discovery/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" displayDetailsOnPhpunitDeprecations="true" failOnPhpunitDeprecation="false" failOnRisky="true" failOnWarning="true">
<testsuites>
<testsuite name="Tempest Discovery">
<directory>tests</directory>
</testsuite>
</testsuites>
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

interface DiscoversPath
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

use Tempest\Reflection\ClassReflector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

use Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

use ArrayIterator;
use Countable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

final readonly class DiscoveryLocation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

use Attribute;

Expand All @@ -12,7 +12,7 @@ final class DoNotDiscover
public function __construct(
/**
* Allows the specified `Discovery` classes to still discover this class.
* @var array<class-string<\Tempest\Core\Discovery>>
* @var array<class-string<\Tempest\Discovery\Discovery>>
*/
public readonly array $except = [],
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Tempest\Core;
namespace Tempest\Discovery;

/** @phpstan-require-implements \Tempest\Core\Discovery */
/** @phpstan-require-implements \Tempest\Discovery\Discovery */
trait IsDiscovery
{
private DiscoveryItems $discoveryItems;
Expand Down
Empty file.
Loading

0 comments on commit 58aadc9

Please sign in to comment.