-
Notifications
You must be signed in to change notification settings - Fork 60
/
cli-config.dist.php
88 lines (79 loc) · 3 KB
/
cli-config.dist.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
use Jackalope\Tools\Console\Helper\DoctrineDbalHelper;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Doctrine\Dbal\Connection;
use Doctrine\DBAL\DriverManager;
use Jackalope\RepositoryFactoryDoctrineDBAL;
use PHPCR\RepositoryInterface;
use PHPCR\SimpleCredentials;
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
use PHPCR\Util\Console\Helper\PhpcrHelper;
use Symfony\Component\Console\Helper\HelperSet;
/**
* Bootstrapping the repository implementation for the stand-alone cli application.
*
* Copy this file to cli-config.php and adjust the configuration parts to your need.
*/
/*
* Configuration
*/
$workspace = 'default'; // phpcr workspace to use
// jackalope-doctrine-dbal does not verify credentials. $user is recorded as node creator.
// See the `getDoctrineDbalConnection` method for the DBAL database credentials.
$user = 'admin';
function getDoctrineDbalConnection(): Connection
{
/*
* Additional Doctrine DBAL configuration.
*
* For further details, please see Doctrine configuration page.
* http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connection-details
*/
$sqluser = 'root';
$sqlpass = '';
$driver = 'pdo_sqlite';
$host = 'localhost';
$database = 'jackalope';
$path = 'phpcr.sqlite';
return DriverManager::getConnection([
'driver' => $driver,
'host' => $host,
'user' => $sqluser,
'password' => $sqlpass,
'dbname' => $database,
'path' => $path, // remove this line if not using sqlite
]);
}
function bootstrapDoctrineDbal(Connection $connection): RepositoryInterface
{
return (new RepositoryFactoryDoctrineDBAL())
->getRepository([
'jackalope.doctrine_dbal_connection' => $connection,
]);
}
/* Only create a session if this is neither the help nor the initialization command. */
if (!array_key_exists(1, $argv[1])) {
return;
}
if(!in_array($argv[1], ['jackalope:init:dbal', 'list', 'help'], true)) {
$repository = bootstrapDoctrineDbal(getDoctrineDbalConnection());
$credentials = new SimpleCredentials($user, null); // password is not used by jackalope-doctrine-dbal
$session = $repository->login($credentials, $workspace);
$helperSet = new HelperSet([
'phpcr' => new PhpcrHelper($session),
'phpcr_console_dumper' => new PhpcrConsoleDumperHelper(),
]);
if (class_exists(QuestionHelper::class)) {
$helperSet->set(new QuestionHelper(), 'question');
} else {
// legacy support for old Symfony versions
$helperSet->set(new DialogHelper(), 'dialog');
}
} elseif ('jackalope:init:dbal' === $argv[1]) {
$dbConn = getDoctrineDbalConnection();
// special case: the init command needs the db connection, but a session is impossible if the db is not yet initialized
$helperSet = new HelperSet([
'connection' => new DoctrineDbalHelper($dbConn)
]);
}