mirror of
https://github.com/danog/class-finder.git
synced 2025-01-22 22:01:19 +01:00
Update documentation.
This commit is contained in:
parent
4ecfb28c51
commit
74d70a30c3
45
README.md
45
README.md
@ -1,7 +1,7 @@
|
||||
ClassFinder
|
||||
===========
|
||||
|
||||
A lightweight utility to identify classes in a given namespace. This package is an improved implementation of an
|
||||
A dead simple utility to identify classes in a given namespace. This package is an improved implementation of an
|
||||
[answer on Stack Overflow](https://stackoverflow.com/a/40229665/3000068) that provides additional features with less
|
||||
configuration required.
|
||||
|
||||
@ -9,15 +9,8 @@ Requirements
|
||||
------------
|
||||
|
||||
* Application is using Composer.
|
||||
* Classes are compliant with PSR-4.
|
||||
* Classes can be autoloaded with PSR-4 or classmaps.
|
||||
* PHP >= 5.3.0
|
||||
|
||||
Known Limitations
|
||||
-----------------
|
||||
|
||||
* ClassFinder can only identify classes autoloaded with PSR-4. PSR-0, classmaps, and files are not supported.
|
||||
|
||||
These limitations may eventually be fixed.
|
||||
|
||||
Installing
|
||||
----------
|
||||
@ -64,4 +57,36 @@ Documentation
|
||||
**Internals**
|
||||
|
||||
* [How Testing Works](docs/testing.md)
|
||||
* [Continuous Integration Notes](docs/ci.md)
|
||||
* [Continuous Integration Notes](docs/ci.md)
|
||||
|
||||
Roadmap
|
||||
-------
|
||||
|
||||
> **WARNING**: Before 1.0.0, expect that bug fixes _will not_ be backported to older versions. Backwards incompatible changes
|
||||
may be introduced in minor 0.X.Y versions, where X changes.
|
||||
|
||||
0.0.1 - First party `psr4` classes
|
||||
|
||||
0.1.0 - Third party `psr4` classes
|
||||
|
||||
0.2.0 - `classmap` support.
|
||||
|
||||
0.3.0 - `files` support
|
||||
|
||||
0.4.0 - `psr0` support
|
||||
|
||||
0.5.0 - Additional features:
|
||||
|
||||
Various ideas:
|
||||
|
||||
* `ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE)`.
|
||||
Providing classes multiple namespaces deep.
|
||||
|
||||
* `ClassFinder::getClassesImplementingInterface('TestApp1\Foo', 'TestApp1\FooInterface', ClassFinder::RECURSIVE_MODE)`.
|
||||
Filtering classes to only classes that implement a namespace.
|
||||
|
||||
* `ClassFinder::debugRenderReport('TestApp1\Foo\Baz')`
|
||||
Guidance for solving "class not found" errors resulting from typos in namespaces, missing directories, etc. Would print
|
||||
an HTML report. Not intended for production use, but debugging.
|
||||
|
||||
1.0.0 - Better compliance with semantic versioning.
|
@ -1,3 +1,21 @@
|
||||
Version 0.2.0
|
||||
-------------
|
||||
|
||||
* Added support for finding classes declared via `classmap`.
|
||||
* Exceptions will no longer be thrown when PSR4 can't find a registered namespace (because it could be a valid class
|
||||
declared in a `classmap`)
|
||||
|
||||
Example composer.json that is now supported:
|
||||
```
|
||||
...
|
||||
"autoload": {
|
||||
...
|
||||
"classmap": [ "src/foo/", "src/bar/" ]
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
Version 0.1.2
|
||||
-------------
|
||||
|
||||
|
37
docs/exceptions/unknownNamespace.md
Normal file
37
docs/exceptions/unknownNamespace.md
Normal file
@ -0,0 +1,37 @@
|
||||
Unknown Namespace
|
||||
-----------------
|
||||
|
||||
Example PHP:
|
||||
```
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use HaydenPierce\ClassFinder\ClassFinder;
|
||||
|
||||
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||
```
|
||||
|
||||
Example `composer.json`:
|
||||
```
|
||||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Acme\\": "src/",
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Results in this exception:
|
||||
|
||||
> Unknown namespace 'Acme\Foo\Bar'
|
||||
|
||||
This exception occurs when the provided namespace isn't declared or isn't accessible based on items are _are_ declared
|
||||
in `composer.json`. In the given example, `Acme` is declared to map to `src/` in `composer.json`, so PSR4 would mandate
|
||||
that `src/Foo/Bar` is a valid path for a directory. However, that directory could not be located, and therefore the
|
||||
provided namespace is unknown.
|
||||
|
||||
If you discover that this exception is raised and Composer _can_ autoload classes found in the namespace, please submit
|
||||
an issue.
|
@ -1,51 +0,0 @@
|
||||
Unknown Child Namespace
|
||||
-----------------------
|
||||
|
||||
Example composer.json:
|
||||
```
|
||||
{
|
||||
"name": "haydenpierce/sample-app",
|
||||
"type": "application",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Hayden Pierce",
|
||||
"email": "hayden@haydenpierce.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Acme\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Example PHP:
|
||||
```
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use HaydenPierce\ClassFinder\ClassFinder;
|
||||
|
||||
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||
```
|
||||
|
||||
Results in this exception:
|
||||
|
||||
> Unknown namespace 'TestApp1\Foo\Bar'. Checked for files in *C:\Users\HPierce\PhpstormProjects\ClassFinder\test\app1\src\Foo\Bar*, but that directory did not exist
|
||||
|
||||
ClassFinder attempts to figure out which directory it should look for classes in by piecing together a path from
|
||||
elements in your `autoload.psr-4` configuration. In this instance, we've asked for classes in the `Acme\Foo\Bar` namespace,
|
||||
so ClassFinder will attempt to build a directory path there. ClassFinder successfully mapped *Acme* to `src/`, but upon adding
|
||||
the rest of the namespace to the path, failed to find a directory.
|
||||
|
||||
Things to check for:
|
||||
|
||||
* Does the directory actually exist?
|
||||
* Does PHP have permissions to the directory?
|
||||
* Is your app PSR-4 compliant?
|
||||
* Is the namespace correct?
|
||||
|
||||
If this information doesn't resolve the issue, please feel free to submit an issue.
|
@ -1,62 +0,0 @@
|
||||
Unknown Namespace Root
|
||||
----------------------
|
||||
|
||||
Example composer.json:
|
||||
```
|
||||
{
|
||||
"name": "haydenpierce/sample-app",
|
||||
"type": "application",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Hayden Pierce",
|
||||
"email": "hayden@haydenpierce.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"HaydenPierce\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Example PHP:
|
||||
```
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use HaydenPierce\ClassFinder\ClassFinder;
|
||||
|
||||
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||
```
|
||||
|
||||
Results in this exception:
|
||||
|
||||
> Unknown namespace 'DoesNotExist\Foo\Bar'. You should add the namespace prefix to composer.json.
|
||||
|
||||
ClassFinder attempts to figure out which directory it should look for classes in by piecing together a path from
|
||||
elements in your `autoload.psr-4` configuration. In this instance, we've asked for classes in the `Acme\Foo\Bar` namespace,
|
||||
so ClassFinder will attempt to build a directory path there. Since none of `Acme`, `Acme\Foo`, or `Acme\Foo\Bar` exist
|
||||
in the `autoload.psr-4`, ClassFinder cannot determine a valid path.
|
||||
|
||||
This can be solved by adding `Acme` to the `autoload.psr-4` key like so:
|
||||
|
||||
```
|
||||
{
|
||||
...
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"HaydenPierce\\": "src/",
|
||||
"Acme\\" : "src/acme"
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
This will allow ClassFinder to search `src/acme/Foo/Bar/*` for classes in the `Acme\Foo\Bar` namespace. You could also add
|
||||
`Acme\Foo` to the `autoload.psr-4` config if that makes more sense.
|
||||
|
||||
If this information doesn't resolve the issue, please feel free to submit an issue.
|
@ -48,7 +48,7 @@ class ClassFinder
|
||||
if (!$isNamespaceKnown) {
|
||||
throw new ClassFinderException(sprintf("Unknown namespace '%s'. See '%s' for details.",
|
||||
$namespace,
|
||||
'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/unregisteredRoot.md'
|
||||
'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/unknownNamespace.md'
|
||||
));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user