Author: fabien
Date: 2010-03-10 16:15:07 +0100 (Wed, 10 Mar 2010)
New Revision: 28463
Modified:
branches/2.0/src/Symfony/Components/Console/Application.php
branches/2.0/src/Symfony/Components/Console/Command/Command.php
branches/2.0/src/Symfony/Components/RequestHandler/Request.php
branches/2.0/src/Symfony/Components/Routing/Generator/Dumper/PhpGeneratorDumper.php
branches/2.0/src/Symfony/Components/Routing/Generator/UrlGenerator.php
branches/2.0/src/Symfony/Components/Routing/Matcher/UrlMatcher.php
branches/2.0/src/Symfony/Foundation/Kernel.php
branches/2.0/src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext1.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext2.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml1.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml2.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_gethelp.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_run1.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_run2.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/application_run3.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/command_astext.txt
branches/2.0/tests/fixtures/Symfony/Components/Console/command_asxml.txt
branches/2.0/tests/unit/Symfony/Components/Console/Command/CommandTest.php
Log:
Merge branch 'master' of git://github.com/symfony/symfony
Modified: branches/2.0/src/Symfony/Components/Console/Application.php
===================================================================
--- branches/2.0/src/Symfony/Components/Console/Application.php 2010-03-10
13:03:45 UTC (rev 28462)
+++ branches/2.0/src/Symfony/Components/Console/Application.php 2010-03-10
15:15:07 UTC (rev 28463)
@@ -249,13 +249,13 @@
$this->getLongVersion(),
'',
'<comment>Usage:</comment>',
- sprintf(" %s [options] command [arguments]\n", $this->getName()),
+ sprintf(" [options] command [arguments]\n"),
'<comment>Options:</comment>',
);
foreach ($this->definition->getOptions() as $option)
{
- $messages[] = sprintf(' %-24s %s %s',
+ $messages[] = sprintf(' %-29s %s %s',
'<info>--'.$option->getName().'</info>',
$option->getShortcut() ? '<info>-'.$option->getShortcut().'</info>' :
' ',
$option->getDescription()
Modified: branches/2.0/src/Symfony/Components/Console/Command/Command.php
===================================================================
--- branches/2.0/src/Symfony/Components/Console/Command/Command.php
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/src/Symfony/Components/Console/Command/Command.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -406,7 +406,7 @@
*/
public function getSynopsis()
{
- return sprintf('%%s %s %s', $this->getFullName(),
$this->definition->getSynopsis());
+ return sprintf('%s %s', $this->getFullName(),
$this->definition->getSynopsis());
}
/**
@@ -432,7 +432,7 @@
{
$messages = array(
'<comment>Usage:</comment>',
- sprintf(' '.$this->getSynopsis(), null === $this->application ? '' :
$this->application->getName()),
+ ' '.$this->getSynopsis(),
'',
);
Modified: branches/2.0/src/Symfony/Components/RequestHandler/Request.php
===================================================================
--- branches/2.0/src/Symfony/Components/RequestHandler/Request.php
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/src/Symfony/Components/RequestHandler/Request.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -28,7 +28,7 @@
protected $pathParameters;
protected $requestParameters;
protected $queryParameters;
- protected $serverParameter;
+ protected $serverParameters;
protected $languages;
protected $charsets;
protected $acceptableContentTypes;
Modified:
branches/2.0/src/Symfony/Components/Routing/Generator/Dumper/PhpGeneratorDumper.php
===================================================================
---
branches/2.0/src/Symfony/Components/Routing/Generator/Dumper/PhpGeneratorDumper.php
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/src/Symfony/Components/Routing/Generator/Dumper/PhpGeneratorDumper.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -59,12 +59,13 @@
$variables = str_replace("\n", '',
var_export($compiledRoute->getVariables(), true));
$defaults = str_replace("\n", '', var_export($route->getDefaults(),
true));
+ $requirements = str_replace("\n", '',
var_export($compiledRoute->getRequirements(), true));
$tokens = str_replace("\n", '', var_export($compiledRoute->getTokens(),
true));
$methods[] = <<<EOF
protected function get{$name}RouteInfo()
{
- return array($variables, array_merge(\$this->defaults, $defaults),
$tokens);
+ return array($variables, array_merge(\$this->defaults, $defaults),
$requirements, $tokens);
}
EOF
@@ -82,9 +83,9 @@
throw new \InvalidArgumentException(sprintf('Route "%s" does not
exist.', \$name));
}
- list(\$variables, \$defaults, \$tokens) = \$this->\$method();
+ list(\$variables, \$defaults, \$requirements, \$tokens) =
\$this->\$method();
- return \$this->doGenerate(\$variables, \$defaults, \$tokens, \$parameters,
\$name, \$absolute);
+ return \$this->doGenerate(\$variables, \$defaults, \$requirements,
\$tokens, \$parameters, \$name, \$absolute);
}
$methods
Modified: branches/2.0/src/Symfony/Components/Routing/Generator/UrlGenerator.php
===================================================================
--- branches/2.0/src/Symfony/Components/Routing/Generator/UrlGenerator.php
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/src/Symfony/Components/Routing/Generator/UrlGenerator.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -38,7 +38,7 @@
public function __construct(RouteCollection $routes, array $context =
array(), array $defaults = array())
{
$this->routes = $routes;
- $this->context = array_merge(array('base_url', ''), $context);
+ $this->context = array_merge(array('base_url' => ''), $context);
$this->defaults = $defaults;
$this->cache = array();
}
@@ -64,10 +64,10 @@
$this->cache[$name] = $route->compile();
}
- return $this->doGenerate($this->cache[$name]->getVariables(),
$route->getDefaults(), $this->cache[$name]->getTokens(), $parameters, $name,
$absolute);
+ return $this->doGenerate($this->cache[$name]->getVariables(),
$route->getDefaults(), $route->getRequirements(),
$this->cache[$name]->getTokens(), $parameters, $name, $absolute);
}
- protected function doGenerate($variables, $defaults, $tokens, $parameters,
$name, $absolute)
+ protected function doGenerate($variables, $defaults, $requirements, $tokens,
$parameters, $name, $absolute)
{
$defaults = array_merge($this->defaults, $defaults);
$tparams = array_merge($defaults, $parameters);
@@ -86,6 +86,12 @@
{
if (false === $optional || !isset($defaults[$token[3]]) ||
(isset($parameters[$token[3]]) && $parameters[$token[3]] !=
$defaults[$token[3]]))
{
+ // check requirement
+ if (isset($requirements[$token[3]]) &&
!preg_match('#^'.$requirements[$token[3]].'$#', $tparams[$token[3]]))
+ {
+ throw new \InvalidArgumentException(sprintf('Parameter "%s" for
route "%s" must match "%s" ("%s" given).', $token[3], $name,
$requirements[$token[3]], $tparams[$token[3]]));
+ }
+
$url = $token[1].urlencode($tparams[$token[3]]).$url;
$optional = false;
}
Modified: branches/2.0/src/Symfony/Components/Routing/Matcher/UrlMatcher.php
===================================================================
--- branches/2.0/src/Symfony/Components/Routing/Matcher/UrlMatcher.php
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/src/Symfony/Components/Routing/Matcher/UrlMatcher.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -59,7 +59,7 @@
$compiledRoute = $route->compile();
// check HTTP method requirement
- if (!isset($this->context['method']) || (($req =
$route->getRequirement('_method')) &&
!in_array(strtolower($this->context['method']), array_map('strtolower', (array)
$req))))
+ if (isset($this->context['method']) && (($req =
$route->getRequirement('_method')) &&
!in_array(strtolower($this->context['method']), array_map('strtolower', (array)
$req))))
{
continue;
}
Modified: branches/2.0/src/Symfony/Foundation/Kernel.php
===================================================================
--- branches/2.0/src/Symfony/Foundation/Kernel.php 2010-03-10 13:03:45 UTC
(rev 28462)
+++ branches/2.0/src/Symfony/Foundation/Kernel.php 2010-03-10 15:15:07 UTC
(rev 28463)
@@ -185,7 +185,7 @@
public function getParameters()
{
- return $parameters;
+ return $this->parameters;
}
public function getDefaultParameters()
Modified: branches/2.0/src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php
===================================================================
--- branches/2.0/src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -57,12 +57,14 @@
protected function read()
{
- $db = $this->initDb(SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READ);
- $data = $db->querySingle(sprintf("SELECT data FROM data WHERE token = '%s'
LIMIT 1 ORDER BY created_at DESC", $db->escapeString($this->token)));
-
- $this->data = unserialize(pack('H*', $data));
-
- $db->close();
+ $db = $this->initDb();
+ $args = array(':token' => $this->token);
+ $data = $this->exec($db, "SELECT data FROM data WHERE token = :token ORDER
BY created_at DESC LIMIT 1", $args);
+ $this->close($db);
+ if (isset($data[0]['data']))
+ {
+ return unserialize(pack('H*', $data[0]['data']));
+ }
}
public function write($data)
@@ -70,23 +72,84 @@
$unpack = unpack('H*', serialize($data));
$data = $unpack[1];
- $db = $this->initDb(SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
- $db->exec(sprintf("INSERT INTO data (token, data, created_at) VALUES
('%s', '%s', %s)", $db->escapeString($this->token), $db->escapeString($data),
time()));
- $db->close();
+ $db = $this->initDb(false);
+ $args = array(
+ ':token' => $this->token,
+ ':data' => (string) $data,
+ ':time' => time()
+ );
+ $this->exec($db, "INSERT INTO data (token, data, created_at) VALUES
(:token, :data, :time)", $args);
+ $this->close($db);
}
- protected function initDb($flags)
+ protected function initDb($readOnly = true)
{
- $db = new \SQLite3($this->store, $flags);
- $db->exec('CREATE TABLE IF NOT EXISTS data (token STRING, data STRING,
created_at TIMESTAMP)');
+ if (class_exists('\SQLite3'))
+ {
+ $flags = $readOnly ? \SQLITE3_OPEN_READONLY : \SQLITE3_OPEN_READWRITE;
+ $flags |= \SQLITE3_OPEN_CREATE;
+ $db = new \SQLite3($this->store, $flags);
+ }
+ elseif (class_exists('\PDO') && in_array('sqlite',
\PDO::getAvailableDrivers(), true))
+ {
+ $db = new \PDO('sqlite:'.$this->store);
+ }
+ else
+ {
+ throw new \RuntimeException('You need to enable either the SQLite or
PDO_SQLite extension for the ProfilerBundle to run properly.');
+ }
+
+ $db->exec('CREATE TABLE IF NOT EXISTS data (token STRING, data STRING,
created_at INTEGER)');
$db->exec('CREATE INDEX IF NOT EXISTS data_data ON data (created_at)');
return $db;
}
+ protected function exec($db, $query, array $args = array())
+ {
+ $return = array();
+ $stmt = $db->prepare($query);
+
+ if ($db instanceof \SQLite3)
+ {
+ foreach ($args as $arg => $val)
+ {
+ $stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER :
\SQLITE3_TEXT);
+ }
+ $res = $stmt->execute();
+ while ($row = $res->fetchArray(\SQLITE3_ASSOC))
+ {
+ $return[] = $row;
+ }
+ $res->finalize();
+ $stmt->close();
+ }
+ else
+ {
+ foreach ($args as $arg => $val)
+ {
+ $stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT :
\PDO::PARAM_STR);
+ }
+ $stmt->execute();
+ $return = $stmt->fetchAll(\PDO::FETCH_ASSOC);
+ }
+
+ return $return;
+ }
+
+ protected function close($db)
+ {
+ if ($db instanceof \SQLite3)
+ {
+ $db->close();
+ }
+ }
+
public function purge($lifetime)
{
- $db = $this->initDb(SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
- $db->exec(sprintf("DELETE FROM data WHERE strftime('%%s', 'now') -
created_at > %d", $lifetime));
+ $db = $this->initDb(false);
+ $args = array(':time' => time() - (int) $lifetime);
+ $this->exec($db, "DELETE FROM data WHERE created_at < :time", $args);
+ $this->close($db);
}
}
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext1.txt
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext1.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext1.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,7 +1,7 @@
<info>Console Tool</info>
<comment>Usage:</comment>
- UNKNOWN [options] command [arguments]
+ [options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext2.txt
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext2.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/tests/fixtures/Symfony/Components/Console/application_astext2.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,7 +1,7 @@
<info>Console Tool</info>
<comment>Usage:</comment>
- UNKNOWN [options] command [arguments]
+ [options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml1.txt
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml1.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml1.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -2,7 +2,7 @@
<symfony>
<commands>
<command id="help" namespace="_global" name="help">
- <usage> help [--xml] [command_name]</usage>
+ <usage>help [--xml] [command_name]</usage>
<description>Displays help for a command</description>
<help>The <info>help</info> command displays help for a given
command:
@@ -29,7 +29,7 @@
</options>
</command>
<command id="list" namespace="_global" name="list">
- <usage> list [--xml] [namespace]</usage>
+ <usage>list [--xml] [namespace]</usage>
<description>Lists commands</description>
<help>The <info>list</info> command lists all commands:
@@ -56,7 +56,7 @@
</options>
</command>
<command id="foo:bar" namespace="foo" name="bar">
- <usage> foo:bar </usage>
+ <usage>foo:bar </usage>
<description>The foo:bar command</description>
<help/>
<aliases>
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml2.txt
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml2.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/tests/fixtures/Symfony/Components/Console/application_asxml2.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -2,7 +2,7 @@
<symfony>
<commands namespace="foo">
<command id="foo:bar" namespace="foo" name="bar">
- <usage> foo:bar </usage>
+ <usage>foo:bar </usage>
<description>The foo:bar command</description>
<help/>
<aliases>
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_gethelp.txt
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/Console/application_gethelp.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/tests/fixtures/Symfony/Components/Console/application_gethelp.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,7 +1,7 @@
<info>Console Tool</info>
<comment>Usage:</comment>
- UNKNOWN [options] command [arguments]
+ [options] command [arguments]
<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
===================================================================
---
branches/2.0/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++
branches/2.0/tests/fixtures/Symfony/Components/Console/application_renderexception2.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -6,6 +6,6 @@
-UNKNOWN list [--xml] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command [namespace]
+list [--xml] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command [namespace]
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_run1.txt
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Console/application_run1.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/tests/fixtures/Symfony/Components/Console/application_run1.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,7 +1,7 @@
Console Tool
Usage:
- UNKNOWN [options] command [arguments]
+ [options] command [arguments]
Options:
--help -h Display this help message.
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_run2.txt
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Console/application_run2.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/tests/fixtures/Symfony/Components/Console/application_run2.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,5 +1,5 @@
Usage:
- UNKNOWN help [--xml] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command [command_name]
+ help [--xml] [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command [command_name]
Aliases: ?
Arguments:
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/application_run3.txt
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Console/application_run3.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/tests/fixtures/Symfony/Components/Console/application_run3.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,5 +1,5 @@
Usage:
- UNKNOWN list [--xml] [namespace]
+ list [--xml] [namespace]
Arguments:
namespace The namespace name
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/command_astext.txt
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Console/command_astext.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/tests/fixtures/Symfony/Components/Console/command_astext.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,5 +1,5 @@
<comment>Usage:</comment>
- UNKNOWN namespace:name [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command
+ namespace:name [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command
<comment>Aliases:</comment> <info>name</info>
<comment>Arguments:</comment>
Modified:
branches/2.0/tests/fixtures/Symfony/Components/Console/command_asxml.txt
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Console/command_asxml.txt
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/tests/fixtures/Symfony/Components/Console/command_asxml.txt
2010-03-10 15:15:07 UTC (rev 28463)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="namespace:name" namespace="namespace" name="name">
- <usage> namespace:name [-h|--help] [-q|--quiet] [-v|--verbose]
[-V|--version] [-c|--color] [-n|--no-interaction] command</usage>
+ <usage>namespace:name [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version]
[-c|--color] [-n|--no-interaction] command</usage>
<description>description</description>
<help>help</help>
<aliases>
Modified:
branches/2.0/tests/unit/Symfony/Components/Console/Command/CommandTest.php
===================================================================
--- branches/2.0/tests/unit/Symfony/Components/Console/Command/CommandTest.php
2010-03-10 13:03:45 UTC (rev 28462)
+++ branches/2.0/tests/unit/Symfony/Components/Console/Command/CommandTest.php
2010-03-10 15:15:07 UTC (rev 28463)
@@ -132,7 +132,7 @@
// ->getSynopsis()
$t->diag('->getSynopsis()');
-$t->is($command->getSynopsis(), '%s foobar:bar [--foo] [foo]',
'->getSynopsis() returns the synopsis');
+$t->is($command->getSynopsis(), 'foobar:bar [--foo] [foo]', '->getSynopsis()
returns the synopsis');
// ->mergeApplicationDefinition()
$t->diag('->mergeApplicationDefinition()');
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.