ergebnis/classy
ergebnis/classy adds convenient helpers for working with PHP classes and reflection. Generate class names, namespaces, and short names, and inspect class metadata in a clean, test-friendly way—useful for tooling, libraries, and code generation.
ergebnis/classy) provides runtime reflection capabilities for PHP class constructs (classes, enums, interfaces, traits), which aligns well with Laravel’s dependency injection (DI) container, service providers, and dynamic metadata needs (e.g., validation rules, policies, or custom logic based on class hierarchies).ReflectionClass, ClassLoader) but offers a more ergonomic API for batch operations (e.g., collecting all classes implementing an interface).Illuminate\Support\Manager or Illuminate\Contracts\Container\BindingResolution for advanced use cases.eval), which may limit use cases in Laravel’s event system or middleware.composer dump-autoload or incorrect PSR-4 paths).app_path(), config('app.namespace'), and config('autoload.psr-4').vendor/ or bootstrap/).app/, config/, or custom paths.Cache::remember)?app()->tagged(), collect(app()->getBindings())) suffice?ClassyServiceProvider) and bind a facade or manager class for global access.
// app/Providers/ClassyServiceProvider.php
public function register()
{
$this->app->singleton(ClassyCollector::class, function () {
return new ClassyCollector(app_path());
});
}
php artisan classy:scan --interface=ContractInterface).Classy::classesImplementing(Contract::class)).$classes = Cache::remember('classy_scan_'.md5($interface), now()->addHours(1), function () use ($interface) {
return Classy::classesImplementing($interface);
});
booted or registered events (e.g., after service providers load).ReflectionClass checks in a test suite with Classy::verifyImplements().get_declared_classes() with Classy::allClasses().Illuminate\Container\Container::build() to check for interface implementations.ext-reflection.Collector class to add Laravel-specific filters (e.g., exclude vendor/ or tests/ paths).
class LaravelClassyCollector extends ClassyCollector
{
public function __construct(string $basePath = app_path())
{
parent::__construct($basePath);
$this->ignorePaths(['vendor', 'tests']);
}
}
composer require ergebnis/classy
public function test_collects_classes_implementing_interface()
{
$collector = new ClassyCollector(app_path());
$classes = $collector->classesImplementing(ContractInterface::class);
$this->assertContains(MyService::class, $classes);
}
tideways or laravel-debugbar).ergebnis/classy for breaking changes (e.g., PHP 9.0+ support).^1.0) and test upgrades in a staging environment.README or CONTRIBUTING.md.ShouldQueue interfaces, extend ClassyCollector and override shouldCollect()."dd() or Xdebug to inspect class paths.debugbar to log scan results.php artisan classy:scan --cache).app/ with 1000+ classes may time out. Optimize with:
spatie/async).spatie/laravel-model-caching).How can I help you explore Laravel packages today?