Skip to content

Commit

Permalink
Merge branch '2.8'
Browse files Browse the repository at this point in the history
* 2.8:
  [Yaml] throw a ParseException on invalid data type
  [TwigBridge] type-dependent path discovery
  Resources as string have the same problem
  Introduce failing test case when a SplFileInfo object is passed to the extract() method in the TwigExtractor.
  #15331 add infos about deprecated classes to UPGRADE-3.0
  [Asset] removed unused private property.
  [Twig+FrameworkBundle] Fix forward compat with Form 2.8
  [2.6] Static Code Analysis for Components
  [Security/Http] Fix test relying on a private property
  [Serializer] Fix bugs reported in b5990be#commitcomment-12301266
  [Form] Fix not-BC test assertion
  [Security] Moved Simple{Form,Pre}AuthenticatorInterfaces to Security\Http
  [Security] removed useless else condition in SwitchUserListener class.
  [travis] Tests deps=low with PHP 5.6
  Implement resettable containers
  [Console] Fix console output with closed stdout
  • Loading branch information
fabpot committed Jul 26, 2015
2 parents 7742c30 + 96e211d commit 803144d
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 45 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -12,7 +12,6 @@ matrix:
- php: hhvm
- php: 5.5.9
- php: 5.5
- php: 5.6
- php: 5.6
env: deps=low
- php: 5.6
Expand Down
11 changes: 11 additions & 0 deletions UPGRADE-3.0.md
Expand Up @@ -305,6 +305,17 @@ UPGRADE FROM 2.x to 3.0
```php
echo $form->getErrors(true, false);
```
* The `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList`.

* The `Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\LazyChoiceList`.

* The `Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList`.

* The `Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList`.

### FrameworkBundle

Expand Down
19 changes: 16 additions & 3 deletions src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php
Expand Up @@ -73,15 +73,28 @@ public function getExtractData()

/**
* @expectedException \Twig_Error
* @expectedExceptionMessageRegExp /Unclosed "block" in "extractor(\/|\\)syntax_error\.twig" at line 1/
* @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
* @dataProvider resourcesWithSyntaxErrorsProvider
*/
public function testExtractSyntaxError()
public function testExtractSyntaxError($resources)
{
$twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));

$extractor = new TwigExtractor($twig);
$extractor->extract(__DIR__.'/../Fixtures', new MessageCatalogue('en'));
$extractor->extract($resources, new MessageCatalogue('en'));
}

