Skip to content

Commit

Permalink
Merge branch '4.1'
Browse files Browse the repository at this point in the history
* 4.1:
  fixed CS
  Avoiding session migration for stateless firewall UsernamePasswordJsonAuthenticationListener
  fixed CS
  Avoid migration on stateless firewalls
  [Serializer] deserialize from xml: Fix a collection that contains the only one element
  [HttpKernel] Log/Collect exceptions at prio 0
  [PhpUnitBridge] Fix error on some Windows OS
  [DI] Deduplicate generated proxy classes
  [Routing] fix matching host patterns, utf8 prefixes and non-capturing groups
  • Loading branch information
nicolas-grekas committed Jun 11, 2018
2 parents d4f5d46 + 8bbda2c commit 169b13c
Show file tree
Hide file tree
Showing 37 changed files with 1,680 additions and 1,164 deletions.
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit
Expand Up @@ -99,6 +99,8 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
throw new \RuntimeException("Could not find $remoteZip");
}
stream_copy_to_stream($remoteZipStream, fopen("$PHPUNIT_VERSION.zip", 'wb'));
} elseif ('\\' === DIRECTORY_SEPARATOR) {
passthru("certutil -urlcache -split -f \"https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip\" $PHPUNIT_VERSION.zip");
} else {
@unlink("$PHPUNIT_VERSION.zip");
passthru("wget -q https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip");
Expand Down
Expand Up @@ -80,6 +80,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.guard'));
$listener->replaceArgument(2, $id);
$listener->replaceArgument(3, $authenticators);
$listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));

// determine the entryPointId to use
$entryPointId = $this->determineEntryPoint($defaultEntryPoint, $config);
Expand Down
Expand Up @@ -41,6 +41,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.basic'));
$listener->replaceArgument(2, $id);
$listener->replaceArgument(3, new Reference($entryPointId));
$listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));

return array($provider, $listenerId, $entryPointId);
}
Expand Down
Expand Up @@ -89,6 +89,7 @@ protected function createListener($container, $id, $config, $userProvider)
$listener->replaceArgument(4, isset($config['success_handler']) ? new Reference($this->createAuthenticationSuccessHandler($container, $id, $config)) : null);
$listener->replaceArgument(5, isset($config['failure_handler']) ? new Reference($this->createAuthenticationFailureHandler($container, $id, $config)) : null);
$listener->replaceArgument(6, array_intersect_key($config, $this->options));
$listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));

$listenerId .= '.'.$id;
$container->setDefinition($listenerId, $listener);
Expand Down
Expand Up @@ -38,6 +38,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.remote_user'));
$listener->replaceArgument(2, $id);
$listener->replaceArgument(3, $config['user']);
$listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));

return array($providerId, $listenerId, $defaultEntryPoint);
}
Expand Down
Expand Up @@ -57,6 +57,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
$listener = $container->setDefinition($listenerId, new ChildDefinition('security.authentication.listener.simple_preauth'));
$listener->replaceArgument(2, $id);
$listener->replaceArgument(3, new Reference($config['authenticator']));
$listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));

return array($provider, $listenerId, null);
}
Expand Down
Expand Up @@ -39,6 +39,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
$listener->replaceArgument(2, $id);
$listener->replaceArgument(3, $config['user']);
$listener->replaceArgument(4, $config['credentials']);
$listener->addMethodCall('setSessionAuthenticationStrategy', array(new Reference('security.authentication.session_strategy.'.$id)));

return array($providerId, $listenerId, $defaultEntryPoint);
}
Expand Down
Expand Up @@ -285,7 +285,11 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
}

$listeners[] = new Reference($this->createContextListener($container, $contextKey));
$sessionStrategyId = 'security.authentication.session_strategy';
} else {
$sessionStrategyId = 'security.authentication.session_strategy_noop';
}
$container->setAlias(new Alias('security.authentication.session_strategy.'.$id, false), $sessionStrategyId);

$config->replaceArgument(6, $contextKey);

Expand Down
Expand Up @@ -64,6 +64,10 @@
</service>
<service id="Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface" alias="security.authentication.session_strategy" />

<service id="security.authentication.session_strategy_noop" class="Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy" public="false">
<argument>none</argument>
</service>

