ergebnis / classy
Provides a finder for classy constructs (classes, interfaces, and traits).
Fund package maintenance!
localheinz
Installs: 404 093
Dependents: 7
Suggesters: 0
Security: 0
Stars: 16
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- ext-tokenizer: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.13.2
- ergebnis/license: ^1.1.0
- ergebnis/php-cs-fixer-config: ^2.13.0
- ergebnis/phpstan-rules: ~0.15.3
- ergebnis/test-util: ^1.0.0
- infection/infection: ~0.15.3
- phpstan/extension-installer: ^1.1.0
- phpstan/phpstan: ~0.12.70
- phpstan/phpstan-deprecation-rules: ~0.12.6
- phpstan/phpstan-strict-rules: ~0.12.9
- phpunit/phpunit: ^8.5.14
- psalm/plugin-phpunit: ~0.15.0
- vimeo/psalm: ^4.4.1
- zendframework/zend-file: ^2.8.3
README
Provides a finder for classy constructs (classes, interfaces, and traits).
Installation
Run
$ composer require ergebnis/classy
Usage
Collect classy constructs from source code
Use Constructs::fromSource()
to collect classy constructs in source code:
<?php use Ergebnis\Classy\Construct; use Ergebnis\Classy\Constructs; $source = <<<'PHP' <?php namespace Example; class Foo {} interface Bar {} trait Baz {} PHP; /** @var Construct[] $constructs */ $constructs = Constructs::fromSource($source); $names = array_map(static function (Construct $construct): string { return $construct->name(); }, $constructs); var_dump($names); // ['Example\Bar', 'Example\Baz', 'Example\Foo']
Collect classy constructs from a directory
Use Constructs::fromDirectory()
to collect classy constructs in a directory:
<?php use Ergebnis\Classy\Construct; use Ergebnis\Classy\Constructs; /** @var Construct[] $constructs */ $constructs = Constructs::fromDirectory(__DIR__ . '/example'); $names = array_map(static function (Construct $construct): string { return $construct->name(); }, $constructs); var_dump($names); // ['Example\Bar', 'Example\Bar\Baz', 'Example\Foo\Bar\Baz']
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Credits
The algorithm for finding classes in PHP files in Constructs
has been adopted from Zend\File\ClassFileLocator
(originally licensed under BSD-3-Clause).
Curious what I am building?
📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.