Skip to content

Commit

Permalink
Add useful exception when hook class is invalid/missing (see #1949)
Browse files Browse the repository at this point in the history
Description
-----------

If an invalid class is imported, we'd always get `Warning: in_array() expects parameter 2 to be array, null given` because `get_class_methods()` returns null instead of an array.

Commits
-------

1cf46e6 Add useful exception when hook class is invalid/missing
d5bc83c CS
  • Loading branch information
aschempp committed Jul 21, 2020
1 parent c596c9b commit ba9ea6c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core-bundle/src/Resources/contao/library/Contao/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ protected function import($strClass, $strKey=null, $blnForce=false)
{
$this->arrObjects[$strKey] = $container->get($strClass);
}
elseif (!class_exists($strClass))
{
throw new \RuntimeException('System::import() failed because class "' . $strClass . '" is not a valid class name or does not exist.');
}
elseif (\in_array('getInstance', get_class_methods($strClass)))
{
$this->arrObjects[$strKey] = \call_user_func(array($strClass, 'getInstance'));
Expand Down Expand Up @@ -202,6 +206,10 @@ public static function importStatic($strClass, $strKey=null, $blnForce=false)
{
static::$arrStaticObjects[$strKey] = $container->get($strClass);
}
elseif (!class_exists($strClass))
{
throw new \RuntimeException('System::importStatic() failed because class "' . $strClass . '" is not a valid class name or does not exist.');
}
elseif (\in_array('getInstance', get_class_methods($strClass)))
{
static::$arrStaticObjects[$strKey] = \call_user_func(array($strClass, 'getInstance'));
Expand Down

0 comments on commit ba9ea6c

Please sign in to comment.