PHP code example of spatie / php-structure-discoverer
1. Go to this page and download the library: Download spatie/php-structure-discoverer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / php-structure-discoverer example snippets
use Spatie\StructureDiscoverer\Discover;
// PostModel::class, Collection::class, ...
Discover::in(__DIR__)->classes()->implementing(Arrayable::class)->get();
return [
/*
* A list of files that should be ignored during the discovering process.
*/
'ignored_files' => [
],
/**
* The directories where the package should search for structure scouts
*/
'structure_scout_directories' => [
app_path(),
],
/*
* Configure the cache driver for discoverers
*/
'cache' => [
'driver' => \Spatie\StructureDiscoverer\Cache\LaravelDiscoverCacheDriver::class,
'store' => null,
]
];
use Spatie\StructureDiscoverer\Enums\Sort;
Discover::in(__DIR__)->sortBy(Sort::Name)->get();
use Spatie\StructureDiscoverer\Enums\Sort;
Discover::in(__DIR__)->sortBy(Sort::Name);
Discover::in(__DIR__)->sortBy(Sort::Size);
Discover::in(__DIR__)->sortBy(Sort::Type);
Discover::in(__DIR__)->sortBy(Sort::Extension);
Discover::in(__DIR__)->sortBy(Sort::ChangedTime);
Discover::in(__DIR__)->sortBy(Sort::ModifiedTime);
Discover::in(__DIR__)->sortBy(Sort::AccessedTime);
Discover::in(__DIR__)->sortBy(Sort::CaseInsensitiveName);
class EnumsStructureScout extends StructureScout
{
protected function definition(): Discover|DiscoverConditionFactory
{
return Discover::in(__DIR__)->enums();
}
public function cacheDriver(): DiscoverCacheDriver
{
return new FileDiscoverCacheDriver('/path/to/temp/directory');
}
}
interface DiscoverCacheDriver
{
public function has(string $id): bool;
public function get(string $id): array;
public function put(string $id, array $discovered): void;
public function forget(string $id): void;
}
Discover::in(__DIR__)
->withCache(
'Some identifier',
new FileDiscoverCacheDriver('/path/to/temp/directory);
)
->get();
Discover::in(__DIR__)->parallel()->get();
Discover::in(__DIR__)->parallel(100)->get();
class Request
{
}
class FormRequest extends Request
{
}
class UserFormRequest extends FormRequest
{
}
class DiscoveredClass extends DiscoveredStructure
{
public function __construct(
string $name,
string $file,
string $namespace,
public bool $isFinal,
public bool $isAbstract,
public bool $isReadonly,
public ?string $extends,
public array $implements,
public array $attributes,
public ?array $extendsChain = null,
public ?array $implementsChain = null,
) {
}
}
class DiscoveredInterface extends DiscoveredStructure
{
public function __construct(
string $name,
string $file,
string $namespace,
public array $extends,
public array $attributes,
public ?array $extendsChain = null,
) {
}
class DiscoveredEnum extends DiscoveredStructure
{
public function __construct(
public string $name,
public string $namespace,
public string $file,
public DiscoveredEnumType $type,
public array $implements,
public array $attributes,
public ?array $implementsChain = null,
) {
}
}
class DiscoveredTrait extends DiscoveredStructure
{
public function __construct(
public string $name,
public string $namespace,
public string $file,
) {
}
}