Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brenoroosevelt/flex-fqcn-finder
Flexible FQCN Finder
https://github.com/brenoroosevelt/flex-fqcn-finder
compositions decorators filters finder flex-fqcn-finder fqcn
Last synced: 28 days ago
JSON representation
Flexible FQCN Finder
- Host: GitHub
- URL: https://github.com/brenoroosevelt/flex-fqcn-finder
- Owner: brenoroosevelt
- License: mit
- Created: 2021-04-04T16:07:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-12T14:42:53.000Z (over 1 year ago)
- Last Synced: 2024-11-21T01:59:13.719Z (about 1 month ago)
- Topics: compositions, decorators, filters, finder, flex-fqcn-finder, fqcn
- Language: PHP
- Homepage:
- Size: 52.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flex FQCN Finder
[![Build](https://github.com/brenoroosevelt/flex-fqcn-finder/actions/workflows/ci.yml/badge.svg)](https://github.com/brenoroosevelt/oni-bus/actions/workflows/ci.yml)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/brenoroosevelt/flex-fqcn-finder/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/brenoroosevelt/flex-fqcn-finder/?branch=main)
[![codecov](https://codecov.io/gh/brenoroosevelt/flex-fqcn-finder/branch/main/graph/badge.svg?token=S1QBA18IBX)](https://codecov.io/gh/brenoroosevelt/flex-fqcn-finder)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)The Flex FQCN Finder allows you to find all the Fully Qualified Class Names (FQCN) available in a project. This package was designed to be flexible and reliable.
## Features- Find classes, traits and interfaces (PSR-4 complaint);
- Search in directories (recursively or not);
- Many filter options;
- Cache (PSR-16 complaint).
- Composite finders.
- Get classes from Composer ClassMap.## Requirements
* The following versions of PHP are supported: `^8`.
* For PHP 7.*, please install version 1.0.0## Install
``` bash
$ composer require brenoroosevelt/flex-fqcn-finder
```## Usage
Use the `FlexFqcnFinder\Fqcn` helper to apply filters, decorators and compositions on your own way.```php
addDirectory('/path/to/dir1', $recursive)
->addDirectory('/path/to/dir2', !$recursive)
->withFilter(
Filter::by() // or: Filter::anyOf()
->implementsInterface('MyInterface')
->hasMethod('method')
)
->includeDeclaredClasses()
->withCache(new MyPsr16Cache(), 'cacheKey')
->find();var_dump($fqcns);
/* output
[
'NamespaceA\FooClass',
'NamespaceB\BarClass',
'NamespaceC\Traits\HelperTrait'
]
*/
```### Finders
Finders are classes that implement interface `FqcnFinderInterface` and return a list (array) of FQCNs found.
```php
find();
```
### DecoratorsDecorators available for Finders:
* `FlexFqcnFinder\Finder\Decorator\CachedFqcnFinder`
* `FlexFqcnFinder\Finder\Decorator\FilteringFqcnFinder`You can decorate any finder (including compositions):
```php
find();
```#### Filters
Filters can be used as a Decorator for Finders and using it is optional.All filters have been designed according to the Specification Pattern. You can chain the following filters using `Filter::by()` or `Filter::anyOf()`:
* `apply(Closure $fn)`
* `belongsToNamespace(string $namespace)`
* `classNameEndsWith(string $value)`
* `classNameStartsWith(string $value)`
* `hasMethod(string $method)`
* `implementsInterface(string $interface)`
* `isAbstract()`
* `isClass()`
* `isCloneable()`
* `isFinal()`
* `isInstanceOf(string $subject)`
* `isInstantiable()`
* `isInterface()`
* `isInternal()`
* `isIterateable()`
* `isSubClassOf(string $class)`
* `isTrait()`
* `isUserDefined()`
* `namespaceEqualsTo(string $namespace)`
* `not(FqcnSpecification $specification)`
* `useTrait(string $trait)`
* `anyOf(FqcnSpecification ...$specifications)`
* `allOf(FqcnSpecification ...$specifications)`
* `and(FqcnSpecification ...$specifications)`
* `or(FqcnSpecification ...$specifications)`Any filter can be used with `FlexFqcnFinder\Finder\Decorator\FilteringFqcnFinder` decorator:
```php
implementsInterface('MyInterface')
->hasMethod('execute')
->and(
Filter::by()
->usingTrait('MyTrait')
->apply(function($fqcn) {
return $fqcn === 'my_condition';
})
)
);$fqcns = $filtered->find();
```#### Creating Filters
You can create you own filter implementing interface `FqcnSpecification`:```php
find();```
## Contributing
Please read the Contributing guide to learn about contributing to this project.
## License
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE.md) file for license rights and limitations.