danog/class-finder
Fast PHP class discovery utility. Scan directories/files and find classes, interfaces, and traits without manually maintaining lists. Useful for autoload-based plugins, reflection tooling, and package indexing, with a simple API and minimal setup.
composer --perfer-dist. Thanks, Benedikt FrankeClassfinder::namespaceHasClasses to detect if a namespace is empty. Thanks, Benedikt Frankeexec function was disabled by PHP configuration - even when files support was explicitly disabled. Thanks, incraigulous.autoload configuration. Thanks, walid.ammar and TheFehr.composer.json should be more consistent and no longer immediately fallback to /.ClassFinder::getClassesInNamespace()
in this mode will result in classes in subnamespaces being turned up.<?php
require_once __DIR__ . '/vendor/autoload.php';
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo', 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);
files entries in composer.json. Including this feature
is a significant drain on performance, so it must be explicitly enabled.<?php
require_once __DIR__ . '/vendor/autoload.php';
ClassFinder::enableExperimentalFilesSupport();
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo');
<?php
require_once __DIR__ . '/vendor/autoload.php';
ClassFinder::disablePSR4Support();
ClassFinder::disableClassmapSupport();
$classes = ClassFinder::getClassesInNamespace('TestApp1\Foo');
classmap.classmap)Example composer.json that is now supported:
...
"autoload": {
...
"classmap": [ "src/foo/", "src/bar/" ]
}
...
Unknown namespace Acme\Whatever. Checked for files in , but that directory did not exist. [...]
when that namespace does indeed exist.Acme, when Acme\Foo is a better choice)Mapping a namespace to multiple directories:
...
"autoload": {
"psr-4": {
"Acme\\Foo\\": [ "src/", "srcButDifferent/" ]
}
}
...
Old overriding app root:
ClassFinder::appRoot = '/home/hpierce/whatevs';
New overriding app root:
ClassFinder::setAppRoot('/home/hpierce/whatevs');
How can I help you explore Laravel packages today?