/**
* @return array
*/
public function resourcesWithSyntaxErrorsProvider()
{
return array(
array(__DIR__.'/../Fixtures'),
array(__DIR__.'/../Fixtures/extractor/syntax_error.twig'),
array(new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig')),
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Translation;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
use Symfony\Component\Translation\Extractor\ExtractorInterface;
use Symfony\Component\Translation\MessageCatalogue;
Expand Down Expand Up @@ -60,7 +61,11 @@ public function extract($resource, MessageCatalogue $catalogue)
try {
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
} catch (\Twig_Error $e) {
$e->setTemplateFile($file->getRelativePathname());
if ($file instanceof SplFileInfo) {
$e->setTemplateFile($file->getRelativePathname());
} elseif ($file instanceof \SplFileInfo) {
$e->setTemplateFile($file->getRealPath());
}

throw $e;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Asset/UrlPackage.php
Expand Up @@ -36,7 +36,6 @@
class UrlPackage extends Package
{
private $baseUrls = array();
private $sslUrls;
private $sslPackage;

/**
Expand All @@ -62,7 +61,7 @@ public function __construct($baseUrls = array(), VersionStrategyInterface $versi
$sslUrls = $this->getSslUrls($baseUrls);

if ($sslUrls && $baseUrls !== $sslUrls) {
$this->sslPackage = new UrlPackage($sslUrls, $versionStrategy);
$this->sslPackage = new self($sslUrls, $versionStrategy);
}
}

Expand Down
27 changes: 22 additions & 5 deletions src/Symfony/Component/Console/Output/ConsoleOutput.php
Expand Up @@ -46,12 +46,9 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
{
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';

parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);

$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
$this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
}

/**
Expand Down Expand Up @@ -129,4 +126,24 @@ private function isRunningOS400()
{
return 'OS400' === php_uname('s');
}

/**
* @return resource
*/
private function openOutputStream()
{
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';

return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
}

/**
* @return resource
*/
private function openErrorStream()
{
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';

return fopen($errorStream, 'w');
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* allowed specifying a directory to recursively load all configuration files it contains
* deprecated the concept of scopes
* added `Definition::setShared()` and `Definition::isShared()`
* added ResettableContainerInterface to be able to reset the container to release memory on shutdown

2.7.0
-----
Expand Down
15 changes: 14 additions & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
Expand Down Expand Up @@ -60,7 +61,7 @@
*
* @api
*/
class Container implements IntrospectableContainerInterface
class Container implements IntrospectableContainerInterface, ResettableContainerInterface
{
/**
* @var ParameterBagInterface
Expand Down Expand Up @@ -367,6 +368,18 @@ public function initialized($id)
return isset($this->services[$id]) || array_key_exists($id, $this->services);
}

/**
* {@inheritdoc}
*/
public function reset()
{
if (!empty($this->scopedServices)) {
throw new LogicException('Resetting the container is not allowed when a scope is active.');
}

$this->services = array();
}

/**
* Gets all service ids.
*
Expand Down
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection;

/**
* ResettableContainerInterface defines additional resetting functionality
* for containers, allowing to release shared services when the container is
* not needed anymore.
*
* @author Christophe Coevoet <stof@notk.org>
*/
interface ResettableContainerInterface extends ContainerInterface
{
/**
* Resets shared services from the container.
*
* The container is not intended to be used again after being reset in a normal workflow. This method is
* meant as a way to release references for ref-counting.
* A subsequent call to ContainerInterface::get will recreate a new instance of the shared service.
*/
public function reset();
}
43 changes: 43 additions & 0 deletions src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
Expand Up @@ -308,6 +308,49 @@ public function testInitialized()
$this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized');
}

public function testReset()
{
$c = new Container();
$c->set('bar', new \stdClass());

$c->reset();

$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
* @expectedExceptionMessage Resetting the container is not allowed when a scope is active.
* @group legacy
*/
public function testCannotResetInActiveScope()
{
$c = new Container();
$c->addScope(new Scope('foo'));
$c->set('bar', new \stdClass());

$c->enterScope('foo');

$c->reset();
}

/**
* @group legacy
*/
public function testResetAfterLeavingScope()
{
$c = new Container();
$c->addScope(new Scope('foo'));
$c->set('bar', new \stdClass());

$c->enterScope('foo');
$c->leaveScope('foo');

$c->reset();

$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}

/**
* @group legacy
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/Client.php
Expand Up @@ -101,7 +101,7 @@ protected function getScript($request)

$r = new \ReflectionClass('\\Symfony\\Component\\ClassLoader\\ClassLoader');
$requirePath = str_replace("'", "\\'", $r->getFileName());
$symfonyPath = str_replace("'", "\\'", realpath(__DIR__.'/../../..'));
$symfonyPath = str_replace("'", "\\'", dirname(dirname(dirname(__DIR__))));
$errorReporting = error_reporting();

$code = <<<EOF
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
Expand Down Expand Up @@ -164,6 +165,10 @@ public function shutdown()
$bundle->setContainer(null);
}

if ($this->container instanceof ResettableContainerInterface) {
$this->container->reset();
}

$this->container = null;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Intl/Resources/bin/update-data.php
Expand Up @@ -178,8 +178,7 @@
$compiler = new GenrbCompiler($genrb, $genrbEnv);
$config = new GeneratorConfig($sourceDir.'/data', $icuVersionInDownload);

// Don't wrap "/data" in realpath(), in case the directory does not exist
$baseDir = realpath(__DIR__.'/..').'/data';
$baseDir = dirname(__DIR__).'/data';

//$txtDir = $baseDir.'/txt';
$jsonDir = $baseDir;
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Security/CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@ CHANGELOG

* deprecated `getKey()` of the `AnonymousToken`, `RememberMeToken` and `AbstractRememberMeServices` classes
in favor of `getSecret()`.
* deprecated `Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface`, use
`Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface` instead
* deprecated `Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface`, use
`Symfony\Component\Security\Http\Authentication\SimpleFormAuthenticatorInterface` instead

2.7.0
-----
Expand Down
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\HttpFoundation\Request;

/**
* @deprecated Deprecated since version 2.8, to be removed in 3.0. Use the same interface from Security\Http\Authentication instead.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SimpleFormAuthenticatorInterface extends SimpleAuthenticatorInterface
Expand Down
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\HttpFoundation\Request;

/**
* @deprecated Since version 2.8, to be removed in 3.0. Use the same interface from Security\Http\Authentication instead.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SimplePreAuthenticatorInterface extends SimpleAuthenticatorInterface
Expand Down
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Http\Authentication;

use Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface as BaseSimpleFormAuthenticatorInterface;

/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SimpleFormAuthenticatorInterface extends BaseSimpleFormAuthenticatorInterface
{
}
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Http\Authentication;

use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface as BaseSimplePreAuthenticatorInterface;

/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SimplePreAuthenticatorInterface extends BaseSimplePreAuthenticatorInterface
{
}
Expand Up @@ -115,9 +115,9 @@ private function attemptSwitchUser(Request $request)
if (false !== $originalToken) {
if ($token->getUsername() === $request->get($this->usernameParameter)) {
return $token;
} else {
throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
}

throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
}

if (false === $this->accessDecisionManager->decide($token, array($this->role))) {
Expand Down
Expand Up @@ -54,10 +54,9 @@ public function testHandleWithTokenStorageHavingNoToken()
$authenticationManager
->expects($this->once())
->method('authenticate')
->with(self::logicalAnd(
$this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken'),
$this->attributeEqualTo('secret', 'TheSecret')
))
->with($this->callback(function ($token) {
return 'TheSecret' === $token->getSecret();
}))
->will($this->returnValue($anonymousToken))
;

Expand Down

0 comments on commit 803144d

Please sign in to comment.