Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alekitto/class-finder
Utility classes to help discover other classes/namespaces
https://github.com/alekitto/class-finder
class-discovery class-finder namespaces-php
Last synced: 3 days ago
JSON representation
Utility classes to help discover other classes/namespaces
- Host: GitHub
- URL: https://github.com/alekitto/class-finder
- Owner: alekitto
- License: mit
- Created: 2018-01-08T00:17:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T23:00:07.000Z (7 months ago)
- Last Synced: 2024-05-01T12:38:22.288Z (7 months ago)
- Topics: class-discovery, class-finder, namespaces-php
- Language: PHP
- Homepage: https://alekitto.github.io/class-finder/
- Size: 260 KB
- Stars: 26
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ClassFinder
Utility classes to help discover other classes/namespaces
![Tests](https://github.com/alekitto/class-finder/workflows/Tests/badge.svg)
[![codecov](https://codecov.io/gh/alekitto/class-finder/branch/master/graph/badge.svg)](https://codecov.io/gh/alekitto/class-finder)---
## Installation
```bash
$ composer require kcs/class-finder
```## Usage
Finder helps you to discover classes into your project.
The most common way to discover is to use the provided `ComposerFinder`.
This will search for classes using the auto-generated class loader
from composer and resolving PSR-* namespaces accordingly.Read more in the docs at [https://alekitto.github.io/class-finder/](https://alekitto.github.io/class-finder/)
### Basic usage
```php
use Kcs\ClassFinder\Finder\ComposerFinder;$finder = new ComposerFinder();
foreach ($finder as $className => $reflector) {
// Do magic things...
}
```### Filtering
You can filter classes using the methods exposed by `FinderInterface`:
- `implementationOf(array $interfaces)`: Finds the classes that implements
all the given interfaces. You can pass a single interface as string.
- `subclassOf(string $superClass)`: Finds all the classes that are subclasses
of the given class.
- `annontatedBy(string $annotationClass)`: Finds all the classes that have
the given annotation in the class docblock.
- `withAttribute(string $attributeClass)`: Finds all the classes that have
the given attribute applied on the class (PHP >= 8.0) only.
- `in(array $dirs)`: Searches only in given directories.
- `inNamespace(array $namespaces)`: Searches only in given namespaces.
- `filter(callable $callback)`: Custom filtering callback.
- `pathFilter(callable $callback)`: Custom filtering callback for loading files.## License
This library is released under the MIT license.
## Contributions
Contributions are always welcome.
Please feel free to open a PR or file an issue.---
Thank you for reading
A.