Skip to content

Commit 57e506c

Browse files
committed
Add dependency injection for session and new config
1 parent 922c14a commit 57e506c

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

config/parse.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,16 @@
6666

6767
'mount_path' => '1',
6868

69+
/*
70+
|--------------------------------------------------------------------------
71+
| Parse Session Handler
72+
|--------------------------------------------------------------------------
73+
|
74+
| Here you may specify your parse session handler.
75+
| Use 'laravel' if you want to use Laravel's session or blank if you don't.
76+
|
77+
*/
78+
79+
'session' => 'laravel',
80+
6981
];

src/ParseServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ protected function setupParse()
7171
ParseClient::setServerURL($serverURL, $mountPath);
7272
}
7373

74-
ParseClient::setStorage(new ParseSessionStorage());
74+
if (isset($config['session']) && $config['session'] === 'laravel') {
75+
ParseClient::setStorage(new ParseSessionStorage($this->app->session));
76+
}
7577
}
7678

7779
/**

src/ParseSessionStorage.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
namespace GrahamCampbell\Parse;
44

5+
use Illuminate\Session\SessionManager;
56
use Parse\ParseStorageInterface;
67

78
class ParseSessionStorage implements ParseStorageInterface
89
{
910
/**
10-
* Parse will store its values in a specific key.
11-
*
12-
* @var string
11+
* @var \Illuminate\Session\SessionManager
1312
*/
14-
private $storageKey = 'parseData';
13+
private $session;
1514

16-
public function __construct()
15+
/**
16+
* @param \Illuminate\Session\SessionManager $session
17+
*/
18+
public function __construct(SessionManager $session)
1719
{
18-
20+
$this->session = $session;
1921
}
2022

2123
/**
@@ -28,7 +30,7 @@ public function __construct()
2830
*/
2931
public function set($key, $value)
3032
{
31-
\Session::put($this->storageKey . '.' . $key, $value);
33+
$this->session->put($key, $value);
3234
}
3335

3436
/**
@@ -40,7 +42,7 @@ public function set($key, $value)
4042
*/
4143
public function remove($key)
4244
{
43-
\Session::forget($this->storageKey . '.' . $key);
45+
$this->session->forget($key);
4446
}
4547

4648
/**
@@ -52,10 +54,9 @@ public function remove($key)
5254
*/
5355
public function get($key)
5456
{
55-
if (\Session::has($this->storageKey . '.' . $key)) {
56-
return \Session::get($this->storageKey . '.' . $key);
57+
if ($this->session->has($key)) {
58+
return $this->session->get($key);
5759
}
58-
return;
5960
}
6061

6162
/**
@@ -65,7 +66,7 @@ public function get($key)
6566
*/
6667
public function clear()
6768
{
68-
\Session::forget($this->storageKey);
69+
$this->session->forget();
6970
}
7071

7172
/**
@@ -77,17 +78,17 @@ public function clear()
7778
*/
7879
public function save()
7980
{
80-
return;
81+
//
8182
}
8283

8384
/**
84-
* Get all keys in storage.
85-
*
86-
* @return array
87-
*/
85+
* Get all keys in storage.
86+
*
87+
* @return array
88+
*/
8889
public function getKeys()
8990
{
90-
return array_keys(\Session::get($this->storageKey));
91+
return array_keys($this->session->get());
9192
}
9293

9394
/**
@@ -97,6 +98,6 @@ public function getKeys()
9798
*/
9899
public function getAll()
99100
{
100-
return \Session::get($this->storageKey);
101+
return $this->session->get();
101102
}
102103
}

0 commit comments

Comments
 (0)