Merge branch '4.0'
* 4.0: fix merge Fix lock strategy tests [travis] cache compiled php extensions fix merge Allow remember-me factory creation when multiple user providers are configured. Add tests for glob loaders Improve assertions [DI][Routing] Fix tracking of globbed resources [Config] Handle Service/EventSubscriberInterface in ReflectionClassResource always call the parent class' constructor
This commit is contained in:
commit
302f33702d
22
.travis.yml
22
.travis.yml
@ -32,6 +32,7 @@ cache:
|
||||
directories:
|
||||
- .phpunit
|
||||
- php-$MIN_PHP
|
||||
- php-ext
|
||||
|
||||
services:
|
||||
- memcached
|
||||
@ -97,6 +98,23 @@ before_install:
|
||||
echo extension = redis.so >> $INI
|
||||
echo extension = memcached.so >> $INI
|
||||
|
||||
# tpecl is a helper to compile and cache php extensions
|
||||
tpecl () {
|
||||
local ext_name=$1
|
||||
local ext_so=$2
|
||||
local ext_dir=$(php -r "echo ini_get('extension_dir');")
|
||||
local ext_cache=~/php-ext/$(basename $ext_dir)/$ext_name
|
||||
|
||||
if [[ -e $ext_cache/$ext_so ]]; then
|
||||
echo extension = $ext_cache/$ext_so >> $INI
|
||||
else
|
||||
mkdir -p $ext_cache
|
||||
echo yes | pecl install -f $ext_name &&
|
||||
cp $ext_dir/$ext_so $ext_cache
|
||||
fi
|
||||
}
|
||||
export -f tpecl
|
||||
|
||||
# Matrix lines for intermediate PHP versions are skipped for pull requests
|
||||
if [[ ! $deps && ! $PHP = $MIN_PHP && $TRAVIS_PULL_REQUEST != false ]]; then
|
||||
deps=skip
|
||||
@ -115,8 +133,8 @@ before_install:
|
||||
- |
|
||||
# Install extra PHP extensions
|
||||
if [[ ! $skip ]]; then
|
||||
tfold ext.apcu5 'echo yes | pecl install -f apcu-5.1.6'
|
||||
tfold ext.mongodb pecl install -f mongodb-1.4.0RC1
|
||||
tfold ext.apcu tpecl apcu-5.1.6 apcu.so
|
||||
tfold ext.mongodb tpecl mongodb-1.4.0RC1 mongodb.so
|
||||
fi
|
||||
|
||||
- |
|
||||
|
@ -40,7 +40,7 @@ class ManagerRegistryTest extends TestCase
|
||||
$registry->resetManager();
|
||||
|
||||
$this->assertSame($foo, $container->get('foo'));
|
||||
$this->assertFalse(isset($foo->bar));
|
||||
$this->assertObjectNotHasAttribute('bar', $foo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ class LoggerTest extends TestCase
|
||||
$logger = new Logger(__METHOD__, array($handler), array($processor));
|
||||
|
||||
$this->assertTrue($logger->error('error message'));
|
||||
$this->assertSame(1, count($logger->getLogs()));
|
||||
$this->assertCount(1, $logger->getLogs());
|
||||
}
|
||||
|
||||
public function testCountErrorsWithDebugProcessor()
|
||||
|
@ -30,7 +30,7 @@
|
||||
<argument type="service" id="file_locator" />
|
||||
</service>
|
||||
|
||||
<service id="routing.loader.glob" class="Symfony\Component\Config\Loader\GlobFileLoader">
|
||||
<service id="routing.loader.glob" class="Symfony\Component\Routing\Loader\GlobFileLoader">
|
||||
<tag name="routing.loader" />
|
||||
<argument type="service" id="file_locator" />
|
||||
</service>
|
||||
|
@ -1134,7 +1134,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
$this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id));
|
||||
|
||||
$tag = $poolDefinition->getTag('cache.pool');
|
||||
$this->assertTrue(isset($tag[0]['default_lifetime']), 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
|
||||
$this->assertArrayHasKey('default_lifetime', $tag[0], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
|
||||
$this->assertSame($defaultLifetime, $tag[0]['default_lifetime'], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
|
||||
|
||||
$parentDefinition = $poolDefinition;
|
||||
|
@ -27,7 +27,7 @@
|
||||
"symfony/polyfill-mbstring": "~1.0",
|
||||
"symfony/filesystem": "~3.4|~4.0",
|
||||
"symfony/finder": "~3.4|~4.0",
|
||||
"symfony/routing": "~3.4|~4.0"
|
||||
"symfony/routing": "^3.4.5|^4.0.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/cache": "~1.0",
|
||||
|
@ -415,6 +415,9 @@ class SecurityExtension extends Extension
|
||||
throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall[$key]['provider']));
|
||||
}
|
||||
$userProvider = $providerIds[$normalizedName];
|
||||
} elseif ('remember_me' === $key) {
|
||||
// RememberMeFactory will use the firewall secret when created
|
||||
$userProvider = null;
|
||||
} elseif ($defaultProvider) {
|
||||
$userProvider = $defaultProvider;
|
||||
} else {
|
||||
|
@ -186,6 +186,28 @@ class SecurityExtensionTest extends TestCase
|
||||
$container->compile();
|
||||
}
|
||||
|
||||
public function testPerListenerProviderWithRememberMe()
|
||||
{
|
||||
$container = $this->getRawContainer();
|
||||
$container->loadFromExtension('security', array(
|
||||
'providers' => array(
|
||||
'first' => array('id' => 'foo'),
|
||||
'second' => array('id' => 'bar'),
|
||||
),
|
||||
|
||||
'firewalls' => array(
|
||||
'default' => array(
|
||||
'form_login' => array('provider' => 'second'),
|
||||
'logout_on_user_change' => true,
|
||||
'remember_me' => array('secret' => 'baz'),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$container->compile();
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
protected function getRawContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -53,7 +53,7 @@ class NullAdapterTest extends TestCase
|
||||
$itemKey = $item->getKey();
|
||||
|
||||
$this->assertEquals($itemKey, $key, 'Keys must be preserved when fetching multiple items');
|
||||
$this->assertTrue(in_array($key, $keys), 'Cache key can not change.');
|
||||
$this->assertContains($key, $keys, 'Cache key can not change.');
|
||||
$this->assertFalse($item->isHit());
|
||||
|
||||
// Remove $key for $keys
|
||||
|
@ -43,7 +43,7 @@ class ProxyAdapterTest extends AdapterTestCase
|
||||
|
||||
$proxyItem = $pool->getItem('foo');
|
||||
|
||||
$this->assertFalse($proxyItem === $item);
|
||||
$this->assertNotSame($item, $proxyItem);
|
||||
$pool->save($proxyItem->set('bar'));
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class NullCacheTest extends TestCase
|
||||
$count = 0;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
$this->assertTrue(in_array($key, $keys), 'Cache key can not change.');
|
||||
$this->assertContains($key, $keys, 'Cache key can not change.');
|
||||
$this->assertSame($default, $item);
|
||||
|
||||
// Remove $key for $keys
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Config\Resource;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
@ -114,7 +117,9 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
|
||||
private function generateSignature(\ReflectionClass $class)
|
||||
{
|
||||
yield $class->getDocComment().$class->getModifiers();
|
||||
yield $class->getDocComment();
|
||||
yield (int) $class->isFinal();
|
||||
yield (int) $class->isAbstract();
|
||||
|
||||
if ($class->isTrait()) {
|
||||
yield print_r(class_uses($class->name), true);
|
||||
@ -142,5 +147,15 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
}
|
||||
yield print_r($defaults, true);
|
||||
}
|
||||
|
||||
if ($class->isSubclassOf(EventSubscriberInterface::class)) {
|
||||
yield EventSubscriberInterface::class;
|
||||
yield print_r(\call_user_func(array($class->name, 'getSubscribedEvents')), true);
|
||||
}
|
||||
|
||||
if ($class->isSubclassOf(ServiceSubscriberInterface::class)) {
|
||||
yield ServiceSubscriberInterface::class;
|
||||
yield print_r(\call_user_func(array($class->name, 'getSubscribedServices')), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ namespace Symfony\Component\Config\Tests\Resource;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Resource\ReflectionClassResource;
|
||||
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class ReflectionClassResourceTest extends TestCase
|
||||
{
|
||||
@ -100,7 +102,7 @@ EOPHP;
|
||||
$signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class))));
|
||||
|
||||
if ($changeExpected) {
|
||||
$this->assertTrue($expectedSignature !== $signature);
|
||||
$this->assertNotSame($expectedSignature, $signature);
|
||||
} else {
|
||||
$this->assertSame($expectedSignature, $signature);
|
||||
}
|
||||
@ -132,8 +134,52 @@ EOPHP;
|
||||
yield array(0, 14, '/** priv docblock */');
|
||||
yield array(0, 15, '');
|
||||
}
|
||||
|
||||
public function testEventSubscriber()
|
||||
{
|
||||
$res = new ReflectionClassResource(new \ReflectionClass(TestEventSubscriber::class));
|
||||
$this->assertTrue($res->isFresh(0));
|
||||
|
||||
TestEventSubscriber::$subscribedEvents = array(123);
|
||||
$this->assertFalse($res->isFresh(0));
|
||||
|
||||
$res = new ReflectionClassResource(new \ReflectionClass(TestEventSubscriber::class));
|
||||
$this->assertTrue($res->isFresh(0));
|
||||
}
|
||||
|
||||
public function testServiceSubscriber()
|
||||
{
|
||||
$res = new ReflectionClassResource(new \ReflectionClass(TestServiceSubscriber::class));
|
||||
$this->assertTrue($res->isFresh(0));
|
||||
|
||||
TestServiceSubscriber::$subscribedServices = array(123);
|
||||
$this->assertFalse($res->isFresh(0));
|
||||
|
||||
$res = new ReflectionClassResource(new \ReflectionClass(TestServiceSubscriber::class));
|
||||
$this->assertTrue($res->isFresh(0));
|
||||
}
|
||||
}
|
||||
|
||||
interface DummyInterface
|
||||
{
|
||||
}
|
||||
|
||||
class TestEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public static $subscribedEvents = array();
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return self::$subscribedEvents;
|
||||
}
|
||||
}
|
||||
|
||||
class TestServiceSubscriber implements ServiceSubscriberInterface
|
||||
{
|
||||
public static $subscribedServices = array();
|
||||
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return self::$subscribedServices;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
"symfony/filesystem": "~3.4|~4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"symfony/event-dispatcher": "~3.4|~4.0",
|
||||
"symfony/finder": "~3.4|~4.0",
|
||||
"symfony/yaml": "~3.4|~4.0"
|
||||
},
|
||||
|
@ -56,14 +56,14 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
|
||||
}
|
||||
$class = $value->getClass();
|
||||
|
||||
if (!is_subclass_of($class, ServiceSubscriberInterface::class)) {
|
||||
if (!class_exists($class, false)) {
|
||||
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $this->currentId));
|
||||
}
|
||||
|
||||
if (!$r = $this->container->getReflectionClass($class)) {
|
||||
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $this->currentId));
|
||||
}
|
||||
if (!$r->isSubclassOf(ServiceSubscriberInterface::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $this->currentId, ServiceSubscriberInterface::class));
|
||||
}
|
||||
$this->container->addObjectResource($class);
|
||||
$class = $r->name;
|
||||
|
||||
$subscriberMap = array();
|
||||
$declaringClass = (new \ReflectionMethod($class, 'getSubscribedServices'))->class;
|
||||
|
||||
|
@ -129,6 +129,11 @@ class PhpDumper extends Dumper
|
||||
|
||||
if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {
|
||||
$baseClass = sprintf('%s\%s', $options['namespace'] ? '\\'.$options['namespace'] : '', $baseClass);
|
||||
$baseClassWithNamespace = $baseClass;
|
||||
} elseif ('Container' === $baseClass) {
|
||||
$baseClassWithNamespace = Container::class;
|
||||
} else {
|
||||
$baseClassWithNamespace = $baseClass;
|
||||
}
|
||||
|
||||
$this->initializeMethodNamesMap('Container' === $baseClass ? Container::class : $baseClass);
|
||||
@ -170,7 +175,7 @@ class PhpDumper extends Dumper
|
||||
}
|
||||
|
||||
$code =
|
||||
$this->startClass($options['class'], $baseClass).
|
||||
$this->startClass($options['class'], $baseClass, $baseClassWithNamespace).
|
||||
$this->addServices().
|
||||
$this->addDefaultParametersMethod().
|
||||
$this->endClass()
|
||||
@ -868,7 +873,7 @@ EOF;
|
||||
return $return.sprintf("new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments));
|
||||
}
|
||||
|
||||
private function startClass(string $class, string $baseClass): string
|
||||
private function startClass(string $class, string $baseClass, string $baseClassWithNamespace): string
|
||||
{
|
||||
$namespaceLine = !$this->asFiles && $this->namespace ? "\nnamespace {$this->namespace};\n" : '';
|
||||
|
||||
@ -919,6 +924,14 @@ EOF;
|
||||
$code .= " \$this->buildParameters = \$buildParameters;\n";
|
||||
}
|
||||
|
||||
if (Container::class !== $baseClassWithNamespace) {
|
||||
$r = $this->container->getReflectionClass($baseClassWithNamespace, false);
|
||||
|
||||
if (null !== $r && (null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) {
|
||||
$code .= " parent::__construct();\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->container->getParameterBag()->all()) {
|
||||
$code .= " \$this->parameters = \$this->getDefaultParameters();\n\n";
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?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\Loader;
|
||||
|
||||
/**
|
||||
* GlobFileLoader loads files from a glob pattern.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class GlobFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $type = null)
|
||||
{
|
||||
foreach ($this->glob($resource, false, $globResource) as $path => $info) {
|
||||
$this->import($path);
|
||||
}
|
||||
|
||||
$this->container->addResource($globResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return 'glob' === $type;
|
||||
}
|
||||
}
|
@ -106,6 +106,46 @@ class PhpDumperTest extends TestCase
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services12.php', $dumper->dump(array('file' => __FILE__)), '->dump() dumps __DIR__ relative strings');
|
||||
}
|
||||
|
||||
public function testDumpCustomContainerClassWithoutConstructor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->compile();
|
||||
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_without_constructor.php', $dumper->dump(array('base_class' => 'NoConstructorContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container')));
|
||||
}
|
||||
|
||||
public function testDumpCustomContainerClassConstructorWithoutArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->compile();
|
||||
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_constructor_without_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithoutArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container')));
|
||||
}
|
||||
|
||||
public function testDumpCustomContainerClassWithOptionalArgumentLessConstructor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->compile();
|
||||
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_optional_constructor_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithOptionalArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container')));
|
||||
}
|
||||
|
||||
public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->compile();
|
||||
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_mandatory_constructor_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithMandatoryArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidParameters
|
||||
* @expectedException \InvalidArgumentException
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class ConstructorWithMandatoryArgumentsContainer
|
||||
{
|
||||
public function __construct($mandatoryArgument)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class ConstructorWithOptionalArgumentsContainer
|
||||
{
|
||||
public function __construct($optionalArgument = 'foo')
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class ConstructorWithoutArgumentsContainer
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
class NoConstructorContainer
|
||||
{
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
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 \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\ConstructorWithoutArgumentsContainer
|
||||
{
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->services = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
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 \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\ConstructorWithMandatoryArgumentsContainer
|
||||
{
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->services = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
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 \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\ConstructorWithOptionalArgumentsContainer
|
||||
{
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->services = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
|
||||
|
||||
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 \Symfony\Component\DependencyInjection\Tests\Fixtures\Container\NoConstructorContainer
|
||||
{
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->services = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?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\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Resource\GlobResource;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class GlobFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new GlobFileLoader(new ContainerBuilder(), new FileLocator());
|
||||
|
||||
$this->assertTrue($loader->supports('any-path', 'glob'), '->supports() returns true if the resource has the glob type');
|
||||
$this->assertFalse($loader->supports('any-path'), '->supports() returns false if the resource is not of glob type');
|
||||
}
|
||||
|
||||
public function testLoadAddsTheGlobResourceToTheContainer()
|
||||
{
|
||||
$loader = new GlobFileLoaderWithoutImport($container = new ContainerBuilder(), new FileLocator());
|
||||
$loader->load(__DIR__.'/../Fixtures/config/*');
|
||||
|
||||
$this->assertEquals(new GlobResource(__DIR__.'/../Fixtures/config', '/*', false), $container->getResources()[1]);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobFileLoaderWithoutImport extends GlobFileLoader
|
||||
{
|
||||
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
||||
{
|
||||
}
|
||||
}
|
@ -88,17 +88,15 @@ class RegisterListenersPass implements CompilerPassInterface
|
||||
$def = $container->getDefinition($id);
|
||||
|
||||
// We must assume that the class value has been correctly filled, even if the service is created by a factory
|
||||
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
||||
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
|
||||
$class = $def->getClass();
|
||||
|
||||
if (!is_subclass_of($class, $interface)) {
|
||||
if (!class_exists($class, false)) {
|
||||
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
|
||||
if (!$r = $container->getReflectionClass($class)) {
|
||||
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
|
||||
}
|
||||
$container->addObjectResource($class);
|
||||
if (!$r->isSubclassOf(EventSubscriberInterface::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, EventSubscriberInterface::class));
|
||||
}
|
||||
$class = $r->name;
|
||||
|
||||
ExtractingEventDispatcher::$subscriber = $class;
|
||||
$extractingDispatcher->addSubscriber($extractingDispatcher);
|
||||
|
@ -690,9 +690,9 @@ class FormDataCollectorTest extends TestCase
|
||||
|
||||
$this->assertTrue($formData['has_children_error']);
|
||||
$this->assertTrue($child1Data['has_children_error']);
|
||||
$this->assertFalse(isset($child11Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
|
||||
$this->assertArrayNotHasKey('has_children_error', $child11Data, 'The leaf data does not contains "has_children_error" property.');
|
||||
$this->assertFalse($child2Data['has_children_error']);
|
||||
$this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
|
||||
$this->assertArrayNotHasKey('has_children_error', $child21Data, 'The leaf data does not contains "has_children_error" property.');
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
|
@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
@ -31,7 +32,6 @@ use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
use Symfony\Component\HttpKernel\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
|
||||
use Symfony\Component\Config\Loader\GlobFileLoader;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
@ -721,7 +721,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
new YamlFileLoader($container, $locator),
|
||||
new IniFileLoader($container, $locator),
|
||||
new PhpFileLoader($container, $locator),
|
||||
new GlobFileLoader($locator),
|
||||
new GlobFileLoader($container, $locator),
|
||||
new DirectoryLoader($container, $locator),
|
||||
new ClosureLoader($container),
|
||||
));
|
||||
|
@ -537,14 +537,14 @@ EOF;
|
||||
$kernel = new CustomProjectDirKernel();
|
||||
$kernel->boot();
|
||||
|
||||
$this->assertSame($containerClass, get_class($kernel->getContainer()));
|
||||
$this->assertInstanceOf($containerClass, $kernel->getContainer());
|
||||
$this->assertFileExists($containerFile);
|
||||
unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta');
|
||||
|
||||
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
|
||||
$kernel->boot();
|
||||
|
||||
$this->assertTrue(get_class($kernel->getContainer()) !== $containerClass);
|
||||
$this->assertNotInstanceOf($containerClass, $kernel->getContainer());
|
||||
$this->assertFileExists($containerFile);
|
||||
$this->assertFileExists(dirname($containerFile).'.legacy');
|
||||
}
|
||||
|
@ -83,22 +83,22 @@ class FileProfilerStorageTest extends TestCase
|
||||
$profile = new Profile('simple_quote');
|
||||
$profile->setUrl('http://foo.bar/\'');
|
||||
$this->storage->write($profile);
|
||||
$this->assertTrue(false !== $this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
|
||||
$this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL');
|
||||
|
||||
$profile = new Profile('double_quote');
|
||||
$profile->setUrl('http://foo.bar/"');
|
||||
$this->storage->write($profile);
|
||||
$this->assertTrue(false !== $this->storage->read('double_quote'), '->write() accepts double quotes in URL');
|
||||
$this->assertNotFalse($this->storage->read('double_quote'), '->write() accepts double quotes in URL');
|
||||
|
||||
$profile = new Profile('backslash');
|
||||
$profile->setUrl('http://foo.bar/\\');
|
||||
$this->storage->write($profile);
|
||||
$this->assertTrue(false !== $this->storage->read('backslash'), '->write() accepts backslash in URL');
|
||||
$this->assertNotFalse($this->storage->read('backslash'), '->write() accepts backslash in URL');
|
||||
|
||||
$profile = new Profile('comma');
|
||||
$profile->setUrl('http://foo.bar/,');
|
||||
$this->storage->write($profile);
|
||||
$this->assertTrue(false !== $this->storage->read('comma'), '->write() accepts comma in URL');
|
||||
$this->assertNotFalse($this->storage->read('comma'), '->write() accepts comma in URL');
|
||||
}
|
||||
|
||||
public function testStoreDuplicateToken()
|
||||
@ -247,7 +247,7 @@ class FileProfilerStorageTest extends TestCase
|
||||
$profile->setMethod('GET');
|
||||
$this->storage->write($profile);
|
||||
|
||||
$this->assertTrue(false !== $this->storage->read('token1'));
|
||||
$this->assertNotFalse($this->storage->read('token1'));
|
||||
$this->assertCount(1, $this->storage->find('127.0.0.1', '', 10, 'GET'));
|
||||
|
||||
$profile = new Profile('token2');
|
||||
@ -256,7 +256,7 @@ class FileProfilerStorageTest extends TestCase
|
||||
$profile->setMethod('GET');
|
||||
$this->storage->write($profile);
|
||||
|
||||
$this->assertTrue(false !== $this->storage->read('token2'));
|
||||
$this->assertNotFalse($this->storage->read('token2'));
|
||||
$this->assertCount(2, $this->storage->find('127.0.0.1', '', 10, 'GET'));
|
||||
|
||||
$this->storage->purge();
|
||||
|
@ -27,7 +27,7 @@
|
||||
"symfony/config": "~3.4|~4.0",
|
||||
"symfony/console": "~3.4|~4.0",
|
||||
"symfony/css-selector": "~3.4|~4.0",
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"symfony/dependency-injection": "^3.4.5|^4.0.5",
|
||||
"symfony/dom-crawler": "~3.4|~4.0",
|
||||
"symfony/expression-language": "~3.4|~4.0",
|
||||
"symfony/finder": "~3.4|~4.0",
|
||||
@ -44,7 +44,7 @@
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/config": "<3.4",
|
||||
"symfony/dependency-injection": "<3.4",
|
||||
"symfony/dependency-injection": "<3.4.5|<4.0.5,>=4",
|
||||
"symfony/var-dumper": "<3.4",
|
||||
"twig/twig": "<1.34|<2.4,>=2"
|
||||
},
|
||||
|
@ -82,7 +82,7 @@ class ConsensusStrategyTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideIndeterminate
|
||||
*/
|
||||
public function canBeMet($success, $failure, $total, $isMet)
|
||||
public function testCanBeMet($success, $failure, $total, $isMet)
|
||||
{
|
||||
$this->assertSame($isMet, $this->strategy->canBeMet($failure, $total));
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class UnanimousStrategyTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideIndeterminate
|
||||
*/
|
||||
public function canBeMet($success, $failure, $total, $isMet)
|
||||
public function testCanBeMet($success, $failure, $total, $isMet)
|
||||
{
|
||||
$this->assertSame($isMet, $this->strategy->canBeMet($failure, $total));
|
||||
}
|
||||
|
47
src/Symfony/Component/Routing/Loader/GlobFileLoader.php
Normal file
47
src/Symfony/Component/Routing/Loader/GlobFileLoader.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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\Routing\Loader;
|
||||
|
||||
use Symfony\Component\Config\Loader\FileLoader;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* GlobFileLoader loads files from a glob pattern.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class GlobFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($resource, $type = null)
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
|
||||
foreach ($this->glob($resource, false, $globResource) as $path => $info) {
|
||||
$collection->addCollection($this->import($path));
|
||||
}
|
||||
|
||||
$collection->addResource($globResource);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return 'glob' === $type;
|
||||
}
|
||||
}
|
@ -104,7 +104,6 @@ EOF;
|
||||
\$context = \$this->context;
|
||||
\$request = \$this->request ?: \$this->createRequest(\$pathinfo);
|
||||
\$requestMethod = \$canonicalMethod = \$context->getMethod();
|
||||
\$scheme = \$context->getScheme();
|
||||
|
||||
if ('HEAD' === \$requestMethod) {
|
||||
\$canonicalMethod = 'GET';
|
||||
@ -362,7 +361,7 @@ EOF;
|
||||
$code .= <<<EOF
|
||||
if ('/' === substr(\$pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array(\$this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== \$canonicalMethod) {
|
||||
goto $gotoname;
|
||||
} else {
|
||||
return array_replace(\$ret, \$this->redirect(\$rawPathinfo.'/', '$name'));
|
||||
@ -379,7 +378,7 @@ EOF;
|
||||
$schemes = str_replace("\n", '', var_export(array_flip($schemes), true));
|
||||
$code .= <<<EOF
|
||||
\$requiredSchemes = $schemes;
|
||||
if (!isset(\$requiredSchemes[\$scheme])) {
|
||||
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
|
||||
return array_replace(\$ret, \$this->redirect(\$rawPathinfo, '$name', key(\$requiredSchemes)));
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
@ -84,7 +83,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'baz3');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_baz3;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'baz3'));
|
||||
@ -101,7 +100,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_baz4;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'baz4'));
|
||||
@ -190,7 +189,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'hey');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_hey;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'hey'));
|
||||
@ -340,7 +339,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
if ('/secure' === $pathinfo) {
|
||||
$ret = array('_route' => 'secure');
|
||||
$requiredSchemes = array ( 'https' => 0,);
|
||||
if (!isset($requiredSchemes[$scheme])) {
|
||||
if (!isset($requiredSchemes[$context->getScheme()])) {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo, 'secure', key($requiredSchemes)));
|
||||
}
|
||||
|
||||
@ -351,7 +350,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
if ('/nonsecure' === $pathinfo) {
|
||||
$ret = array('_route' => 'nonsecure');
|
||||
$requiredSchemes = array ( 'http' => 0,);
|
||||
if (!isset($requiredSchemes[$scheme])) {
|
||||
if (!isset($requiredSchemes[$context->getScheme()])) {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo, 'nonsecure', key($requiredSchemes)));
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
@ -58,7 +57,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'a_fourth');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_a_fourth;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fourth'));
|
||||
@ -73,7 +72,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'a_fifth');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_a_fifth;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fifth'));
|
||||
@ -88,7 +87,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'a_sixth');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_a_sixth;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_sixth'));
|
||||
@ -111,7 +110,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'nested_a');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_nested_a;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_a'));
|
||||
@ -126,7 +125,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'nested_b');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_nested_b;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_b'));
|
||||
@ -141,7 +140,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'nested_c');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_nested_c;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_c'));
|
||||
@ -159,7 +158,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'slashed_a');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_slashed_a;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_a'));
|
||||
@ -174,7 +173,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'slashed_b');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_slashed_b;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_b'));
|
||||
@ -189,7 +188,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'slashed_c');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_slashed_c;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_c'));
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
|
@ -23,7 +23,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$context = $this->context;
|
||||
$request = $this->request ?: $this->createRequest($pathinfo);
|
||||
$requestMethod = $canonicalMethod = $context->getMethod();
|
||||
$scheme = $context->getScheme();
|
||||
|
||||
if ('HEAD' === $requestMethod) {
|
||||
$canonicalMethod = 'GET';
|
||||
@ -35,7 +34,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'simple_trailing_slash_no_methods');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_simple_trailing_slash_no_methods;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'simple_trailing_slash_no_methods'));
|
||||
@ -55,7 +54,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'simple_trailing_slash_GET_method');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_simple_trailing_slash_GET_method;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'simple_trailing_slash_GET_method'));
|
||||
@ -75,7 +74,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = array('_route' => 'simple_trailing_slash_HEAD_method');
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_simple_trailing_slash_HEAD_method;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'simple_trailing_slash_HEAD_method'));
|
||||
@ -104,7 +103,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ());
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_regex_trailing_slash_no_methods;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'regex_trailing_slash_no_methods'));
|
||||
@ -124,7 +123,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_regex_trailing_slash_GET_method;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'regex_trailing_slash_GET_method'));
|
||||
@ -144,7 +143,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
|
||||
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
|
||||
if ('/' === substr($pathinfo, -1)) {
|
||||
// no-op
|
||||
} elseif (!in_array($this->context->getMethod(), array('HEAD', 'GET'))) {
|
||||
} elseif ('GET' !== $canonicalMethod) {
|
||||
goto not_regex_trailing_slash_HEAD_method;
|
||||
} else {
|
||||
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'regex_trailing_slash_HEAD_method'));
|
||||
|
@ -0,0 +1,45 @@
|
||||
<?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\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Resource\GlobResource;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\GlobFileLoader;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class GlobFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new GlobFileLoader(new FileLocator());
|
||||
|
||||
$this->assertTrue($loader->supports('any-path', 'glob'), '->supports() returns true if the resource has the glob type');
|
||||
$this->assertFalse($loader->supports('any-path'), '->supports() returns false if the resource is not of glob type');
|
||||
}
|
||||
|
||||
public function testLoadAddsTheGlobResourceToTheContainer()
|
||||
{
|
||||
$loader = new GlobFileLoaderWithoutImport(new FileLocator());
|
||||
$collection = $loader->load(__DIR__.'/../Fixtures/directory/*.yml');
|
||||
|
||||
$this->assertEquals(new GlobResource(__DIR__.'/../Fixtures/directory', '/*.yml', false), $collection->getResources()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobFileLoaderWithoutImport extends GlobFileLoader
|
||||
{
|
||||
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
||||
{
|
||||
return new RouteCollection();
|
||||
}
|
||||
}
|
@ -435,7 +435,7 @@ class UrlMatcherTest extends TestCase
|
||||
{
|
||||
$coll = new RouteCollection();
|
||||
|
||||
$matcher = new UrlMatcher($coll, new RequestContext());
|
||||
$matcher = $this->getUrlMatcher($coll);
|
||||
$matcher->match('/');
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ class RouteCollectionBuilderTest extends TestCase
|
||||
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
|
||||
$routes = $routeCollectionBuilder->build()->all();
|
||||
|
||||
$this->assertEquals(2, count($routes));
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/other/a', $routes['a']->getPath());
|
||||
$this->assertEquals('/other/b', $routes['b']->getPath());
|
||||
}
|
||||
|
Reference in New Issue
Block a user