Skip to content

Commit 86a080a

Browse files
author
Fabian Lange
committed
Merge branch 'symfony'
2 parents 92a8708 + 573f95a commit 86a080a

File tree

95 files changed

+2051
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2051
-475
lines changed

src/Symfony/Components/Console/Application.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ public function getHelp()
249249
$this->getLongVersion(),
250250
'',
251251
'<comment>Usage:</comment>',
252-
sprintf(" %s [options] command [arguments]\n", $this->getName()),
252+
sprintf(" [options] command [arguments]\n"),
253253
'<comment>Options:</comment>',
254254
);
255255

256256
foreach ($this->definition->getOptions() as $option)
257257
{
258-
$messages[] = sprintf(' %-24s %s %s',
258+
$messages[] = sprintf(' %-29s %s %s',
259259
'<info>--'.$option->getName().'</info>',
260260
$option->getShortcut() ? '<info>-'.$option->getShortcut().'</info>' : ' ',
261261
$option->getDescription()

src/Symfony/Components/Console/Command/Command.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public function getAliases()
406406
*/
407407
public function getSynopsis()
408408
{
409-
return sprintf('%%s %s %s', $this->getFullName(), $this->definition->getSynopsis());
409+
return sprintf('%s %s', $this->getFullName(), $this->definition->getSynopsis());
410410
}
411411

412412
/**
@@ -423,6 +423,20 @@ protected function getHelper($name)
423423
return $this->application->getHelperSet()->get($name);
424424
}
425425

426+
/**
427+
* Gets a helper instance by name.
428+
*
429+
* @param string $name The helper name
430+
*
431+
* @return mixed The helper value
432+
*
433+
* @throws \InvalidArgumentException if the helper is not defined
434+
*/
435+
public function __get($name)
436+
{
437+
return $this->application->getHelperSet()->get($name);
438+
}
439+
426440
/**
427441
* Returns a text representation of the command.
428442
*
@@ -432,7 +446,7 @@ public function asText()
432446
{
433447
$messages = array(
434448
'<comment>Usage:</comment>',
435-
sprintf(' '.$this->getSynopsis(), null === $this->application ? '' : $this->application->getName()),
449+
' '.$this->getSynopsis(),
436450
'',
437451
);
438452

src/Symfony/Components/Console/Input/Input.php

+24
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public function setArgument($name, $value)
129129
$this->arguments[$name] = $value;
130130
}
131131

132+
/**
133+
* Returns true if an InputArgument object exists by name or position.
134+
*
135+
* @param string|integer $name The InputArgument name or position
136+
*
137+
* @return Boolean true if the InputArgument object exists, false otherwise
138+
*/
139+
public function hasArgument($name)
140+
{
141+
return $this->definition->hasArgument($name);
142+
}
143+
132144
/**
133145
* Returns the options values.
134146
*
@@ -171,4 +183,16 @@ public function setOption($name, $value)
171183

172184
$this->options[$name] = $value;
173185
}
186+
187+
/**
188+
* Returns true if an InputOption object exists by name.
189+
*
190+
* @param string $name The InputOption name
191+
*
192+
* @return Boolean true if the InputOption object exists, false otherwise
193+
*/
194+
public function hasOption($name)
195+
{
196+
return $this->definition->hasOption($name);
197+
}
174198
}

src/Symfony/Components/DependencyInjection/Builder.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,7 @@ public function getService($id, $invalidBehavior = Container::EXCEPTION_ON_INVAL
9797

9898
$this->loading[$id] = true;
9999

100-
if ($definition->isShared())
101-
{
102-
$service = $this->services[$id] = $this->createService($definition);
103-
}
104-
else
105-
{
106-
$service = $this->createService($definition);
107-
}
100+
$service = $this->createService($definition, $id);
108101

109102
unset($this->loading[$id]);
110103

@@ -339,10 +332,11 @@ public function getDefinition($id)
339332
* Creates a service for a service definition.
340333
*
341334
* @param Definition $definition A service definition instance
335+
* @param string $id The service identifier
342336
*
343337
* @return object The service described by the service definition
344338
*/
345-
protected function createService(Definition $definition)
339+
protected function createService(Definition $definition, $id)
346340
{
347341
if (null !== $definition->getFile())
348342
{
@@ -362,6 +356,11 @@ protected function createService(Definition $definition)
362356
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
363357
}
364358

359+
if ($definition->isShared())
360+
{
361+
$this->services[$id] = $service;
362+
}
363+
365364
foreach ($definition->getMethodCalls() as $call)
366365
{
367366
$services = self::getServiceConditionals($call[1]);

src/Symfony/Components/DependencyInjection/Dumper/PhpDumper.php

+14-22
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,12 @@ protected function addServiceShared($id, $definition)
7676

7777
protected function addServiceReturn($id, $definition)
7878
{
79-
if ($definition->isShared())
80-
{
81-
return <<<EOF
82-
83-
return \$this->shared['$id'] = \$instance;
84-
}
85-
86-
EOF;
87-
}
88-
else
89-
{
90-
return <<<EOF
79+
return <<<EOF
9180
9281
return \$instance;
9382
}
9483
9584
EOF;
96-
}
9785
}
9886

9987
protected function addServiceInstance($id, $definition)
@@ -108,19 +96,23 @@ protected function addServiceInstance($id, $definition)
10896

10997
if (null !== $definition->getConstructor())
11098
{
111-
return sprintf(" \$instance = call_user_func(array(%s, '%s')%s);\n", $class, $definition->getConstructor(), $arguments ? ', '.implode(', ', $arguments) : '');
99+
$code = sprintf(" \$instance = call_user_func(array(%s, '%s')%s);\n", $class, $definition->getConstructor(), $arguments ? ', '.implode(', ', $arguments) : '');
100+
}
101+
elseif ($class != "'".str_replace('\\', '\\\\', $definition->getClass())."'")
102+
{
103+
$code = sprintf(" \$class = %s;\n \$instance = new \$class(%s);\n", $class, implode(', ', $arguments));
112104
}
113105
else
114106
{
115-
if ($class != "'".str_replace('\\', '\\\\', $definition->getClass())."'")
116-
{
117-
return sprintf(" \$class = %s;\n \$instance = new \$class(%s);\n", $class, implode(', ', $arguments));
118-
}
119-
else
120-
{
121-
return sprintf(" \$instance = new %s(%s);\n", $definition->getClass(), implode(', ', $arguments));
122-
}
107+
$code = sprintf(" \$instance = new %s(%s);\n", $definition->getClass(), implode(', ', $arguments));
123108
}
109+
110+
if ($definition->isShared())
111+
{
112+
$code .= sprintf(" \$this->shared['$id'] = \$instance;\n");
113+
}
114+
115+
return $code;
124116
}
125117

126118
protected function addServiceMethodCalls($id, $definition)

src/Symfony/Components/DependencyInjection/SimpleXMLElement.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,24 @@ public function getArgumentsAsPhp($name)
6565
static public function phpize($value)
6666
{
6767
$value = (string) $value;
68+
$lowercaseValue = strtolower($value);
6869

6970
switch (true)
7071
{
71-
case 'null' == strtolower($value):
72+
case 'null' === $lowercaseValue:
7273
return null;
7374
case ctype_digit($value):
7475
return '0' == $value[0] ? octdec($value) : intval($value);
75-
case 'true' === strtolower($value):
76+
case 'true' === $lowercaseValue:
7677
return true;
77-
case 'false' === strtolower($value):
78+
case 'false' === $lowercaseValue:
7879
return false;
7980
case is_numeric($value):
8081
return '0x' == $value[0].$value[1] ? hexdec($value) : floatval($value);
8182
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $value):
8283
return floatval(str_replace(',', '', $value));
8384
default:
84-
return (string) $value;
85+
return $value;
8586
}
8687
}
8788
}

