daycry / class-finder
Namespace Class Finder
Installs: 4 259
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4 || ^8.0
- kint-php/kint: ^4 || ^5
Requires (Dev)
- codeigniter4/framework: ^4
- daycry/twig: ^1
- friendsofphp/php-cs-fixer: 3.6.*
- mikey179/vfsstream: ^1.6
- nexusphp/cs-config: ^3.3
- nexusphp/tachycardia: ^1.0
- phpstan/phpstan: ^1.7.1
- phpunit/phpunit: ^9.1
- rector/rector: 0.13.9
README
ClassFinder
===========
A dead simple utility to identify classes in a given namespace for Codeigniter 4
Requirements
- Application is using Composer.
- Classes can be autoloaded with Composer.
- PHP >= 7.4.0
Installing
Installing is done by requiring it with Composer.
$ composer require daycry/class-finder
Examples
Standard Mode
<?php $classes = (new \Daycry\ClassFinder\ClassFinder())->getClassesInNamespace('Daycry'); /** * array( * 'TestApp1\Foo\Bar', * 'TestApp1\Foo\Baz', * 'TestApp1\Foo\Foo' * ) */ var_dump($classes);
Recursive Mode
<?php $classes = (new \Daycry\ClassFinder\ClassFinder())->getClassesInNamespace('Daycry', \Daycry\ClassFinder\ClassFinder::RECURSIVE_MODE); /** * array( * 'TestApp1\Foo\Bar', * 'TestApp1\Foo\Baz', * 'TestApp1\Foo\Foo', * 'TestApp1\Foo\Box\Bar', * 'TestApp1\Foo\Box\Baz', * 'TestApp1\Foo\Box\Foo', * 'TestApp1\Foo\Box\Lon\Bar', * 'TestApp1\Foo\Box\Lon\Baz', * 'TestApp1\Foo\Box\Lon\Foo', * ) */ var_dump($classes);
If you want to modify the configuration, you can modify the file Config/ClassFinder.php
or
Edit the configuration and pass it to the constructor
<?php $config = config('ClassFinder'); $config->finder['classMap'] = false; $config->finder['files'] = false; $classes = (new \Daycry\ClassFinder\ClassFinder($config))->getClassesInNamespace('Daycry', \Daycry\ClassFinder\ClassFinder::RECURSIVE_MODE);
You can customize the search engine indicating if you want to search for classes, interfaces, traits or functions.
This library also integrates the Autoload.php class from the Config folder to perform searches.
<?php $config = config('ClassFinder'); $config->finder['classMap'] = false; $config->finder['files'] = false; $classes = (new \Daycry\ClassFinder\ClassFinder($config))->getClassesInNamespace('App', \Daycry\ClassFinder\ClassFinder::RECURSIVE_MODE); $classes = (new \Daycry\ClassFinder\ClassFinder($config))->getClassesInNamespace('Config', \Daycry\ClassFinder\ClassFinder::RECURSIVE_MODE);
<?php $config = config('ClassFinder'); $config->finder['classMap'] = false; $config->finder['files'] = false; $classes = (new \Daycry\ClassFinder\ClassFinder($config))->getClassesInNamespace('Daycry', \Daycry\ClassFinder\ClassFinder::RECURSIVE_MODE | \Daycry\ClassFinder\ClassFinder::ALLOW_CLASSES | \Daycry\ClassFinder\ClassFinder::ALLOW_INTERFACES | \Daycry\ClassFinder\ClassFinder::ALLOW_TRAITS | \Daycry\ClassFinder\ClassFinder::ALLOW_FUNCTIONS );