Author: fabien
Date: 2010-03-25 12:30:06 +0100 (Thu, 25 Mar 2010)
New Revision: 28783
Added:
branches/2.0/tests/Symfony/Tests/Components/RequestHandler/
branches/2.0/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfCompact.yml
Removed:
branches/2.0/src/Symfony/Foundation/ClassLoader.php
Modified:
branches/2.0/src/Symfony/Components/RequestHandler/Request.php
branches/2.0/src/Symfony/Components/Yaml/Parser.php
branches/2.0/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php
branches/2.0/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php
branches/2.0/tests/Symfony/Tests/bootstrap.php
branches/2.0/tests/fixtures/Symfony/Components/Yaml/index.yml
branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfTests.yml
Log:
Merge branch 'master' of git://github.com/symfony/symfony
Modified: branches/2.0/src/Symfony/Components/RequestHandler/Request.php
===================================================================
--- branches/2.0/src/Symfony/Components/RequestHandler/Request.php
2010-03-25 10:51:43 UTC (rev 28782)
+++ branches/2.0/src/Symfony/Components/RequestHandler/Request.php
2010-03-25 11:30:06 UTC (rev 28783)
@@ -45,11 +45,14 @@
/**
* Constructor.
*
- * @param array $parameters An array of parameters (see setParameters())
+ * @param array $query The GET parameters
+ * @param array $request The POST parameters
+ * @param array $path The parameters parsed from the PATH_INFO (see
Router)
+ * @param array $server The SERVER parameters
*/
- public function __construct(array $parameters = array())
+ public function __construct(array $query = null, array $request = null,
array $path = null, array $server = null)
{
- $this->setParameters($parameters);
+ $this->setParameters($request, $query, $path, $server);
}
/**
@@ -57,21 +60,17 @@
*
* This method also re-initializes all properties.
*
- * The parameters can define four elements:
- *
- * * request: The POST parameters
- * * query: The GET parameters
- * * path: The parameters parsed from the PATH_INFO (see Router)
- * * server: The SERVER parameters
- *
- * @param array $parameters An array of parameters
+ * @param array $query The GET parameters
+ * @param array $request The POST parameters
+ * @param array $path The parameters parsed from the PATH_INFO
+ * @param array $server The SERVER parameters
*/
- public function setParameters(array $parameters = array())
+ public function setParameters(array $query = null, array $request = null,
array $path = null, array $server = null)
{
- $this->requestParameters = isset($parameters['request']) ?
$parameters['request'] : $_POST;
- $this->queryParameters = isset($parameters['query']) ?
$parameters['query'] : $_GET;
- $this->pathParameters = isset($parameters['path']) ? $parameters['path'] :
array();
- $this->serverParameters = isset($parameters['server']) ?
$parameters['server'] : $_SERVER;
+ $this->requestParameters = null !== $request ? $request : $_POST;
+ $this->queryParameters = null !== $query ? $query : $_GET;
+ $this->pathParameters = null !== $path ? $path : array();
+ $this->serverParameters = null !== $server ? $server : $_SERVER;
$this->languages = null;
$this->charsets = null;
@@ -85,30 +84,25 @@
$this->format = null;
}
- public function duplicate(array $parameters = array())
+ /**
+ * Clones a request and overrides some of its parameters.
+ *
+ * @param array $query The GET parameters
+ * @param array $request The POST parameters
+ * @param array $path The parameters parsed from the PATH_INFO
+ * @param array $server The SERVER parameters
+ */
+ public function duplicate(array $query = null, array $request = null, array
$path = null, array $server = null)
{
- $request = clone $this;
+ $dup = clone $this;
+ $dup->setParameters(
+ null !== $query ? $query : $this->queryParameters,
+ null !== $request ? $request : $this->requestParameters,
+ null !== $path ? $path : $this->pathParameters,
+ null !== $server ? $server : $this->serverParameters
+ );
- foreach (array('request', 'query', 'path', 'server') as $key)
- {
- if (isset($parameters[$key]))
- {
- $request->{$key.'Parameters'} = $parameters[$key];
- }
- }
-
- $this->languages = null;
- $this->charsets = null;
- $this->acceptableContentTypes = null;
- $this->scriptName = null;
- $this->pathInfo = null;
- $this->requestUri = null;
- $this->baseUrl = null;
- $this->basePath = null;
- $this->method = null;
- $this->format = null;
-
- return $request;
+ return $dup;
}
/**
Modified: branches/2.0/src/Symfony/Components/Yaml/Parser.php
===================================================================
--- branches/2.0/src/Symfony/Components/Yaml/Parser.php 2010-03-25 10:51:43 UTC
(rev 28782)
+++ branches/2.0/src/Symfony/Components/Yaml/Parser.php 2010-03-25 11:30:06 UTC
(rev 28783)
@@ -83,11 +83,7 @@
}
else
{
- if (preg_match('/^([^ ]+)\: +({.*?)$/', $values['value'], $matches))
- {
- $data[] = array($matches[1] => Inline::load($matches[2]));
- }
- elseif (isset($values['leadspaces'])
+ if (isset($values['leadspaces'])
&& ' ' == $values['leadspaces']
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^
\'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches))
{
@@ -99,7 +95,7 @@
$block = $values['value'];
if (!$this->isNextLineIndented())
{
- $block .= "\n".$this->getNextEmbedBlock();
+ $block .=
"\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
}
$data[] = $parser->parse($block);
@@ -283,26 +279,38 @@
/**
* Returns the next embed block of YAML.
*
+ * @param integer $indentation The indent level at which the block is to be
read, or null for default
+ *
* @return string A YAML string
*/
- protected function getNextEmbedBlock()
+ protected function getNextEmbedBlock($indentation = null)
{
$this->moveToNextLine();
- $newIndent = $this->getCurrentLineIndentation();
+ if (null === $indentation)
+ {
+ $newIndent = $this->getCurrentLineIndentation();
- if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
+ if (!$this->isCurrentLineEmpty() && 0 == $newIndent)
+ {
+ throw new ParserException(sprintf('Indentation problem at line %d
(%s)', $this->getRealCurrentLineNb() + 1, $this->currentLine));
+ }
+ }
+ else
{
- throw new ParserException(sprintf('Indentation problem at line %d (%s)',
$this->getRealCurrentLineNb() + 1, $this->currentLine));
+ $newIndent = $indentation;
}
$data = array(substr($this->currentLine, $newIndent));
while ($this->moveToNextLine())
{
- if ($this->isCurrentLineBlank())
+ if ($this->isCurrentLineEmpty())
{
- $data[] = substr($this->currentLine, $newIndent);
+ if ($this->isCurrentLineBlank())
+ {
+ $data[] = substr($this->currentLine, $newIndent);
+ }
continue;
}
Deleted: branches/2.0/src/Symfony/Foundation/ClassLoader.php
===================================================================
--- branches/2.0/src/Symfony/Foundation/ClassLoader.php 2010-03-25 10:51:43 UTC
(rev 28782)
+++ branches/2.0/src/Symfony/Foundation/ClassLoader.php 2010-03-25 11:30:06 UTC
(rev 28783)
@@ -1,84 +0,0 @@
-<?php
-
-namespace Symfony\Foundation;
-
-/*
- * This file is part of the symfony package.
- *
- * (c) Fabien Potencier <[email protected]>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * ClassLoader implementation that implements the technical interoperability
- * standards for PHP 5.3 namespaces and class names.
- *
- * Based on
http://groups.google.com/group/php-standards/web/psr-0-final-proposal
- *
- * Example usage:
- *
- * [php]
- * $loader = new ClassLoader();
- * $loader->registerNamespace('Symfony', __DIR__.'/..');
- * $loader->register();
- *
- * @author Jonathan H. Wage <[email protected]>
- * @author Roman S. Borschel <[email protected]>
- * @author Matthew Weier O'Phinney <[email protected]>
- * @author Kris Wallsmith <[email protected]>
- * @author Fabien Potencier <[email protected]>
- */
-class ClassLoader
-{
- protected $namespaces = array();
-
- /**
- * Creates a new loader for classes of the specified namespace.
- *
- * @param string $namespace The namespace to use
- * @param string $includePath The path to the namespace
- */
- public function registerNamespace($namespace, $includePath = null)
- {
- $this->namespaces[$namespace] = $includePath;
- }
-
- /**
- * Installs this class loader on the SPL autoload stack.
- */
- public function register()
- {
- spl_autoload_register(array($this, 'loadClass'));
- }
-
- /**
- * Loads the given class or interface.
- *
- * @param string $className The name of the class to load
- */
- public function loadClass($className)
- {
- $vendor = substr($className, 0, stripos($className, '\\'));
- if (!isset($this->namespaces[$vendor]))
- {
- return;
- }
-
- if (false !== ($lastNsPos = strripos($className, '\\')))
- {
- $namespace = substr($className, 0, $lastNsPos);
- $className = substr($className, $lastNsPos + 1);
- $fileName = str_replace('\\', DIRECTORY_SEPARATOR,
$namespace).DIRECTORY_SEPARATOR;
- }
- else
- {
- $namespace = '';
- $fileName = '';
- }
- $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
-
- require $this->namespaces[$vendor].DIRECTORY_SEPARATOR.$fileName;
- }
-}
Modified:
branches/2.0/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php
===================================================================
--- branches/2.0/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php
2010-03-25 10:51:43 UTC (rev 28782)
+++ branches/2.0/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php
2010-03-25 11:30:06 UTC (rev 28783)
@@ -45,7 +45,7 @@
list($parameters['_bundle'], $parameters['_controller'],
$parameters['_action']) = explode(':', $controller);
$parameters['_format'] = $request->getRequestFormat();
- $request = $request->duplicate(array('path' => $parameters));
+ $request = $request->duplicate(null, null, $parameters);
return $this->container->getRequestHandlerService()->handleRaw($request,
false);
}
Modified:
branches/2.0/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php
===================================================================
--- branches/2.0/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php
2010-03-25 10:51:43 UTC (rev 28782)
+++ branches/2.0/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php
2010-03-25 11:30:06 UTC (rev 28783)
@@ -67,7 +67,7 @@
'logs' =>
$this->container->hasService('zend.logger.writer.debug') ?
$this->container->getService('zend.logger.writer.debug')->getLogs() : array(),
);
- $request = $event->getParameter('request')->duplicate(array('path' =>
$parameters));
+ $request = $event->getParameter('request')->duplicate(null, null,
$parameters);
try
{
Added:
branches/2.0/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
===================================================================
--- branches/2.0/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
(rev 0)
+++ branches/2.0/tests/Symfony/Tests/Components/RequestHandler/RequestTest.php
2010-03-25 11:30:06 UTC (rev 28783)
@@ -0,0 +1,68 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ *
+ * (c) Fabien Potencier <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Tests\Components\RequestHandler;
+
+require_once __DIR__.'/../../bootstrap.php';
+
+use Symfony\Components\RequestHandler\Request;
+
+class RequestTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @covers Request::__construct()
+ */
+ public function testConstructor()
+ {
+ $this->testSetParameters();
+ }
+
+ /**
+ * @covers Request::setParameters()
+ */
+ public function testSetParameters()
+ {
+ $request = new Request();
+
+ $request->setParameters(array('foo' => 'bar'));
+ $this->assertEquals('bar', $request->getQueryParameter('foo'),
'->setParameter() takes an array of query parameters as its first argument');
+
+ $request->setParameters(null, array('foo' => 'bar'));
+ $this->assertEquals('bar', $request->getRequestParameter('foo'),
'->setParameter() takes an array of request parameters as its second argument');
+
+ $request->setParameters(null, null, array('foo' => 'bar'));
+ $this->assertEquals('bar', $request->getPathParameter('foo'),
'->setParameter() takes an array of path parameters as its thrid argument');
+
+ $request->setParameters(null, null, null, array('HTTP_FOO' => 'bar'));
+ $this->assertEquals('bar', $request->getHttpHeader('foo'),
'->setParameter() takes an array of HTTP headers as its fourth argument');
+ }
+
+ /**
+ * @covers Request::duplicate()
+ */
+ public function testDuplicate()
+ {
+ $request = new Request(array('foo' => 'bar'), array('foo' => 'bar'),
array('foo' => 'bar'), array('HTTP_FOO' => 'bar'));
+ $dup = $request->duplicate();
+
+ $this->assertEquals($request->getQueryParameters(),
$dup->getQueryParameters(), '->duplicate() duplicates a request an copy the
current query parameters');
+ $this->assertEquals($request->getRequestParameters(),
$dup->getRequestParameters(), '->duplicate() duplicates a request an copy the
current request parameters');
+ $this->assertEquals($request->getPathParameters(),
$dup->getPathParameters(), '->duplicate() duplicates a request an copy the
current path parameters');
+ $this->assertEquals($request->getHttpHeader('foo'),
$dup->getHttpHeader('foo'), '->duplicate() duplicates a request an copy the
current HTTP headers');
+
+ $dup = $request->duplicate(array('foo' => 'foobar'), array('foo' =>
'foobar'), array('foo' => 'foobar'), array('HTTP_FOO' => 'foobar'));
+
+ $this->assertEquals(array('foo' => 'foobar'), $dup->getQueryParameters(),
'->duplicate() overrides the query parameters if provided');
+ $this->assertEquals(array('foo' => 'foobar'),
$dup->getRequestParameters(), '->duplicate() overrides the request parameters
if provided');
+ $this->assertEquals(array('foo' => 'foobar'), $dup->getPathParameters(),
'->duplicate() overrides the path parameters if provided');
+ $this->assertEquals('foobar', $dup->getHttpHeader('foo'), '->duplicate()
overrides the HTTP header if provided');
+ }
+}
Modified: branches/2.0/tests/Symfony/Tests/bootstrap.php
===================================================================
--- branches/2.0/tests/Symfony/Tests/bootstrap.php 2010-03-25 10:51:43 UTC
(rev 28782)
+++ branches/2.0/tests/Symfony/Tests/bootstrap.php 2010-03-25 11:30:06 UTC
(rev 28783)
@@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/
-require_once __DIR__.'/../../../src/Symfony/Foundation/ClassLoader.php';
+require_once
__DIR__.'/../../../src/Symfony/Foundation/UniversalClassLoader.php';
require_once 'PHPUnit/Framework.php';
-$loader = new Symfony\Foundation\ClassLoader();
+$loader = new Symfony\Foundation\UniversalClassLoader();
$loader->registerNamespace('Symfony', __DIR__.'/../../../src');
$loader->register();
Modified: branches/2.0/tests/fixtures/Symfony/Components/Yaml/index.yml
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Yaml/index.yml
2010-03-25 10:51:43 UTC (rev 28782)
+++ branches/2.0/tests/fixtures/Symfony/Components/Yaml/index.yml
2010-03-25 11:30:06 UTC (rev 28783)
@@ -1,4 +1,5 @@
- sfComments
+- sfCompact
- sfTests
- sfObjects
- sfMergeKey
Added: branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfCompact.yml
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfCompact.yml
(rev 0)
+++ branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfCompact.yml
2010-03-25 11:30:06 UTC (rev 28783)
@@ -0,0 +1,159 @@
+--- %YAML:1.0
+test: Compact notation
+brief: |
+ Compact notation for sets of mappings with single element
+yaml: |
+ ---
+ # products purchased
+ - item : Super Hoop
+ - item : Basketball
+ quantity: 1
+ - item:
+ name: Big Shoes
+ nick: Biggies
+ quantity: 1
+php: |
+ array (
+ array (
+ 'item' => 'Super Hoop',
+ ),
+ array (
+ 'item' => 'Basketball',
+ 'quantity' => 1,
+ ),
+ array (
+ 'item' => array(
+ 'name' => 'Big Shoes',
+ 'nick' => 'Biggies'
+ ),
+ 'quantity' => 1
+ )
+ )
+---
+test: Compact notation combined with inline notation
+brief: |
+ Combinations of compact and inline notation are allowed
+yaml: |
+ ---
+ items:
+ - { item: Super Hoop, quantity: 1 }
+ - [ Basketball, Big Shoes ]
+php: |
+ array (
+ 'items' => array (
+ array (
+ 'item' => 'Super Hoop',
+ 'quantity' => 1,
+ ),
+ array (
+ 'Basketball',
+ 'Big Shoes'
+ )
+ )
+ )
+--- %YAML:1.0
+test: Compact notation
+brief: |
+ Compact notation for sets of mappings with single element
+yaml: |
+ ---
+ # products purchased
+ - item : Super Hoop
+ - item : Basketball
+ quantity: 1
+ - item:
+ name: Big Shoes
+ nick: Biggies
+ quantity: 1
+php: |
+ array (
+ array (
+ 'item' => 'Super Hoop',
+ ),
+ array (
+ 'item' => 'Basketball',
+ 'quantity' => 1,
+ ),
+ array (
+ 'item' => array(
+ 'name' => 'Big Shoes',
+ 'nick' => 'Biggies'
+ ),
+ 'quantity' => 1
+ )
+ )
+---
+test: Compact notation combined with inline notation
+brief: |
+ Combinations of compact and inline notation are allowed
+yaml: |
+ ---
+ items:
+ - { item: Super Hoop, quantity: 1 }
+ - [ Basketball, Big Shoes ]
+php: |
+ array (
+ 'items' => array (
+ array (
+ 'item' => 'Super Hoop',
+ 'quantity' => 1,
+ ),
+ array (
+ 'Basketball',
+ 'Big Shoes'
+ )
+ )
+ )
+--- %YAML:1.0
+test: Compact notation
+brief: |
+ Compact notation for sets of mappings with single element
+yaml: |
+ ---
+ # products purchased
+ - item : Super Hoop
+ - item : Basketball
+ quantity: 1
+ - item:
+ name: Big Shoes
+ nick: Biggies
+ quantity: 1
+php: |
+ array (
+ array (
+ 'item' => 'Super Hoop',
+ ),
+ array (
+ 'item' => 'Basketball',
+ 'quantity' => 1,
+ ),
+ array (
+ 'item' => array(
+ 'name' => 'Big Shoes',
+ 'nick' => 'Biggies'
+ ),
+ 'quantity' => 1
+ )
+ )
+---
+test: Compact notation combined with inline notation
+brief: |
+ Combinations of compact and inline notation are allowed
+yaml: |
+ ---
+ items:
+ - { item: Super Hoop, quantity: 1 }
+ - [ Basketball, Big Shoes ]
+php: |
+ array (
+ 'items' => array (
+ array (
+ 'item' => 'Super Hoop',
+ 'quantity' => 1,
+ ),
+ array (
+ 'Basketball',
+ 'Big Shoes'
+ )
+ )
+ )
Modified: branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfTests.yml
===================================================================
--- branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfTests.yml
2010-03-25 10:51:43 UTC (rev 28782)
+++ branches/2.0/tests/fixtures/Symfony/Components/Yaml/sfTests.yml
2010-03-25 11:30:06 UTC (rev 28783)
@@ -143,31 +143,3 @@
0123
php: |
array('foo' => "0123\n")
----
-test: Comments in folded scalars
-brief: Comments in folded scalars should be kept as is
-yaml: |
- # comment
- foo: |
- # comment
- bar
- bar:
- # comment
- foo: bar # comment
- bar: |
- # comment
- foo
- foobar:
- foo: |
- # comment
- bar
- # comment
-php: |
- array(
- 'foo' => "# comment\nbar\n",
- 'bar' => array(
- 'foo' => 'bar',
- 'bar' => "# comment\nfoo\n",
- 'foobar' => array('foo' => "# comment\nbar\n")
- )
- )
--
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.