|
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
|
11 |
|
public function addToContainer(Container $c) |
|
16
|
|
|
{ |
|
17
|
|
|
// AccessToken |
|
18
|
|
|
$function = function ($c) { |
|
19
|
|
|
/** @var EntityManager $entityManager */ |
|
20
|
1 |
|
$entityManager = $c['doctrine.entity_manager']; |
|
21
|
1 |
|
$repository = $entityManager->getRepository('OAuth\AccessToken'); |
|
22
|
1 |
|
return $repository; |
|
23
|
1 |
|
}; |
|
24
|
11 |
|
$c['repository.AccessToken'] = $c->factory($function); |
|
25
|
|
|
|
|
26
|
|
|
// AuthCode |
|
27
|
|
|
$function = function ($c) { |
|
28
|
|
|
/** @var EntityManager $entityManager */ |
|
29
|
1 |
|
$entityManager = $c['doctrine.entity_manager']; |
|
30
|
1 |
|
$repository = $entityManager->getRepository('OAuth\AuthCode'); |
|
31
|
1 |
|
return $repository; |
|
32
|
11 |
|
}; |
|
33
|
11 |
|
$c['repository.AuthCode'] = $c->factory($function); |
|
34
|
|
|
|
|
35
|
|
|
// Client |
|
36
|
|
|
$function = function ($c) { |
|
37
|
|
|
/** @var EntityManager $entityManager */ |
|
38
|
1 |
|
$entityManager = $c['doctrine.entity_manager']; |
|
39
|
1 |
|
$repository = $entityManager->getRepository('OAuth\Client'); |
|
40
|
1 |
|
return $repository; |
|
41
|
11 |
|
}; |
|
42
|
11 |
|
$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
|
11 |
|
}; |
|
49
|
11 |
|
$c['oauth.service.client'] = $c->factory($function); |
|
50
|
|
|
|
|
51
|
|
|
// RefreshToken |
|
52
|
|
|
$function = function ($c) { |
|
53
|
|
|
/** @var EntityManager $entityManager */ |
|
54
|
1 |
|
$entityManager = $c['doctrine.entity_manager']; |
|
55
|
1 |
|
$repository = $entityManager->getRepository('OAuth\RefreshToken'); |
|
56
|
1 |
|
return $repository; |
|
57
|
11 |
|
}; |
|
58
|
11 |
|
$c['repository.RefreshToken'] = $c->factory($function); |
|
59
|
|
|
|
|
60
|
|
|
// Scope |
|
61
|
|
|
$function = function ($c) { |
|
62
|
|
|
/** @var EntityManager $entityManager */ |
|
63
|
1 |
|
$entityManager = $c['doctrine.entity_manager']; |
|
64
|
1 |
|
$repository = $entityManager->getRepository('OAuth\Scope'); |
|
65
|
1 |
|
return $repository; |
|
66
|
11 |
|
}; |
|
67
|
11 |
|
$c['repository.Scope'] = $c->factory($function); |
|
68
|
|
|
|
|
69
|
|
|
// User |
|
70
|
|
|
$function = function ($c) { |
|
71
|
|
|
/** @var EntityManager $entityManager */ |
|
72
|
1 |
|
$entityManager = $c['doctrine.entity_manager']; |
|
73
|
1 |
|
$repository = $entityManager->getRepository(OAuthUser::class); |
|
74
|
1 |
|
return $repository; |
|
75
|
11 |
|
}; |
|
76
|
11 |
|
$c['repository.User'] = $c->factory($function); |
|
77
|
11 |
|
} |
|
78
|
|
|
|
|
79
|
11 |
|
public function getEntityPath() |
|
80
|
|
|
{ |
|
81
|
11 |
|
return 'src/Entity/OAuth'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
11 |
|
public function hasEntityPath() |
|
85
|
|
|
{ |
|
86
|
11 |
|
return true; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |