diff --git a/docs/exceptions/filesExecNotAvailable.md b/docs/exceptions/filesExecNotAvailable.md new file mode 100644 index 0000000..addcfe2 --- /dev/null +++ b/docs/exceptions/filesExecNotAvailable.md @@ -0,0 +1,51 @@ +FilesFinder requires that exec() is available. +---------------------------------------------- + +Example PHP: +``` + 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. + + diff --git a/src/Files/FilesFinder.php b/src/Files/FilesFinder.php index 5f01e90..117808a 100644 --- a/src/Files/FilesFinder.php +++ b/src/Files/FilesFinder.php @@ -1,15 +1,28 @@ 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)