Skip to content

Commit 854d26a

Browse files
committed
initial commit
1 parent 32e97f4 commit 854d26a

5 files changed

Lines changed: 215 additions & 0 deletions

File tree

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Composer template
3+
composer.phar
4+
/vendor/
5+
6+
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
7+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
8+
composer.lock
9+
10+
### JetBrains template
11+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
12+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
13+
14+
# User-specific stuff:
15+
.idea
16+
17+
## File-based project format:
18+
*.iws
19+
20+
## Plugin-specific files:
21+
22+
# IntelliJ
23+
/out/
24+
25+
# mpeltonen/sbt-idea plugin
26+
.idea_modules/
27+
28+
# JIRA plugin
29+
atlassian-ide-plugin.xml
30+
31+
# Crashlytics plugin (for Android Studio and IntelliJ)
32+
com_crashlytics_export_strings.xml
33+
crashlytics.properties
34+
crashlytics-build.properties
35+
fabric.properties

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "dotkernel/dot-controller-plugin-session",
3+
"type": "library",
4+
"description": "DotKernel session controller plugin",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "n3vrax",
9+
"email": "tibi@apidemia.com"
10+
}
11+
],
12+
"require": {
13+
"php": "^7.1",
14+
"container-interop/container-interop": "^1.1",
15+
"dotkernel/dot-controller": "dev-develop as 0.6.x-dev",
16+
"dotkernel/dot-event": "dev-develop as 0.6.x-dev"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^4.8",
20+
"squizlabs/php_codesniffer": "^2.3",
21+
22+
"dotkernel/dot-session": "dev-develop as 0.6.x-dev"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"Dot\\Controller\\Plugin\\Session\\": "src/"
27+
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"DotTest\\Controller\\Plugin\\Session\\": "test/"
32+
}
33+
},
34+
"extra": {
35+
"branch-alias": {
36+
"dev-master": "0.6-dev"
37+
}
38+
}
39+
}

src/ConfigProvider.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* @copyright: DotKernel
4+
* @library: dot-controller-plugin-session
5+
* @author: n3vrax
6+
* Date: 2/3/2017
7+
* Time: 12:28 AM
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Dot\Controller\Plugin\Session;
13+
14+
use Dot\Controller\Plugin\Session\Factory\SessionPluginFactory;
15+
16+
/**
17+
* Class ConfigProvider
18+
* @package Dot\Controller\Plugin\Session
19+
*/
20+
class ConfigProvider
21+
{
22+
public function __invoke(): array
23+
{
24+
return [
25+
'dot_controller' => [
26+
'plugin_manager' => [
27+
'factories' => [
28+
'session' => SessionPluginFactory::class,
29+
]
30+
]
31+
]
32+
];
33+
}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @copyright: DotKernel
4+
* @library: dot-controller-plugin-session
5+
* @author: n3vrax
6+
* Date: 2/3/2017
7+
* Time: 12:44 AM
8+
*/
9+
10+
declare(strict_types = 1);
11+
12+
namespace Dot\Controller\Plugin\Session\Factory;
13+
14+
use Dot\Controller\Plugin\Session\SessionPlugin;
15+
use Interop\Container\ContainerInterface;
16+
17+
/**
18+
* Class SessionPluginFactory
19+
* @package Dot\Controller\Plugin\Session\Factory
20+
*/
21+
class SessionPluginFactory
22+
{
23+
public function __invoke(ContainerInterface $container)
24+
{
25+
return new SessionPlugin($container);
26+
}
27+
}

src/SessionPlugin.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* @copyright: DotKernel
4+
* @library: dot-controller-plugin-session
5+
* @author: n3vrax
6+
* Date: 2/3/2017
7+
* Time: 12:30 AM
8+
*/
9+
10+
declare(strict_types = 1);
11+
12+
namespace Dot\Controller\Plugin\Session;
13+
14+
use Dot\Controller\Plugin\PluginInterface;
15+
use Interop\Container\ContainerInterface;
16+
use Zend\Session\Container;
17+
use Zend\Session\ManagerInterface;
18+
use Zend\Session\SessionManager;
19+
20+
/**
21+
* Class SessionPlugin
22+
* @package Dot\Controller\Plugin\Session
23+
*/
24+
class SessionPlugin implements PluginInterface
25+
{
26+
/** @var ContainerInterface **/
27+
protected $container;
28+
29+
/** @var ManagerInterface */
30+
protected $sessionManager;
31+
32+
/**
33+
* SessionPlugin constructor.
34+
* @param ContainerInterface $container
35+
*/
36+
public function __construct(ContainerInterface $container)
37+
{
38+
$this->container = $container;
39+
}
40+
41+
/**
42+
* @param string $name
43+
* @return Container
44+
*/
45+
public function __invoke(string $name): Container
46+
{
47+
$fullName = 'dot-session.' . $name;
48+
49+
$session = null;
50+
if ($this->container->has($fullName)) {
51+
$session = $this->container->get($fullName);
52+
}
53+
54+
if (!$session instanceof Container) {
55+
$session = new Container($name, $this->getSessionManager());
56+
}
57+
58+
return $session;
59+
}
60+
61+
/**
62+
* @return ManagerInterface
63+
*/
64+
protected function getSessionManager(): ManagerInterface
65+
{
66+
if ($this->sessionManager) {
67+
return $this->sessionManager;
68+
}
69+
70+
if ($this->container->has(ManagerInterface::class)) {
71+
$this->sessionManager = $this->container->get(ManagerInterface::class);
72+
}
73+
74+
if (!$this->sessionManager instanceof ManagerInterface) {
75+
$this->sessionManager = new SessionManager();
76+
}
77+
78+
return $this->sessionManager;
79+
}
80+
}

0 commit comments

Comments
 (0)