1
0
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:
Hayden Pierce 2018-08-04 20:06:24 -05:00
parent f7d3eeac21
commit 3df6a82623
3 changed files with 38 additions and 1 deletions

View File

@ -58,3 +58,4 @@ Documentation
* [Unknown namespace - (Unregistered)](docs/exceptions/unregisteredRoot.md)
* [Unknown namespace - (Registered)](docs/exceptions/unknownSubNamespace.md)
* [Missing composer.json](docs/exceptions/missingComposerConfig.md)

View 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.

View File

@ -30,7 +30,7 @@ class ClassFinder
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.",
'https://gitlab.com/hpierce1102/ClassFinder' // TODO: write documentation and update this link.
'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/missingComposerConfig.md'
));
} else {
self::$appRoot = $appRoot;