1
|
|
|
<?php |
2
|
|
|
namespace OAuth; |
3
|
|
|
|
4
|
|
|
use Del\Common\Container\RegistrationInterface; |
5
|
|
|
use Del\Service\UserService; |
6
|
|
|
use Doctrine\ORM\EntityManager; |
7
|
|
|
use OAuth\Service\ClientService; |
8
|
|
|
use Pimple\Container; |
9
|
|
|
|
10
|
|
|
class OAuthPackage implements RegistrationInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param Container $c |
14
|
|
|
*/ |
15
|
7 |
|
public function addToContainer(Container $c) |
16
|
|
|
{ |
17
|
|
|
// AccessToken |
18
|
|
|
$function = function ($c) { |
19
|
|
|
/** @var EntityManager $entityManager */ |
20
|
|
|
$entityManager = $c['doctrine.entity_manager']; |
21
|
|
|
$repository = $entityManager->getRepository('OAuth\AccessToken'); |
22
|
|
|
return $repository; |
23
|
|
|
}; |
24
|
7 |
|
$c['repository.AccessToken'] = $c->factory($function); |
25
|
|
|
|
26
|
|
|
// AuthCode |
27
|
|
|
$function = function ($c) { |
28
|
|
|
/** @var EntityManager $entityManager */ |
29
|
|
|
$entityManager = $c['doctrine.entity_manager']; |
30
|
|
|
$repository = $entityManager->getRepository('OAuth\AuthCode'); |
31
|
|
|
return $repository; |
32
|
7 |
|
}; |
33
|
7 |
|
$c['repository.AuthCode'] = $c->factory($function); |
34
|
|
|
|
35
|
|
|
// Client |
36
|
|
|
$function = function ($c) { |
37
|
|
|
/** @var EntityManager $entityManager */ |
38
|
|
|
$entityManager = $c['doctrine.entity_manager']; |
39
|
|
|
$repository = $entityManager->getRepository('OAuth\Client'); |
40
|
|
|
return $repository; |
41
|
7 |
|
}; |
42
|
7 |
|
$c['repository.Client'] = $c->factory($function); |
43
|
|
|
|
44
|
|
|
$function = function ($c) { |
45
|
|
|
$repository = $c['repository.Client']; |
46
|
|
|
$svc = new ClientService($repository); |
47
|
|
|
return $svc; |
48
|
7 |
|
}; |
49
|
7 |
|
$c['oauth.service.client'] = $c->factory($function); |
50
|
|
|
|
51
|
|
|
// RefreshToken |
52
|
|
|
$function = function ($c) { |
53
|
|
|
/** @var EntityManager $entityManager */ |
54
|
|
|
$entityManager = $c['doctrine.entity_manager']; |
55
|
|
|
$repository = $entityManager->getRepository('OAuth\RefreshToken'); |
56
|
|
|
return $repository; |
57
|
7 |
|
}; |
58
|
7 |
|
$c['repository.RefreshToken'] = $c->factory($function); |
59
|
|
|
|
60
|
|
|
// Scope |
61
|
|
|
$function = function ($c) { |
62
|
|
|
/** @var EntityManager $entityManager */ |
63
|
|
|
$entityManager = $c['doctrine.entity_manager']; |
64
|
|
|
$repository = $entityManager->getRepository('OAuth\Scope'); |
65
|
|
|
return $repository; |
66
|
7 |
|
}; |
67
|
7 |
|
$c['repository.Scope'] = $c->factory($function); |
68
|
|
|
|
69
|
|
|
// User |
70
|
|
|
$function = function ($c) { |
71
|
|
|
/** @var EntityManager $entityManager */ |
72
|
|
|
$entityManager = $c['doctrine.entity_manager']; |
73
|
|
|
$repository = $entityManager->getRepository(OAuthUser::class); |
74
|
|
|
return $repository; |
75
|
7 |
|
}; |
76
|
7 |
|
$c['repository.User'] = $c->factory($function); |
77
|
7 |
|
} |
78
|
|
|
|
79
|
7 |
|
public function getEntityPath() |
80
|
|
|
{ |
81
|
7 |
|
return 'src/Entity/OAuth'; |
82
|
|
|
} |
83
|
|
|
|
84
|
7 |
|
public function hasEntityPath() |
85
|
|
|
{ |
86
|
7 |
|
return true; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |