Skip to content

Commit 7ef3f38

Browse files
authored
Merge pull request #2 from iteman/symfony4-support
Symfony4 support
2 parents 9db2393 + c466247 commit 7ef3f38

26 files changed

+476
-25
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
/.buildpath
12
/.composer/
3+
/.idea/
24
/.php_cs.cache
5+
/.project
6+
/.settings/
37
/composer.lock
48
/composer.phar
59
/docker-compose.yml
10+
/docker/php.ini
611
/php-cs-fixer.phar
12+
/var/
713
/vendor/
14+
/tests/Feature/app/cache/*
15+
/tests/Feature/app/logs/*
16+
!/tests/Feature/app/cache/.gitkeep
17+
!/tests/Feature/app/logs/.gitkeep
18+
*.iml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PHPMentorsRouteBasedSessionConfigurationBundle
1+
# RouteBasedSessionConfigurationBundle
22

33
A Symfony bundle for session configuration based on route configuration
44

composer.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,30 @@
1212
],
1313
"require": {
1414
"php": ">=5.5.9",
15-
"symfony/config": "~2.8|~3.0",
16-
"symfony/dependency-injection": "~2.8|~3.0",
17-
"symfony/framework-bundle": "~2.8|~3.0",
18-
"symfony/http-foundation": "~2.8|~3.0",
19-
"symfony/http-kernel": "~2.8|~3.0",
20-
"symfony/routing": "~2.8|~3.0"
15+
"symfony/config": "~2.8|~3.0|~4.0",
16+
"symfony/dependency-injection": "~2.8|~3.0|~4.0",
17+
"symfony/framework-bundle": "~2.8|~3.0|~4.0",
18+
"symfony/http-foundation": "~2.8|~3.0|~4.0",
19+
"symfony/http-kernel": "~2.8|~3.0|~4.0",
20+
"symfony/routing": "~2.8|~3.0|~4.0"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "~4.0",
24+
"symfony/asset": "~2.8|~3.0|~4.0",
25+
"symfony/browser-kit": "~2.8|~3.0|~4.0",
26+
"symfony/filesystem": "~2.8|~3.0|~4.0",
27+
"symfony/http-foundation": "~2.8|~3.0|~4.0"
2128
},
2229
"autoload": {
2330
"psr-4": {
2431
"PHPMentors\\RouteBasedSessionConfigurationBundle\\": "src/"
2532
}
2633
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"PHPMentors\\RouteBasedSessionConfigurationBundle\\": "tests/"
37+
}
38+
},
2739
"extra": {
2840
"branch-alias": {
2941
"dev-master": "1.1.x-dev"

docker-compose.yml.dist

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
version: '2'
1+
version: '3'
22
services:
3-
app:
4-
container_name: "phpmentors.route-based-session-configuration-bundle.app"
5-
image: "phpmentors/php-app:php55"
6-
volumes:
7-
- ".:/var/app"
8-
environment:
9-
TERM: "xterm"
10-
TZ: "Asia/Tokyo"
11-
LANG: "ja_JP.UTF-8"
3+
app:
4+
build: docker
5+
network_mode: bridge
6+
volumes:
7+
- .:/var/app
8+
working_dir: /var/app
9+
environment:
10+
TZ: "Asia/Tokyo"
11+
LANG: "ja_JP.UTF-8"
12+
# PHP_INI: "docker/php.ini"

docker/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM phpmentors/php-app:php72
2+
3+
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
4+
RUN apt-get update -y
5+
RUN apt-get upgrade -y
6+
7+
# Other tools
8+
RUN apt-get install -y less unzip

docker/php.ini.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
;memory_limit=256M
2+
;xdebug.remote_autostart=on
3+
;xdebug.remote_port=9000
4+
;xdebug.remote_host=172.17.0.1

phpunit.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
backupGlobals="false"
6+
verbose="true"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Test Suite">
10+
<directory suffix="Test.php">./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
14+
<filter>
15+
<whitelist>
16+
<directory>./src</directory>
17+
</whitelist>
18+
</filter>
19+
</phpunit>

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
44
* All rights reserved.
55
*
6-
* This file is part of PHPMentorsRouteBasedSessionConfigurationBundle.
6+
* This file is part of RouteBasedSessionConfigurationBundle.
77
*
88
* This program and the accompanying materials are made available under
99
* the terms of the BSD 2-Clause License which accompanies this

src/DependencyInjection/PHPMentorsRouteBasedSessionConfigurationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
44
* All rights reserved.
55
*
6-
* This file is part of PHPMentorsRouteBasedSessionConfigurationBundle.
6+
* This file is part of RouteBasedSessionConfigurationBundle.
77
*
88
* This program and the accompanying materials are made available under
99
* the terms of the BSD 2-Clause License which accompanies this

src/EventListener/SessionConfigurationListener.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
44
* All rights reserved.
55
*
6-
* This file is part of PHPMentorsRouteBasedSessionConfigurationBundle.
6+
* This file is part of RouteBasedSessionConfigurationBundle.
77
*
88
* This program and the accompanying materials are made available under
99
* the terms of the BSD 2-Clause License which accompanies this
@@ -37,10 +37,7 @@ class SessionConfigurationListener
3737
public function __construct(RouterInterface $router, SessionStorageInterface $sessionStorage)
3838
{
3939
$this->router = $router;
40-
41-
if ($sessionStorage instanceof NativeSessionStorage) {
42-
$this->sessionStorage = $sessionStorage;
43-
}
40+
$this->sessionStorage = $sessionStorage;
4441
}
4542

4643
/**

src/PHPMentorsRouteBasedSessionConfigurationBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
44
* All rights reserved.
55
*
6-
* This file is part of PHPMentorsRouteBasedSessionConfigurationBundle.
6+
* This file is part of RouteBasedSessionConfigurationBundle.
77
*
88
* This program and the accompanying materials are made available under
99
* the terms of the BSD 2-Clause License which accompanies this

tests/Functional/AbstractTestCase.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/*
3+
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
4+
* All rights reserved.
5+
*
6+
* This file is part of RouteBasedSessionConfigurationBundle.
7+
*
8+
* This program and the accompanying materials are made available under
9+
* the terms of the BSD 2-Clause License which accompanies this
10+
* distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
11+
*/
12+
13+
namespace PHPMentors\RouteBasedSessionConfigurationBundle\Functional;
14+
15+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
16+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
17+
use Symfony\Component\Filesystem\Filesystem;
18+
19+
/**
20+
* @since Class available since Release 1.1.0
21+
*/
22+
abstract class AbstractTestCase extends WebTestCase
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected function setUp()
28+
{
29+
parent::setUp();
30+
31+
$_SERVER['KERNEL_DIR'] = __DIR__.'/app';
32+
require_once $_SERVER['KERNEL_DIR'].'/AppKernel.php';
33+
$_SERVER['KERNEL_CLASS'] = 'AppKernel';
34+
35+
if (self::$kernel !== null) {
36+
$this->removeCacheDir(self::$kernel->getCacheDir());
37+
}
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
protected function tearDown()
44+
{
45+
parent::tearDown();
46+
47+
if (self::$kernel !== null) {
48+
$this->removeCacheDir(self::$kernel->getCacheDir());
49+
}
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
protected static function createKernel(array $options = array())
56+
{
57+
$kernel = KernelTestCase::createKernel($options);
58+
if (array_key_exists('config', $options)) {
59+
$kernel->setConfig($options['config']);
60+
}
61+
62+
return $kernel;
63+
}
64+
65+
protected function removeCacheDir($cacheDir)
66+
{
67+
$fileSystem = new Filesystem();
68+
$fileSystem->remove($cacheDir);
69+
}
70+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*
3+
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
4+
* All rights reserved.
5+
*
6+
* This file is part of RouteBasedSessionConfigurationBundle.
7+
*
8+
* This program and the accompanying materials are made available under
9+
* the terms of the BSD 2-Clause License which accompanies this
10+
* distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
11+
*/
12+
13+
namespace PHPMentors\RouteBasedSessionConfigurationBundle\Functional\Bundle\TestBundle\Controller;
14+
15+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16+
use Symfony\Component\HttpFoundation\JsonResponse;
17+
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
19+
20+
/**
21+
* @since Class available since Release 1.1.0
22+
*/
23+
class RuntimeSessionConfigurationController extends Controller
24+
{
25+
private $sessionStorage;
26+
27+
public function __construct(SessionStorageInterface $sessionStorage)
28+
{
29+
$this->sessionStorage = $sessionStorage;
30+
}
31+
32+
/**
33+
* @param Request $request
34+
*
35+
* @return JsonResponse
36+
*/
37+
public function indexAction(Request $request)
38+
{
39+
return new JsonResponse(array(
40+
'session' => array(
41+
'options' => $this->sessionStorage->getOptions()
42+
)
43+
));
44+
}
45+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/*
3+
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
4+
* All rights reserved.
5+
*
6+
* This file is part of RouteBasedSessionConfigurationBundle.
7+
*
8+
* This program and the accompanying materials are made available under
9+
* the terms of the BSD 2-Clause License which accompanies this
10+
* distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
11+
*/
12+
13+
namespace PHPMentors\RouteBasedSessionConfigurationBundle\Functional\Bundle\TestBundle\DependencyInjection\Compiler;
14+
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
18+
/**
19+
* @since Class available since Release 1.1.0
20+
*/
21+
class ReplaceSessionStorageDefinitionPass implements CompilerPassInterface
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function process(ContainerBuilder $container)
27+
{
28+
if ($container->hasDefinition('session.storage.mock_file')) {
29+
$container->getDefinition('phpmentors_route_based_session_configuration_test.mock_file_session_storage')->setArguments($container->getDefinition('session.storage.mock_file')->getArguments());
30+
$container->setAlias('session.storage.mock_file', 'phpmentors_route_based_session_configuration_test.mock_file_session_storage');
31+
}
32+
}
33+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_runtime_session_configuration_index:
2+
path: /runtime-session-configuration/
3+
defaults: { _controller: "phpmentors_route_based_session_configuration_test.runtime_session_configuration_controller:indexAction" }
4+
methods: [GET]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_runtime_session_configuration_index_admin:
2+
path: /runtime-session-configuration/
3+
defaults: { _controller: "phpmentors_route_based_session_configuration_test.runtime_session_configuration_controller:indexAction" }
4+
methods: [GET]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
4+
* All rights reserved.
5+
*
6+
* This file is part of RouteBasedSessionConfigurationBundle.
7+
*
8+
* This program and the accompanying materials are made available under
9+
* the terms of the BSD 2-Clause License which accompanies this
10+
* distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
11+
*/
12+
13+
namespace PHPMentors\RouteBasedSessionConfigurationBundle\Functional\Bundle\TestBundle\Session\Storage;
14+
15+
/**
16+
* @since Class available since Release 1.1.0
17+
*/
18+
class MockFileSessionStorage extends \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage
19+
{
20+
private $options = array();
21+
22+
public function setOptions(array $options)
23+
{
24+
$this->options = $options;
25+
}
26+
27+
public function getOptions()
28+
{
29+
return $this->options;
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Copyright (c) KUBO Atsuhiro <kubo@iteman.jp>,
4+
* All rights reserved.
5+
*
6+
* This file is part of RouteBasedSessionConfigurationBundle.
7+
*
8+
* This program and the accompanying materials are made available under
9+
* the terms of the BSD 2-Clause License which accompanies this
10+
* distribution, and is available at http://opensource.org/licenses/BSD-2-Clause
11+
*/
12+
13+
namespace PHPMentors\RouteBasedSessionConfigurationBundle\Functional\Bundle\TestBundle;
14+
15+
use PHPMentors\RouteBasedSessionConfigurationBundle\Functional\Bundle\TestBundle\DependencyInjection\Compiler\ReplaceSessionStorageDefinitionPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\HttpKernel\Bundle\Bundle;
18+
19+
/**
20+
* @since Class available since Release 1.1.0
21+
*/
22+
class TestBundle extends Bundle
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function build(ContainerBuilder $container)
28+
{
29+
$container->addCompilerPass(new ReplaceSessionStorageDefinitionPass());
30+
}
31+
}

0 commit comments

Comments
 (0)