1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
require_once 'Storages/MockSessionStorage.php'; |
4
|
|
|
require_once 'Storages/MockScopeStorage.php'; |
5
|
|
|
require_once 'Storages/MockRefreshTokenStorage.php'; |
6
|
|
|
require_once 'Storages/MockClientStorage.php'; |
7
|
|
|
require_once 'Storages/MockAccessTokenStorage.php'; |
8
|
|
|
|
9
|
|
|
use Illuminate\Contracts\Container\Container; |
10
|
|
|
use Illuminate\Support\ServiceProvider; |
11
|
|
|
use League\OAuth2\Server\Storage\AccessTokenInterface; |
12
|
|
|
use League\OAuth2\Server\Storage\ClientInterface; |
13
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface; |
14
|
|
|
use League\OAuth2\Server\Storage\ScopeInterface; |
15
|
|
|
use League\OAuth2\Server\Storage\SessionInterface; |
16
|
|
|
|
17
|
|
View Code Duplication |
class MockStorageServiceProvider extends ServiceProvider |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @inheritdoc |
21
|
|
|
*/ |
22
|
|
|
public function register() |
23
|
|
|
{ |
24
|
|
|
$this->registerContainerBindings($this->app); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
protected function registerContainerBindings(Container $container) |
31
|
|
|
{ |
32
|
|
|
$container->bind(MockAccessTokenStorage::class, function () { |
33
|
|
|
return new MockAccessTokenStorage; |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
$container->bind( MockClientStorage::class, function () { |
37
|
|
|
return new MockClientStorage; |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
$container->bind(MockRefreshTokenStorage::class, function () { |
41
|
|
|
return new MockRefreshTokenStorage; |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
$container->bind(MockScopeStorage::class, function () { |
45
|
|
|
return new MockScopeStorage; |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$container->bind(MockSessionStorage::class, function () { |
49
|
|
|
return new MockSessionStorage; |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
$container->bind(AccessTokenInterface::class, MockAccessTokenStorage::class); |
53
|
|
|
$container->bind(ClientInterface::class, MockClientStorage::class); |
54
|
|
|
$container->bind(RefreshTokenInterface::class, MockRefreshTokenStorage::class); |
55
|
|
|
$container->bind(ScopeInterface::class, MockScopeStorage::class); |
56
|
|
|
$container->bind(SessionInterface::class, MockSessionStorage::class); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.