8000 Merge branch '2.8' into 3.3 · symfony/symfony@87b3b1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 87b3b1a

Browse files
Merge branch '2.8' into 3.3
* 2.8: [travis] update to trusty Fix ArrayInput::toString() for VALUE_IS_ARRAY options/args [ExpressionLanguage] throws an exception on calling uncallable method
2 parents a4a87ac + c3f1470 commit 87b3b1a

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: php
22

3-
dist: precise
3+
dist: trusty
44
sudo: false
55

66
git:
@@ -20,10 +20,8 @@ env:
2020

2121
matrix:
2222
include:
23-
# Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
2423
- php: hhvm-3.18
2524
sudo: required
26-
dist: trusty
2725
group: edge
2826
- php: 5.5
2927
- php: 5.6
@@ -104,7 +102,6 @@ before_install:
104102
echo opcache.enable_cli = 1 >> $INI
105103
echo hhvm.jit = 0 >> $INI
106104
echo apc.enable_cli = 1 >> $INI
107-
echo extension = ldap.so >> $INI
108105
echo extension = redis.so >> $INI
109106
echo extension = memcached.so >> $INI
110107
[[ $PHP = 5.* ]] && echo extension = memcache.so >> $INI

src/Symfony/Component/Console/Input/ArrayInput.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ public function __toString()
112112
$params = array();
113113
foreach ($this->parameters as $param => $val) {
114114
if ($param && '-' === $param[0]) {
115-
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
115+
if (is_array($val)) {
116+
foreach ($val as $v) {
117+
$params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
118+
}
119+
} else {
120+
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
121+
}
116122
} else {
117-
$params[] = $this->escapeToken($val);
123+
$params[] = is_array($val) ? array_map(array($this, 'escapeToken'), $val) : $this->escapeToken($val);
118124
}
119125
}
120126

src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,8 @@ public function testToString()
167167
{
168168
$input = new ArrayInput(array('-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"));
169169
$this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
170+
171+
$input = new ArrayInput(array('-b' => array('bval_1', 'bval_2'), '--f' => array('fval_1', 'fval_2')));
172+
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
170173
}
171174
}

src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ public function evaluate($functions, $values)
8282
if (!is_object($obj)) {
8383
throw new \RuntimeException('Unable to get a property on a non-object.');
8484
}
85+
if (!is_callable($toCall = array($obj, $this->nodes['attribute']->attributes['value']))) {
86+
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], get_class($obj)));
87+
}
8588

86-
return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['value']), $this->nodes['arguments']->evaluate($functions, $values));
89+
return call_user_func_array($toCall, $this->nodes['arguments']->evaluate($functions, $values));
8790

8891
case self::ARRAY_CALL:
8992
$array = $this->nodes['node']->evaluate($functions, $values);

src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ public function testRegisterAfterEval($registerCallback)
242242
$registerCallback($el);
243243
}
244244

245+
/**
246+
* @expectedException \RuntimeException
247+
* @expectedExceptionMessageRegExp /Unable to call method "\w+" of object "\w+"./
248+
*/
249+
public function testCallBadCallable()
250+
{
251+
$el = new ExpressionLanguage();
252+
$el->evaluate('foo.myfunction()', array('foo' => new \stdClass()));
253+
}
254+
245255
/**
246256
* @dataProvider getRegisterCallbacks
247257
* @expectedException \LogicException

src/Symfony/Component/HttpFoundation/JsonResponse.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,17 @@ public function setData($data = array())
146146
$data = json_encode($data, $this->encodingOptions);
147147
} else {
148148
try {
149-
// PHP 5.4 and up wrap exceptions thrown by JsonSerializable
150-
// objects in a new exception that needs to be removed.
151-
// Fortunately, PHP 5.5 and up do not trigger any warning anymore.
152-
$data = json_encode($data, $this->encodingOptions);
149+
if (!interface_exists('JsonSerializable', false)) {
150+
set_error_handler(function () { return false; });
151+
$data = @json_encode($data, $this->encodingOptions);
152+
restore_error_handler();
153+
} else {
154+
$data = json_encode($data, $this->encodingOptions);
155+
}
153156
} catch (\Exception $e) {
154-
if ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
157+
if (!interface_exists('JsonSerializable', false)) {
158+
restore_error_handler();
159+
} elseif ('Exception' === get_class($e) && 0 === strpos($e->getMessage(), 'Failed calling ')) {
155160
throw $e->getPrevious() ?: $e;
156161
}
157162
throw $e;

src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ public function testSetContent()
228228
*/
229229
public function testSetContentJsonSerializeError()
230230
{
231+
if (!interface_exists('JsonSerializable', false)) {
232+
$this->markTestSkipped('JsonSerializable is required.');
233+
}
234+
231235
$serializable = new JsonSerializableObject();
232236

233237
JsonResponse::create($serializable);
@@ -242,7 +246,7 @@ public function testSetComplexCallback()
242246
}
243247
}
244248

245-
if (interface_exists('JsonSerializable')) {
249+
if (interface_exists('JsonSerializable', false)) {
246250
class JsonSerializableObject implements \JsonSerializable
247251
{
248252
public function jsonSerialize()

0 commit comments

Comments
 (0)
0