-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
cli-config.doctrine_dbal.php.dist
64 lines (55 loc) · 2.54 KB
/
cli-config.doctrine_dbal.php.dist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* The config file is responsible to make class loading work and initialize a
* DocumentManagerHelper that contains the doctrine document manager with a
* Session of your phpcr implementation.
* The array $extraCommands can be used to inject implementation specific commands.
* Add instances of commands for eventual implementation specific commands to this array.
*/
$extraCommands = [];
$extraCommands[] = new \Jackalope\Tools\Console\Command\InitDoctrineDbalCommand();
$params = [
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'user' => 'root',
'password' => '',
'dbname' => 'phpcr_odm_tests',
'charset' => 'utf8mb4',
];
$dbConn = \Doctrine\DBAL\DriverManager::getConnection($params);
$workspace = 'default';
$user = 'admin';
$pass = 'admin';
/* only create a session if this is not about the server control command */
if (isset($argv[1])
&& $argv[1] != 'jackalope:init:dbal'
&& $argv[1] != 'list'
&& $argv[1] != 'help'
) {
$factory = new \Jackalope\RepositoryFactoryDoctrineDBAL();
$repository = $factory->getRepository(['jackalope.doctrine_dbal_connection' => $dbConn]);
$credentials = new \PHPCR\SimpleCredentials(null, null);
$session = $repository->login($credentials, $workspace);
/* prepare the doctrine configuration */
$config = new \Doctrine\ODM\PHPCR\Configuration();
$driver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver([
__DIR__ . '/lib/Doctrine/ODM/PHPCR/Document'
]);
$config->setMetadataDriverImpl($driver);
$dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session, $config);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet([
'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($session),
'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(),
'dm' => new \Doctrine\ODM\PHPCR\Tools\Console\Helper\DocumentManagerHelper(null, $dm),
]);
if (class_exists('Symfony\Component\Console\Helper\QuestionHelper')) {
$helperSet->set(new \Symfony\Component\Console\Helper\QuestionHelper(), 'question');
} else {
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper, 'dialog');
}
} elseif (isset($argv[1]) && $argv[1] == 'jackalope:init:dbal') {
// special case: the init command needs the db connection, but a session is impossible if the db is not yet initialized
$helperSet = new \Symfony\Component\Console\Helper\HelperSet([
'connection' => new \Jackalope\Tools\Console\Helper\DoctrineDbalHelper($dbConn)
]);
}