Skip to content

Commit 8fb9271

Browse files
committed
[Provider] Implement SocialConnect\Provider\Session
1 parent cc3c764 commit 8fb9271

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

AbstractBaseProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace SocialConnect\Provider;
88

99
use SocialConnect\Common\Http\Client\ClientInterface;
10+
use SocialConnect\Provider\Session\SessionInterface;
1011

1112
abstract class AbstractBaseProvider
1213
{
@@ -42,15 +43,21 @@ abstract class AbstractBaseProvider
4243
*/
4344
protected $state;
4445

46+
/**
47+
* @var SessionInterface
48+
*/
49+
protected $session;
50+
4551
/**
4652
* @param ClientInterface $httpClient
47-
* @param Consumer $consumer
53+
* @param SessionInterface $session
4854
* @param array $parameters
4955
*/
50-
public function __construct(ClientInterface $httpClient, Consumer $consumer, array $parameters)
56+
public function __construct(ClientInterface $httpClient, SessionInterface $session, Consumer $consumer, array $parameters)
5157
{
52-
$this->consumer = $consumer;
5358
$this->httpClient = $httpClient;
59+
$this->session = $session;
60+
$this->consumer = $consumer;
5461

5562
if (isset($parameters['scope'])) {
5663
$this->setScope($parameters['scope']);

Session/Session.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @author Patsura Dmitry https://github.com/ovr <talk@dmtry.me>
4+
*/
5+
6+
namespace SocialConnect\Provider\Session;
7+
8+
class Session implements SessionInterface
9+
{
10+
public function __construct()
11+
{
12+
session_start();
13+
}
14+
15+
/**
16+
* @param string $key
17+
*
18+
* @return mixed
19+
*/
20+
public function get($key)
21+
{
22+
if (isset($_SESSION[$key])) {
23+
return $_SESSION[$key];
24+
}
25+
26+
return null;
27+
}
28+
29+
/**
30+
* @param string $key
31+
* @param mixed $value
32+
*/
33+
public function set($key, $value)
34+
{
35+
$_SESSION[$key] = $value;
36+
}
37+
38+
/**
39+
* @param string $key
40+
*/
41+
public function delete($key)
42+
{
43+
if (isset($_SESSION[$key])) {
44+
unset($_SESSION[$key]);
45+
}
46+
}
47+
}

Session/SessionInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace SocialConnect\Provider\Session;
4+
5+
interface SessionInterface
6+
{
7+
/**
8+
* @param string $key
9+
*
10+
* @return mixed
11+
*/
12+
public function get($key);
13+
14+
/**
15+
* @param string $key
16+
* @param mixed $value
17+
*/
18+
public function set($key, $value);
19+
20+
/**
21+
* @param string $key
22+
*/
23+
public function delete($key);
24+
}

0 commit comments

Comments
 (0)