From 208ca5f8aa60451986acf8c6e9ecca4b9ccf574d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 24 Jul 2013 05:31:30 +0200 Subject: [PATCH] [Debug] made guessing of possible class names more flexible --- src/Symfony/Component/Debug/ErrorHandler.php | 21 ++++++++++++------- .../Debug/Tests/ErrorHandlerTest.php | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index ed4dc67c32..9a6f13c788 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -43,11 +43,6 @@ class ErrorHandler E_PARSE => 'Parse', ); - private $classNameToUseStatementSuggestions = array( - 'Request' => 'Symfony\Component\HttpFoundation\Request', - 'Response' => 'Symfony\Component\HttpFoundation\Response', - ); - private $level; private $reservedMemory; @@ -293,11 +288,23 @@ class ErrorHandler ); } - if (isset($this->classNameToUseStatementSuggestions[$className])) { - $message .= sprintf(' Perhaps you need to add "use %s" at the top of this file?', $this->classNameToUseStatementSuggestions[$className]); + if ($classes = $this->getUseStatementSuggestions($className)) { + $message .= sprintf(' Perhaps you need to add a use statement for one of the following class: %s.', implode(', ', $classes)); } return new ClassNotFoundException($message, $exception); } } + + protected function getUseStatementSuggestions($class) + { + $classNameToUseStatementSuggestions = array( + 'Request' => array('Symfony\Component\HttpFoundation\Request'), + 'Response' => array('Symfony\Component\HttpFoundation\Response'), + ); + + if (isset($classNameToUseStatementSuggestions[$class])) { + return $classNameToUseStatementSuggestions[$class]; + } + } } diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 9868d7e7ef..e2cada866c 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -121,7 +121,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class "Request" not found', ), - 'Attempted to load class "Request" from the global namespace in foo.php line 12. Did you forget a use statement for this class? Perhaps you need to add "use Symfony\\Component\\HttpFoundation\\Request" at the top of this file?', + 'Attempted to load class "Request" from the global namespace in foo.php line 12. Did you forget a use statement for this class? Perhaps you need to add a use statement for one of the following class: Symfony\Component\HttpFoundation\Request.', ), array( array( @@ -130,7 +130,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase 'file' => 'foo.php', 'message' => 'Class "Foo\\Bar\\Request" not found', ), - 'Attempted to load class "Request" from namespace "Foo\\Bar" in foo.php line 12. Do you need to "use" it from another namespace? Perhaps you need to add "use Symfony\\Component\\HttpFoundation\\Request" at the top of this file?', + 'Attempted to load class "Request" from namespace "Foo\Bar" in foo.php line 12. Do you need to "use" it from another namespace? Perhaps you need to add a use statement for one of the following class: Symfony\Component\HttpFoundation\Request.', ), ); }