1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mouf\Security\DAO; |
4
|
|
|
|
5
|
|
|
use Mouf\Actions\InstallUtils; |
6
|
|
|
use Mouf\Database\Patcher\DatabasePatchInstaller; |
7
|
|
|
use Mouf\Installer\PackageInstallerInterface; |
8
|
|
|
use Mouf\MoufManager; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
class TablesInstaller implements PackageInstallerInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* (non-PHPdoc). |
17
|
|
|
* |
18
|
|
|
* @see \Mouf\Installer\PackageInstallerInterface::install() |
19
|
|
|
*/ |
20
|
|
|
public static function install(MoufManager $moufManager) |
21
|
|
|
{ |
22
|
|
|
DatabasePatchInstaller::registerPatch($moufManager, |
23
|
|
|
'createUserRoleRightTablesPatch', |
24
|
|
|
'This patch is added by the mouf/security.daos.tdbm package. It creates users, users_roles, roles, roles_rights tables.', |
25
|
|
|
'vendor/mouf/security.daos.tdbm/database/up/users-roles-rights.sql', // SQL patch file, relative to ROOT_PATH |
26
|
|
|
'vendor/mouf/security.daos.tdbm/database/down/users-roles-rights.sql'); // Optional SQL revert patch file, relative to ROOT_PATH |
27
|
|
|
|
28
|
|
|
// These instances are expected to exist when the installer is run. |
29
|
|
|
$tdbmService = $moufManager->getInstanceDescriptor('tdbmService'); |
30
|
|
|
|
31
|
|
|
// Let's create the instances. |
32
|
|
|
$Mouf_Security_Rights_RightsRegistry = InstallUtils::getOrCreateInstance('Mouf\\Security\\Rights\\RightsRegistry', 'Mouf\\Security\\Rights\\RightsRegistry', $moufManager); |
33
|
|
|
$Mouf_Security_DAO_SecurityRightDao = InstallUtils::getOrCreateInstance('Mouf\\Security\\DAO\\SecurityRightDao', 'Mouf\\Security\\DAO\\SecurityRightDao', $moufManager); |
34
|
|
|
$Mouf_Security_DAO_SecurityUserDao = InstallUtils::getOrCreateInstance('Mouf\\Security\\DAO\\SecurityUserDao', 'Mouf\\Security\\DAO\\SecurityUserDao', $moufManager); |
35
|
|
|
|
36
|
|
|
// Let's bind instances together. |
37
|
|
|
if (!$Mouf_Security_Rights_RightsRegistry->getConstructorArgumentProperty('rights')->isValueSet()) { |
38
|
|
|
$Mouf_Security_Rights_RightsRegistry->getConstructorArgumentProperty('rights')->setValue(array()); |
39
|
|
|
} |
40
|
|
|
if (!$Mouf_Security_DAO_SecurityRightDao->getConstructorArgumentProperty('tdbmService')->isValueSet()) { |
41
|
|
|
$Mouf_Security_DAO_SecurityRightDao->getConstructorArgumentProperty('tdbmService')->setValue($tdbmService); |
42
|
|
|
} |
43
|
|
|
if (!$Mouf_Security_DAO_SecurityRightDao->getConstructorArgumentProperty('rightsRegistry')->isValueSet()) { |
44
|
|
|
$Mouf_Security_DAO_SecurityRightDao->getConstructorArgumentProperty('rightsRegistry')->setValue($Mouf_Security_Rights_RightsRegistry); |
45
|
|
|
} |
46
|
|
|
if (!$Mouf_Security_DAO_SecurityUserDao->getConstructorArgumentProperty('tdbmService')->isValueSet()) { |
47
|
|
|
$Mouf_Security_DAO_SecurityUserDao->getConstructorArgumentProperty('tdbmService')->setValue($tdbmService); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// Lets bind UserDao and RightsDao to userService and rightsService |
51
|
|
|
$rightsService = $moufManager->getInstanceDescriptor('rightsService'); |
52
|
|
|
$rightsService->getPublicFieldProperty('rightsDao')->setValue($Mouf_Security_DAO_SecurityRightDao); |
53
|
|
|
|
54
|
|
|
$userService = $moufManager->getInstanceDescriptor('userService'); |
55
|
|
|
$userService->getPublicFieldProperty('userDao')->setValue($Mouf_Security_DAO_SecurityUserDao); |
56
|
|
|
|
57
|
|
|
// TODO: apply patch |
58
|
|
|
// TODO: regenerate DAOs. |
59
|
|
|
|
60
|
|
|
// Let's rewrite the MoufComponents.php file to save the component |
61
|
|
|
$moufManager->rewriteMouf(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|