src/Symfony/Components/OutputEscaper/Escaper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static public function escape($escaper, $value)
133133
// return the unescaped object
134134
return $value;
135135
}
136-
elseif ($value instanceof Safe)
136+
elseif ($value instanceof SafeDecorator)
137137
{
138138
// do not escape objects marked as safe
139139
// return the original object

src/Symfony/Components/OutputEscaper/Safe.php src/Symfony/Components/OutputEscaper/SafeDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @subpackage output_escaper
1919
* @author Fabien Potencier <[email protected]>
2020
*/
21-
class Safe extends \ArrayIterator
21+
class SafeDecorator extends \ArrayIterator
2222
{
2323
protected $value;
2424

src/Symfony/Components/RequestHandler/Request.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Request implements RequestInterface
2828
protected $pathParameters;
2929
protected $requestParameters;
3030
protected $queryParameters;
31-
protected $serverParameter;
31+
protected $serverParameters;
3232
protected $languages;
3333
protected $charsets;
3434
protected $acceptableContentTypes;

src/Symfony/Components/Routing/Generator/Dumper/PhpGeneratorDumper.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ protected function addGenerator()
5959

6060
$variables = str_replace("\n", '', var_export($compiledRoute->getVariables(), true));
6161
$defaults = str_replace("\n", '', var_export($route->getDefaults(), true));
62+
$requirements = str_replace("\n", '', var_export($compiledRoute->getRequirements(), true));
6263
$tokens = str_replace("\n", '', var_export($compiledRoute->getTokens(), true));
6364

6465
$methods[] = <<<EOF
6566
protected function get{$name}RouteInfo()
6667
{
67-
return array($variables, array_merge(\$this->defaults, $defaults), $tokens);
68+
return array($variables, array_merge(\$this->defaults, $defaults), $requirements, $tokens);
6869
}
6970
7071
EOF
@@ -82,9 +83,9 @@ public function generate(\$name, array \$parameters, \$absolute = false)
8283
throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', \$name));
8384
}
8485
85-
list(\$variables, \$defaults, \$tokens) = \$this->\$method();
86+
list(\$variables, \$defaults, \$requirements, \$tokens) = \$this->\$method();
8687
87-
return \$this->doGenerate(\$variables, \$defaults, \$tokens, \$parameters, \$name, \$absolute);
88+
return \$this->doGenerate(\$variables, \$defaults, \$requirements, \$tokens, \$parameters, \$name, \$absolute);
8889
}
8990
9091
$methods

