minor #20169 Minor fixes & cleanups (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
Minor fixes & cleanups
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
dcf601f
Minor fixes & cleanups
This commit is contained in:
commit
962248dbd9
@ -216,10 +216,10 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testSetComplexCallback()
|
public function testSetComplexCallback()
|
||||||
{
|
{
|
||||||
$response = JsonResponse::fromJsonString('{foo: "bar"}');
|
$response = JsonResponse::create(array('foo' => 'bar'));
|
||||||
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
|
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
|
||||||
|
|
||||||
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({foo: "bar"});', $response->getContent());
|
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,8 @@ class ReflectionCaster
|
|||||||
|
|
||||||
if (isset($a[$prefix.'returnType'])) {
|
if (isset($a[$prefix.'returnType'])) {
|
||||||
$v = $a[$prefix.'returnType'];
|
$v = $a[$prefix.'returnType'];
|
||||||
$a[$prefix.'returnType'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
$v = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||||
|
$a[$prefix.'returnType'] = $a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v;
|
||||||
}
|
}
|
||||||
if (isset($a[$prefix.'this'])) {
|
if (isset($a[$prefix.'this'])) {
|
||||||
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
|
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
|
||||||
@ -168,21 +169,12 @@ class ReflectionCaster
|
|||||||
'allowsNull' => 'allowsNull',
|
'allowsNull' => 'allowsNull',
|
||||||
));
|
));
|
||||||
|
|
||||||
try {
|
|
||||||
if (method_exists($c, 'getType')) {
|
if (method_exists($c, 'getType')) {
|
||||||
if ($v = $c->getType()) {
|
if ($v = $c->getType()) {
|
||||||
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||||
}
|
}
|
||||||
} else {
|
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $c, $v)) {
|
||||||
$v = explode(' ', $c->__toString(), 6);
|
$a[$prefix.'typeHint'] = $v[1];
|
||||||
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
|
|
||||||
$a[$prefix.'typeHint'] = $v[4];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (\ReflectionException $e) {
|
|
||||||
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
|
|
||||||
$a[$prefix.'typeHint'] = $m[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!isset($a[$prefix.'typeHint'])) {
|
if (!isset($a[$prefix.'typeHint'])) {
|
||||||
unset($a[$prefix.'allowsNull']);
|
unset($a[$prefix.'allowsNull']);
|
||||||
|
Reference in New Issue
Block a user