ergebnis / classy
Provides a finder for classy constructs (classes, enums, interfaces, and traits).
Installs: 1 624 883
Dependents: 24
Suggesters: 0
Security: 0
Stars: 35
Watchers: 3
Forks: 3
Open Issues: 2
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-tokenizer: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.39.0
- ergebnis/license: ^2.3.0
- ergebnis/php-cs-fixer-config: ~6.12.0
- ergebnis/phpunit-slow-test-detector: ^2.4.0
- fakerphp/faker: ^1.23.0
- infection/infection: ~0.27.8
- phpunit/phpunit: ^10.4.2
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ~0.18.11
- vimeo/psalm: ^5.16.0
README
This project provides a composer
package with a finder for classy constructs (classes, enums, interfaces, and traits).
Installation
Run
composer require ergebnis/classy
Usage
Collect classy constructs from source code
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']
Collect classy constructs from a directory
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']
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
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.
PHP Version Support Policy
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.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Credits
The algorithm for finding classes in PHP files in Constructs
has been adopted from Zend\File\ClassFileLocator
(originally licensed under BSD-3-Clause).
Social
Follow @localheinz and @ergebnis on Twitter.