Browse Source

added more information about a resource in error and debug messages

Fabien Potencier 14 years ago
parent
commit
2e1747bf76

+ 1 - 1
src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

@@ -94,7 +94,7 @@ class LoggerDataCollector extends DataCollector
         }
 
         if (is_resource($context)) {
-            return 'Resource';
+            return sprintf('Resource(%s)', get_resource_type($context));
         }
 
         if (is_object($context)) {

+ 16 - 4
src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php

@@ -68,7 +68,7 @@ class FilterControllerEvent extends KernelEvent
     private function varToString($var)
     {
         if (is_object($var)) {
-            return sprintf('[object](%s)', get_class($var));
+            return sprintf('Object(%s)', get_class($var));
         }
 
         if (is_array($var)) {
@@ -77,13 +77,25 @@ class FilterControllerEvent extends KernelEvent
                 $a[] = sprintf('%s => %s', $k, $this->varToString($v));
             }
 
-            return sprintf("[array](%s)", implode(', ', $a));
+            return sprintf("Array(%s)", implode(', ', $a));
         }
 
         if (is_resource($var)) {
-            return '[resource]';
+            return sprintf('Resource(%s)', get_resource_type($var));
         }
 
-        return str_replace("\n", '', var_export((string) $var, true));
+        if (null === $var) {
+            return 'null';
+        }
+
+        if (false === $var) {
+            return 'false';
+        }
+
+        if (true === $var) {
+            return 'true';
+        }
+
+        return (string) $var;
     }
 }

+ 1 - 1
src/Symfony/Component/HttpKernel/Exception/FlattenException.php

@@ -182,7 +182,7 @@ class FlattenException
             } elseif (is_bool($value)) {
                 $result[$key] = array('boolean', $value);
             } elseif (is_resource($value)) {
-                $result[$key] = array('resource', '');
+                $result[$key] = array('resource', get_resource_type($value));
             } else {
                 $result[$key] = array('string', (string) $value);
             }

+ 1 - 1
src/Symfony/Component/Yaml/Inline.php

@@ -73,7 +73,7 @@ class Inline
     {
         switch (true) {
             case is_resource($value):
-                throw new DumpException('Unable to dump PHP resources in a YAML file.');
+                throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
             case is_object($value):
                 return '!!php/object:'.serialize($value);
             case is_array($value):

+ 1 - 1
tests/Symfony/Tests/Component/HttpKernel/DataCollector/LoggerDataCollectorTest.php

@@ -46,7 +46,7 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
             array(
                 1,
                 array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')))),
-                array(array('message' => 'foo', 'context' => array('foo' => 'Resource'))),
+                array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'))),
             ),
             array(
                 1,