https://github.com/thecodingmachine/class-explorer
Find the list of all your PHP classes and more.
https://github.com/thecodingmachine/class-explorer
Last synced: 3 months ago
JSON representation
Find the list of all your PHP classes and more.
- Host: GitHub
- URL: https://github.com/thecodingmachine/class-explorer
- Owner: thecodingmachine
- Created: 2018-08-29T13:06:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-11T00:45:03.000Z (almost 2 years ago)
- Last Synced: 2025-09-30T05:47:06.339Z (4 months ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 12
- Watchers: 8
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Class Explorer
===============
[](https://packagist.org/packages/thecodingmachine/class-explorer)
[](https://packagist.org/packages/thecodingmachine/class-explorer)
[](https://packagist.org/packages/thecodingmachine/class-explorer)
[](https://packagist.org/packages/thecodingmachine/class-explorer)
[](https://travis-ci.org/thecodingmachine/class-explorer)
[](https://coveralls.io/github/thecodingmachine/class-explorer?branch=master)
Discover PHP classes in your project.
This project aim is to offer a set of classes enabling classes/interface/trait discovery in your own project.
Currently, the project contains only one implementation based on scanning files.
GlobClassExplorer
-----------------
The `GlobClassExplorer` will look for all classes in a given namespace.
## Usage
```php
$explorer = new GlobClassExplorer('\\Some\\Namespace\\', $psr16Cache, $cacheTtl);
$classes = $explorer->getClasses();
// Will return: ['Some\Namespace\Foo', 'Some\Namespace\Bar', ...]
```
This explorer:
- looks only for classes in YOUR project (not in the vendor directory)
- assumes that if a file exists in a PSR-0 or PSR-4 directory, the class is available (assumes the file respects PSR-1)
- makes no attempt at autoloading the class
- is pretty fast, even when no cache is involved
By default, `GlobClassExplorer` will load classes recursively in sub-namespaces. You can prevent it to load classes
recursively by passing `false` to the 5th parameter:
```php
$explorer = new GlobClassExplorer('\\This\\Namespace\\Only\\', $psr16Cache, $cacheTtl, null, false);
```
You can also get a class map using the `getClassMap` method.
A class map is an array associating the name of the classes found (in key), to the file they are
linked to (the real path of the file).
```php
$classMap = $explorer->getClassMap();
foreach ($classMap as $class => $file) {
echo 'Class '.$class.' found in file '.$file;
}
```