src/Symfony/Components/Routing/Generator/UrlGenerator.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class UrlGenerator implements UrlGeneratorInterface
3838
public function __construct(RouteCollection $routes, array $context = array(), array $defaults = array())
3939
{
4040
$this->routes = $routes;
41-
$this->context = array_merge(array('base_url', ''), $context);
41+
$this->context = array_merge(array('base_url' => ''), $context);
4242
$this->defaults = $defaults;
4343
$this->cache = array();
4444
}
@@ -64,10 +64,10 @@ public function generate($name, array $parameters, $absolute = false)
6464
$this->cache[$name] = $route->compile();
6565
}
6666

67-
return $this->doGenerate($this->cache[$name]->getVariables(), $route->getDefaults(), $this->cache[$name]->getTokens(), $parameters, $name, $absolute);
67+
return $this->doGenerate($this->cache[$name]->getVariables(), $route->getDefaults(), $route->getRequirements(), $this->cache[$name]->getTokens(), $parameters, $name, $absolute);
6868
}
6969

70-
protected function doGenerate($variables, $defaults, $tokens, $parameters, $name, $absolute)
70+
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute)
7171
{
7272
$defaults = array_merge($this->defaults, $defaults);
7373
$tparams = array_merge($defaults, $parameters);
@@ -86,6 +86,12 @@ protected function doGenerate($variables, $defaults, $tokens, $parameters, $name
8686
{
8787
if (false === $optional || !isset($defaults[$token[3]]) || (isset($parameters[$token[3]]) && $parameters[$token[3]] != $defaults[$token[3]]))
8888
{
89+
// check requirement
90+
if (isset($requirements[$token[3]]) && !preg_match('#^'.$requirements[$token[3]].'$#', $tparams[$token[3]]))
91+
{
92+
throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $requirements[$token[3]], $tparams[$token[3]]));
93+
}
94+
8995
$url = $token[1].urlencode($tparams[$token[3]]).$url;
9096
$optional = false;
9197
}

src/Symfony/Components/Routing/Matcher/UrlMatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function match($url)
5959
$compiledRoute = $route->compile();
6060

6161
// check HTTP method requirement
62-
if (!isset($this->context['method']) || (($req = $route->getRequirement('_method')) && !in_array(strtolower($this->context['method']), array_map('strtolower', (array) $req))))
62+
if (isset($this->context['method']) && (($req = $route->getRequirement('_method')) && !in_array(strtolower($this->context['method']), array_map('strtolower', (array) $req))))
6363
{
6464
continue;
6565
}

src/Symfony/Components/Yaml/Inline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static public function dump($value)
8080
return is_infinite($value) ? str_ireplace('INF', '.Inf', strval($value)) : (is_string($value) ? "'$value'" : $value);
8181
case false !== strpos($value, "\n") || false !== strpos($value, "\r"):
8282
return sprintf('"%s"', str_replace(array('"', "\n", "\r"), array('\\"', '\n', '\r'), $value));
83-
case preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \#] | \A[ - ? | < > = ! % @ ]/x', $value):
83+
case preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ - ? | < > = ! % @ ` ]/x', $value):
8484
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
8585
case '' == $value:
8686
return "''";

src/Symfony/Components/Yaml/Parser.php

+30-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function parse($value)
6565
}
6666

6767
$isRef = $isInPlace = $isProcessed = false;
68-
if (preg_match('#^\-(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
68+
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#', $this->currentLine, $values))
6969
{
7070
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#', $values['value'], $matches))
7171
{
@@ -87,13 +87,30 @@ public function parse($value)
8787
{
8888
$data[] = array($matches[1] => Inline::load($matches[2]));
8989
}
90+
elseif (isset($values['leadspaces'])
91+
&& ' ' == $values['leadspaces']
92+
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
93+
{
94+
// this is a compact notation element, add to next block and parse
95+
$c = $this->getRealCurrentLineNb();
96+
$parser = new Parser($c);
97+
$parser->refs =& $this->refs;
98+
99+
$block = $values['value'];
100+
if (!$this->isNextLineIndented())
101+
{
102+
$block .= "\n".$this->getNextEmbedBlock();
103+
}
104+
105+
$data[] = $parser->parse($block);
106+
}
90107
else
91108
{
92109
$data[] = $this->parseValue($values['value']);
93110
}
94111
}
95112
}
96-
else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ ].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
113+
else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values))
97114
{
98115
$key = Inline::parseScalar($values['key']);
99116

@@ -544,10 +561,18 @@ protected function cleanup($value)
544561
$value = rtrim($value, "\n");
545562

546563
// strip YAML header
547-
preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value);
564+
$count = 0;
565+
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value, -1, $count);
566+
$this->offset += $count;
548567

549-
// remove ---
550-
$value = preg_replace('#^\-\-\-.*?\n#s', '', $value);
568+
// remove leading comments and/or ---
569+
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\n))*#s', '', $value, -1, $count);
570+
if ($count == 1)
571+
{
572+
// items have been removed, update the offset
573+
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
574+
$value = $trimmedValue;
575+
}
551576

552577
return $value;
553578
}

0 commit comments

Comments
 (0)