From 631e09d80224ecdd60e2cc96439dfda6de2dbc4e Mon Sep 17 00:00:00 2001 From: Hayden Pierce Date: Sun, 21 Oct 2018 09:39:21 -0500 Subject: [PATCH] Provide a more helpful error message if files support fails due to exec() being disabled. --- docs/exceptions/filesExecNotAvailable.md | 51 ++++++++++++++++++++++++ src/Files/FilesFinder.php | 13 ++++++ 2 files changed, 64 insertions(+) create mode 100644 docs/exceptions/filesExecNotAvailable.md 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)