<service id="security.encoder_factory.generic" class="Symfony\Component\Security\Core\Encoder\EncoderFactory">
<argument type="collection" />
</service>
Expand Down
Expand Up @@ -406,6 +406,7 @@ private function collectLineage($class, array &$lineage)

private function generateProxyClasses()
{
$alreadyGenerated = array();
$definitions = $this->container->getDefinitions();
$strip = '' === $this->docStar && method_exists('Symfony\Component\HttpKernel\Kernel', 'stripComments');
$proxyDumper = $this->getProxyDumper();
Expand All @@ -414,8 +415,12 @@ private function generateProxyClasses()
if (!$proxyDumper->isProxyCandidate($definition)) {
continue;
}
if (isset($alreadyGenerated[$class = $definition->getClass()])) {
continue;
}
$alreadyGenerated[$class] = true;
// register class' reflector for resource tracking
$this->container->getReflectionClass($definition->getClass());
$this->container->getReflectionClass($class);
$proxyCode = "\n".$proxyDumper->getProxyCode($definition);
if ($strip) {
$proxyCode = "<?php\n".$proxyCode;
Expand Down
Expand Up @@ -616,6 +616,19 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
$this->addToAssertionCount(1);
}

public function testDedupLazyProxy()
{
$container = new ContainerBuilder();
$container->register('foo', 'stdClass')->setLazy(true)->setPublic(true);
$container->register('bar', 'stdClass')->setLazy(true)->setPublic(true);
$container->compile();

$dumper = new PhpDumper($container);
$dumper->setProxyDumper(new \DummyProxyDumper());

$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dedup_lazy_proxy.php', $dumper->dump());
}

public function testLazyArgumentProvideGenerator()
{
require_once self::$fixturesPath.'/includes/classes.php';
Expand Down
Expand Up @@ -90,12 +90,12 @@ public function isProxyCandidate(Definition $definition)

public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null)
{
return " // lazy factory\n\n";
return " // lazy factory for {$definition->getClass()}\n\n";
}

public function getProxyCode(Definition $definition)
{
return "// proxy code\n";
return "// proxy code for {$definition->getClass()}\n";
}
}

Expand Down
@@ -0,0 +1,88 @@
<?php

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;

/**
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*
* @final since Symfony 3.3
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();

public function __construct()
{
$this->services = array();
$this->methodMap = array(
'bar' => 'getBarService',
'foo' => 'getFooService',
);

$this->aliases = array();
}

public function getRemovedIds()
{
return array(
'Psr\\Container\\ContainerInterface' => true,
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
);
}

public function compile()
{
throw new LogicException('You cannot compile a dumped container that was already compiled.');
}

public function isCompiled()
{
return true;
}

public function isFrozen()
{
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED);

return true;
}

protected function createProxy($class, \Closure $factory)
{
return $factory();
}

/**
* Gets the public 'bar' shared service.
*
* @return \stdClass
*/
protected function getBarService($lazyLoad = true)
{
// lazy factory for stdClass

return new \stdClass();
}

/**
* Gets the public 'foo' shared service.
*
* @return \stdClass
*/
protected function getFooService($lazyLoad = true)
{
// lazy factory for stdClass

return new \stdClass();
}
}

// proxy code for stdClass
Expand Up @@ -81,10 +81,10 @@ protected function getBarService()
*/
protected function getFooService($lazyLoad = true)
{
// lazy factory
// lazy factory for stdClass

return new \stdClass();
}
}

// proxy code
// proxy code for stdClass
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/CHANGELOG.md
Expand Up @@ -5,7 +5,7 @@ CHANGELOG
-----

