mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Catch non-existant class fatal exceptions
Add autoloader that throws an error, so we can catch errors instead of fatal crashes. Fixes #220
This commit is contained in:
+14
-12
@@ -68,6 +68,8 @@ class MetaCommand extends Command {
|
|||||||
*/
|
*/
|
||||||
public function fire()
|
public function fire()
|
||||||
{
|
{
|
||||||
|
$this->registerClassAutoloadExceptions();
|
||||||
|
|
||||||
$bindings = array();
|
$bindings = array();
|
||||||
foreach ($this->getAbstracts() as $abstract) {
|
foreach ($this->getAbstracts() as $abstract) {
|
||||||
try {
|
try {
|
||||||
@@ -76,7 +78,7 @@ class MetaCommand extends Command {
|
|||||||
$bindings[$abstract] = get_class($concrete);
|
$bindings[$abstract] = get_class($concrete);
|
||||||
}
|
}
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
$this->error("Cannot make $abstract: ".$e->getMessage());
|
$this->comment("Cannot make '$abstract': ".$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +98,7 @@ class MetaCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a filtered list of abstracts from the Laravel Application.
|
* Get a list of abstracts from the Laravel Application.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -104,20 +106,20 @@ class MetaCommand extends Command {
|
|||||||
{
|
{
|
||||||
$abstracts = $this->laravel->getBindings();
|
$abstracts = $this->laravel->getBindings();
|
||||||
|
|
||||||
// Remove the S3 cloud driver when not available
|
|
||||||
if (config('filesystems.cloud') === 's3' && !class_exists('League\Flysystem\AwsS3v2\AwsS3Adapter')) {
|
|
||||||
unset($abstracts['filesystem.cloud']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove Redis when not available
|
|
||||||
if (isset($abstracts['redis']) && !class_exists('Predis\Client')) {
|
|
||||||
unset($abstracts['redis']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the abstract names only
|
// Return the abstract names only
|
||||||
return array_keys($abstracts);
|
return array_keys($abstracts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an autoloader the throws exceptions when a class is not found.
|
||||||
|
*/
|
||||||
|
protected function registerClassAutoloadExceptions()
|
||||||
|
{
|
||||||
|
spl_autoload_register(function ($class) {
|
||||||
|
throw new \Exception("Class '$class' not found.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the console command options.
|
* Get the console command options.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user