mirror of
https://github.com/danog/class-finder.git
synced 2024-11-30 04:29:03 +01:00
Add more helpful link to error explanation - missing composer config
This commit is contained in:
parent
f7d3eeac21
commit
3df6a82623
@ -58,3 +58,4 @@ Documentation
|
|||||||
|
|
||||||
* [Unknown namespace - (Unregistered)](docs/exceptions/unregisteredRoot.md)
|
* [Unknown namespace - (Unregistered)](docs/exceptions/unregisteredRoot.md)
|
||||||
* [Unknown namespace - (Registered)](docs/exceptions/unknownSubNamespace.md)
|
* [Unknown namespace - (Registered)](docs/exceptions/unknownSubNamespace.md)
|
||||||
|
* [Missing composer.json](docs/exceptions/missingComposerConfig.md)
|
||||||
|
36
docs/exceptions/missingComposerConfig.md
Normal file
36
docs/exceptions/missingComposerConfig.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
Missing composer.json
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Example PHP:
|
||||||
|
```
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
use HaydenPierce\ClassFinder\ClassFinder;
|
||||||
|
|
||||||
|
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||||
|
```
|
||||||
|
|
||||||
|
Results in this exception:
|
||||||
|
|
||||||
|
> Could not locate composer.json. You can get around this by setting ClassFinder::$appRoot manually.
|
||||||
|
|
||||||
|
ClassFinder requires a composer.json to load autoloading settings. In this situation, ClassFinder wasn't able to
|
||||||
|
find it when recursively searching for it. You will need to tell ClassFinder where the root of your application is - this
|
||||||
|
is the directory that contains the composer.json configuration and where classes will be searched out of.
|
||||||
|
|
||||||
|
```
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
use HaydenPierce\ClassFinder\ClassFinder;
|
||||||
|
|
||||||
|
ClassFinder::$appRoot = realpath(__DIR__ . '../../app/'); // This is suggesting that the app root is really someone else.
|
||||||
|
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||||
|
```
|
||||||
|
|
||||||
|
This is an exotic situation and shouldn't apply to most projects.
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ class ClassFinder
|
|||||||
|
|
||||||
if (!file_exists($appRoot . '/composer.json')) {
|
if (!file_exists($appRoot . '/composer.json')) {
|
||||||
throw new ClassFinderException(sprintf("Could not locate composer.json. You can get around this by setting ClassFinder::\$appRoot manually. See '%s' for details.",
|
throw new ClassFinderException(sprintf("Could not locate composer.json. You can get around this by setting ClassFinder::\$appRoot manually. See '%s' for details.",
|
||||||
'https://gitlab.com/hpierce1102/ClassFinder' // TODO: write documentation and update this link.
|
'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/missingComposerConfig.md'
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
self::$appRoot = $appRoot;
|
self::$appRoot = $appRoot;
|
||||||
|
Loading…
Reference in New Issue
Block a user