localheinz / classy
Provides a finder for classy constructs (classes, enums, interfaces, and traits).
Fund package maintenance!
localheinz
Installs: 74 839
Dependents: 0
Suggesters: 0
Security: 0
Stars: 28
Watchers: 2
Forks: 3
Open Issues: 2
Requires
- php: ^7.4 || ^8.0
- ext-tokenizer: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.22.0
- ergebnis/license: ^1.1.0
- ergebnis/php-cs-fixer-config: ^3.4.0
- fakerphp/faker: ^1.17.0
- infection/infection: ~0.25.5
- phpunit/phpunit: ^9.5.11
- psalm/plugin-phpunit: ~0.16.1
- vimeo/psalm: ^4.16.1
- zendframework/zend-file: ^2.8.3
- 1.3.0
- 1.2.0
- 1.1.1
- 1.1.0
- dev-main / 1.0.x-dev
- 1.0.1
- 1.0.0
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-dependabot/composer/phpunit/phpunit-9.5.21
- dev-dependabot/composer/ergebnis/composer-normalize-2.28.1
- dev-dependabot/github_actions/codecov/codecov-action-3.1.0
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-4.14.1
This package is auto-updated.
Last update: 2022-06-23 16:13:52 UTC
README
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 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 {} enum Bar {} interface Baz {} trait Qux {} PHP; $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', 'Example\Qux']
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; $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.