merged 2.0

This commit is contained in:
Fabien Potencier 2012-04-06 14:21:18 +02:00
parent 37c9fe9a2b
commit b9daae2847
13 changed files with 77 additions and 18 deletions

View File

@ -70,6 +70,13 @@ class RedirectController extends ContainerAware
return new Response(null, 410);
}
$statusCode = $permanent ? 301 : 302;
// redirect if the path is a full URL
if (parse_url($path, PHP_URL_SCHEME)) {
return new RedirectResponse($path, $statusCode);
}
$request = $this->container->get('request');
if (null === $scheme) {
$scheme = $request->getScheme();
@ -89,6 +96,6 @@ class RedirectController extends ContainerAware
$url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;
return new RedirectResponse($url, $permanent ? 301 : 302);
return new RedirectResponse($url, $statusCode);
}
}

View File

@ -102,15 +102,22 @@ class RedirectControllerTest extends TestCase
public function testEmptyPath()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$controller = new RedirectController();
$controller->setContainer($container);
$returnResponse = $controller->urlRedirectAction('');
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(410, $returnResponse->getStatusCode());
}
public function testFullURL()
{
$controller = new RedirectController();
$returnResponse = $controller->urlRedirectAction('http://foo.bar/');
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals('http://foo.bar/', $returnResponse->headers->get('Location'));
$this->assertEquals(302, $returnResponse->getStatusCode());
}
}

View File

@ -62,7 +62,7 @@ class HttpDigestFactory implements SecurityFactoryInterface
->children()
->scalarNode('provider')->end()
->scalarNode('realm')->defaultValue('Secured Area')->end()
->scalarNode('key')->cannotBeEmpty()->end()
->scalarNode('key')->isRequired()->cannotBeEmpty()->end()
->end()
;
}

View File

@ -53,7 +53,7 @@ $container->loadFromExtension('security', array(
'simple' => array('pattern' => '/login', 'security' => false),
'secure' => array('stateless' => true,
'http_basic' => true,
'http_digest' => true,
'http_digest' => array('key' => 'TheKey'),
'form_login' => true,
'anonymous' => true,
'switch_user' => true,

View File

@ -45,7 +45,7 @@
<firewall name="secure" stateless="true">
<http-basic />
<http-digest />
<http-digest key="TheKey" />
<form-login />
<anonymous />
<switch-user />

View File

@ -37,7 +37,8 @@ security:
secure:
stateless: true
http_basic: true
http_digest: true
http_digest:
key: TheKey
form_login: true
anonymous: true
switch_user: true

View File

@ -768,13 +768,16 @@ class Application
do {
$title = sprintf(' [%s] ', get_class($e));
$len = $strlen($title);
$width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
$lines = array();
foreach (explode("\n", $e->getMessage()) as $line) {
$lines[] = sprintf(' %s ', $line);
$len = max($strlen($line) + 4, $len);
foreach (preg_split("{\r?\n}", $e->getMessage()) as $line) {
foreach (str_split($line, $width - 4) as $line) {
$lines[] = sprintf(' %s ', $line);
$len = max($strlen($line) + 4, $len);
}
}
$messages = array(str_repeat(' ', $len), $title.str_repeat(' ', $len - $strlen($title)));
$messages = array(str_repeat(' ', $len), $title.str_repeat(' ', max(0, $len - $strlen($title))));
foreach ($lines as $line) {
$messages[] = $line.str_repeat(' ', $len - $strlen($line));
@ -824,6 +827,28 @@ class Application
}
}
protected function getTerminalWidth()
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) {
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
}
if (preg_match("{rows.(\d+);.columns.(\d+);}i", exec('stty -a | grep columns'), $match)) {
return $match[1];
}
}
protected function getTerminalHeight()
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && $ansicon = getenv('ANSICON')) {
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
}
if (preg_match("{rows.(\d+);.columns.(\d+);}i", exec('stty -a | grep columns'), $match)) {
return $match[2];
}
}
/**
* Gets the name of the command based on input.
*

View File

@ -341,6 +341,15 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions');
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
->method('getTerminalWidth')
->will($this->returnValue(32));
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() wraps messages when they are bigger than the terminal');
}
public function testRun()

View File

@ -193,7 +193,8 @@ class YamlFileLoader extends FileLoader
if (isset($service['calls'])) {
foreach ($service['calls'] as $call) {
$definition->addMethodCall($call[0], $this->resolveServices($call[1]));
$args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
$definition->addMethodCall($call[0], $args);
}
}

View File

@ -124,7 +124,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
$this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
$this->assertEquals(array(array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals(array(array('setBar', array()), array('setBar', array())), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());

View File

@ -33,7 +33,7 @@ class ServerBag extends ParameterBag
}
// CONTENT_* are not prefixed with HTTP_
elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
$headers[$key] = $this->parameters[$key];
$headers[$key] = $value;
}
}

View File

@ -10,12 +10,12 @@ translated strings from these including support for pluralization.
$translator = new Translator('fr_FR', new MessageSelector());
$translator->setFallbackLocale('fr');
$translator->addLoader('array', return new ArrayLoader());
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', array(
'Hello World!' => 'Bonjour',
), 'fr');
$translator->trans('Hello World!');
echo $translator->trans('Hello World!') . "\n";
Resources
---------

View File

@ -0,0 +1,9 @@
[InvalidArgumentException]
Command "foo" is not define
d.