This project provides a composer
package with a finder for classy constructs (classes, enums, interfaces, and traits).
Run
composer require ergebnis/classy
Use Classy\Constructs::fromSource()
to collect classy constructs in source code:
<?php
declare(strict_types=1);
use Ergebnis\Classy;
$source = <<<'PHP'
<?php
namespace Example;
class Foo {}
enum Bar {}
interface Baz {}
trait Qux {}
PHP;
$constructs = Classy\Constructs::fromSource($source);
$names = array_map(static function (Classy\Construct $construct): string {
return $construct->name();
}, $constructs);
var_dump($names); // ['Example\Bar', 'Example\Baz', 'Example\Foo', 'Example\Qux']
Use Classy\Constructs::fromDirectory()
to collect classy constructs in a directory:
<?php
declare(strict_types=1);
use Ergebnis\Classy;
$constructs = Classy\Constructs::fromDirectory(__DIR__ . '/example');
$names = array_map(static function (Classy\Construct $construct): string {
return $construct->name();
}, $constructs);
var_dump($names); // ['Example\Bar', 'Example\Bar\Baz', 'Example\Foo\Bar\Baz']
The maintainers of this project record notable changes to this project in a changelog.
The maintainers of this project suggest following the contribution guide.
The maintainers of this project ask contributors to follow the code of conduct.
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.
This project supports PHP versions with active and security support.
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
This project has a security policy.
This project uses the MIT license.
The algorithm for finding classes in PHP files in Constructs
has been adopted from Zend\File\ClassFileLocator
(originally licensed under BSD-3-Clause).
Follow @localheinz and @ergebnis on Twitter.