mirror of
https://github.com/danog/class-finder.git
synced 2024-11-26 20:14:59 +01:00
Provide a more helpful error message if files support fails due to exec() being disabled.
This commit is contained in:
parent
6af0937964
commit
631e09d802
51
docs/exceptions/filesExecNotAvailable.md
Normal file
51
docs/exceptions/filesExecNotAvailable.md
Normal file
@ -0,0 +1,51 @@
|
||||
FilesFinder requires that exec() is available.
|
||||
----------------------------------------------
|
||||
|
||||
Example PHP:
|
||||
```
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use HaydenPierce\ClassFinder\ClassFinder;
|
||||
|
||||
ClassFinder::enableFilesSupport();
|
||||
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||
```
|
||||
|
||||
Results in this exception:
|
||||
|
||||
> FilesFinder requires that exec() is available. Check your php.ini to see if it is disabled.
|
||||
|
||||
When running ClassFinder with support for autoloaded classes in `files`, ClassFinder must execute the included file in a
|
||||
shell to determine any defined classes in it. `exec()` is used to accomplish this. In some environments, hosts may
|
||||
intentionally disable the use `exec()` as a security or performance precaution.
|
||||
|
||||
Possible Solution 1
|
||||
-------------------
|
||||
|
||||
Disable `files` support.
|
||||
|
||||
The majority of users won't need `files` support. If you've copy / pasted a snippet (including from documentation here)
|
||||
that enabled it, you should remove it and see if you're part of the 99% that doesn't need this feature. You may also
|
||||
want to explicitly disable it:
|
||||
|
||||
```
|
||||
ClassFinder::disableFilesSupport();
|
||||
$classes = ClassFinder::getClassesInNamespace('Acme\Foo\Bar');
|
||||
```
|
||||
|
||||
Possible Solution 2
|
||||
-------------------
|
||||
|
||||
Ensure `exec()` is available to PHP.
|
||||
|
||||
Find your `php.ini` file and look for a configuration value called `disabled_functions`:
|
||||
|
||||
```
|
||||
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
|
||||
```
|
||||
|
||||
Remove exec from the list and restart your webserver.
|
||||
|
||||
|
@ -1,15 +1,28 @@
|
||||
<?php
|
||||
namespace HaydenPierce\ClassFinder\Files;
|
||||
|
||||
use HaydenPierce\ClassFinder\Exception\ClassFinderException;
|
||||
use HaydenPierce\ClassFinder\FinderInterface;
|
||||
|
||||
class FilesFinder implements FinderInterface
|
||||
{
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* FilesFinder constructor.
|
||||
* @param FilesEntryFactory $factory
|
||||
* @throws ClassFinderException
|
||||
*/
|
||||
public function __construct(FilesEntryFactory $factory)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
|
||||
if (!function_exists('exec')) {
|
||||
throw new ClassFinderException(sprintf(
|
||||
'FilesFinder requires that exec() is available. Check your php.ini to see if it is disabled. See "%s" for details.',
|
||||
'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/filesExecNotAvailable.md'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function isNamespaceKnown($namespace)
|
||||
|
Loading…
Reference in New Issue
Block a user