Skip to content

Commit

Permalink
[HttpKernel] Added a bit to convert incomplete objects in the error m…
Browse files Browse the repository at this point in the history
…essage
  • Loading branch information
rrehbein authored and fabpot committed Sep 28, 2012
1 parent bf41d8b commit ef18e00
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpKernel/Exception/FlattenException.php
Expand Up @@ -221,11 +221,21 @@ private function flattenArgs($args, $level = 0)
$result[$key] = array('boolean', $value);
} elseif (is_resource($value)) {
$result[$key] = array('resource', get_resource_type($value));
} elseif ($value instanceof \__PHP_Incomplete_Class) {
// Special case of object, is_object will return false
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
} else {
$result[$key] = array('string', (string) $value);
}
}

return $result;
}

private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
{
$array = new \ArrayObject($value);

return $array['__PHP_Incomplete_Class_Name'];
}
}
Expand Up @@ -101,7 +101,7 @@ public function testToArray(\Exception $exception, $statusCode)
'args' => array()
)),
)
),$flattened->toArray());
), $flattened->toArray());
}

public function flattenDataProvider()
Expand All @@ -125,4 +125,45 @@ private function createException($foo)
{
return new \Exception();
}

public function testSetTraceIncompleteClass()
{
$flattened = FlattenException::create(new \Exception('test', 123));
$flattened->setTrace(
array(
array(
'file' => __FILE__,
'line' => 123,
'function' => 'test',
'args' => array(
unserialize('O:14:"BogusTestClass":0:{}')
),
),
),
'foo.php', 123
);

$this->assertEquals(array(
array(
'message'=> 'test',
'class'=>'Exception',
'trace'=>array(
array(
'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => '',
'file' => 'foo.php', 'line' => 123,
'args' => array(),
),
array(
'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => 'test',
'file' => __FILE__, 'line' => 123,
'args' => array(
array(
'incomplete-object', 'BogusTestClass'
),
),
)
),
)
), $flattened->toArray());
}
}

0 comments on commit ef18e00

Please sign in to comment.