* added orphaned events support to `EventDataCollector`
* `ExceptionListener` now logs and collects exceptions at priority `2048` (previously logged at `-128` and collected at `0`)
* `ExceptionListener` now logs exceptions at priority `0` (previously logged at `-128`)
* Deprecated `service:action` syntax with a single colon to reference controllers. Use `service::method` instead.
* Added the ability to profile individual argument value resolvers via the
`Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver`
Expand Down
Expand Up @@ -44,7 +44,6 @@ public function __construct($controller, LoggerInterface $logger = null, $debug
public function logKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $event->getRequest();

$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
}
Expand Down Expand Up @@ -90,7 +89,7 @@ public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array(
array('logKernelException', 2048),
array('logKernelException', 0),
array('onKernelException', -128),
),
);
Expand Down
Expand Up @@ -121,7 +121,7 @@ public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => array('onKernelResponse', -100),
KernelEvents::EXCEPTION => array('onKernelException', 2048),
KernelEvents::EXCEPTION => array('onKernelException', 0),
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
);
}
Expand Down
Expand Up @@ -376,10 +376,10 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
if ($hostRegex) {
preg_match('#^.\^(.*)\$.[a-zA-Z]*$#', $hostRegex, $rx);
$state->vars = array();
$hostRegex = '(?i:'.preg_replace_callback('#\?P<([^>]++)>#', $state->getVars, $rx[1]).')';
$hostRegex = '(?i:'.preg_replace_callback('#\?P<([^>]++)>#', $state->getVars, $rx[1]).')\.';
$state->hostVars = $state->vars;
} else {
$hostRegex = '[^/]*+';
$hostRegex = '(?:(?:[^.]*+\.)++)';
$state->hostVars = array();
}
$state->mark += strlen($rx = ($prev ? ')' : '')."|{$hostRegex}(?");
Expand All @@ -406,6 +406,7 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
$rx = ")$}{$modifiers}";
$code .= "\n .'{$rx}',";
$state->regex .= $rx;
$state->markTail = 0;

// if the regex is too large, throw a signaling exception to recompute with smaller chunk size
set_error_handler(function ($type, $message) { throw 0 === strpos($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message); });
Expand All @@ -427,7 +428,7 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
EOF;
}

$matchedPathinfo = $matchHost ? '$host.$pathinfo' : '$pathinfo';
$matchedPathinfo = $matchHost ? '$host.\'.\'.$pathinfo' : '$pathinfo';
unset($state->getVars);

return <<<EOF
Expand Down
Expand Up @@ -63,11 +63,9 @@ public function getRoutes(): array
*
* @param array|self $route
*/
public function addRoute(string $prefix, $route, string $staticPrefix = null)
public function addRoute(string $prefix, $route)
{
if (null === $staticPrefix) {
list($prefix, $staticPrefix) = $this->getCommonPrefix($prefix, $prefix);
}
list($prefix, $staticPrefix) = $this->getCommonPrefix($prefix, $prefix);

for ($i = \count($this->items) - 1; 0 <= $i; --$i) {
$item = $this->items[$i];
Expand Down Expand Up @@ -102,7 +100,7 @@ public function addRoute(string $prefix, $route, string $staticPrefix = null)

if ($item instanceof self && $this->prefixes[$i] === $commonPrefix) {
// the new route is a child of a previous one, let's nest it
$item->addRoute($prefix, $route, $staticPrefix);
$item->addRoute($prefix, $route);
} else {
// the new route and a previous one have a common prefix, let's merge them
$child = new self($commonPrefix);
Expand Down Expand Up @@ -176,7 +174,7 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
break;
}
$subPattern = substr($prefix, $i, $j - $i);
if ($prefix !== $anotherPrefix && !preg_match('{(?<!'.$subPattern.')}', '')) {
if ($prefix !== $anotherPrefix && !preg_match('/^\(\[[^\]]++\]\+\+\)$/', $subPattern) && !preg_match('{(?<!'.$subPattern.')}', '')) {
// sub-patterns of variable length are not considered as common prefixes because their greediness would break in-order matching
break;
}
Expand All @@ -187,6 +185,12 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
}
}
restore_error_handler();
if ($i < $end && 0b10 === (\ord($prefix[$i]) >> 6) && preg_match('//u', $prefix.' '.$anotherPrefix)) {
do {
// Prevent cutting in the middle of an UTF-8 characters
--$i;
} while (0b10 === (\ord($prefix[$i]) >> 6));
}

return array(substr($prefix, 0, $i), substr($prefix, 0, $staticLength ?? $i));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/RouteCompiler.php
Expand Up @@ -321,7 +321,7 @@ private static function transformCapturingGroupsToNonCapturings(string $regexp):
continue;
}
$regexp = substr_replace($regexp, '?:', $i, 0);
$i += 2;
++$i;
}

return $regexp;
Expand Down

0 comments on commit 169b13c

Please sign in to comment.