ergebnis / classy
Provides a finder for classy constructs (classes, enums, interfaces, and traits).
Installs: 1 267 283
Dependents: 17
Suggesters: 0
Security: 0
Stars: 30
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ~8.1.0 || ~8.2.0
- ext-tokenizer: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.36.0
- ergebnis/license: ^2.1.0
- ergebnis/php-cs-fixer-config: ^5.15.1
- ergebnis/phpunit-slow-test-detector: ^2.3.0
- fakerphp/faker: ^1.23.0
- infection/infection: ~0.27.0
- phpunit/phpunit: ^10.3.4
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ~0.18.3
- vimeo/psalm: ^5.15.0
README
This package provides 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 package record notable changes to this project in a changelog.
Contributing
The maintainers of this package suggest following the contribution guide.
Code of Conduct
The maintainers of this package ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this package provide limited support.
You can support the maintenance of this package by sponsoring @localheinz or requesting an invoice for services related to this package.
PHP Version Support Policy
This package supports PHP versions with active support.
The maintainers of this package add support for a PHP version following its initial release and drop support for a PHP version when it has reached its end of active support.
Security Policy
This package has a security policy.
License
This package 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.