|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Sensio\Bundle\DistributionBundle\Configurator\Step; |
|
|
13 |
|
|
|
14 |
use Sensio\Bundle\DistributionBundle\Configurator\Form\DoctrineStepType; |
|
|
15 |
use Symfony\Component\Validator\Constraints as Assert; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* Doctrine Step. |
|
|
19 |
* |
|
|
20 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
21 |
*/ |
|
|
22 |
class DoctrineStep implements StepInterface |
|
|
23 |
{ |
|
|
24 |
/** |
|
|
25 |
* @Assert\Choice(callback="getDriverKeys") |
|
|
26 |
*/ |
|
|
27 |
public $driver; |
|
|
28 |
|
|
|
29 |
/** |
|
|
30 |
* @Assert\NotBlank |
|
|
31 |
*/ |
|
|
32 |
public $host; |
|
|
33 |
|
|
|
34 |
/** |
|
|
35 |
* @Assert\Min(0) |
|
|
36 |
*/ |
|
|
37 |
public $port; |
|
|
38 |
|
|
|
39 |
/** |
|
|
40 |
* @Assert\NotBlank |
|
|
41 |
*/ |
|
|
42 |
public $name; |
|
|
43 |
|
|
|
44 |
/** |
|
|
45 |
* @Assert\NotBlank |
|
|
46 |
*/ |
|
|
47 |
public $user; |
|
|
48 |
|
|
|
49 |
public $password; |
|
|
50 |
|
|
|
51 |
public function __construct(array $parameters) |
|
|
52 |
{ |
|
|
53 |
foreach ($parameters as $key => $value) { |
|
|
54 |
if (0 === strpos($key, 'database_')) { |
|
|
55 |
$parameters[substr($key, 9)] = $value; |
|
|
56 |
$key = substr($key, 9); |
|
|
57 |
$this->$key = $value; |
|
|
58 |
} |
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
/** |
|
|
63 |
* @see StepInterface |
|
|
64 |
*/ |
|
|
65 |
public function getFormType() |
|
|
66 |
{ |
|
|
67 |
return new DoctrineStepType(); |
|
|
68 |
} |
|
|
69 |
|
|
|
70 |
/** |
|
|
71 |
* @see StepInterface |
|
|
72 |
*/ |
|
|
73 |
public function checkRequirements() |
|
|
74 |
{ |
|
|
75 |
$messages = array(); |
|
|
76 |
|
|
|
77 |
if (!class_exists('\PDO')) { |
|
|
78 |
$messages[] = 'PDO extension is mandatory.'; |
|
|
79 |
} else { |
|
|
80 |
$drivers = \PDO::getAvailableDrivers(); |
|
|
81 |
if (0 == count($drivers)) { |
|
|
82 |
$messages[] = 'Please install PDO drivers.'; |
|
|
83 |
} |
|
|
84 |
} |
|
|
85 |
|
|
|
86 |
return $messages; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
/** |
|
|
90 |
* @see StepInterface |
|
|
91 |
*/ |
|
|
92 |
public function checkOptionalSettings() |
|
|
93 |
{ |
|
|
94 |
return array(); |
|
|
95 |
} |
|
|
96 |
|
|
|
97 |
/** |
|
|
98 |
* @see StepInterface |
|
|
99 |
*/ |
|
|
100 |
public function update(StepInterface $data) |
|
|
101 |
{ |
|
|
102 |
$parameters = array(); |
|
|
103 |
|
|
|
104 |
foreach ($data as $key => $value) { |
|
|
105 |
$parameters['database_'.$key] = $value; |
|
|
106 |
} |
|
|
107 |
|
|
|
108 |
return $parameters; |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
/** |
|
|
112 |
* @see StepInterface |
|
|
113 |
*/ |
|
|
114 |
public function getTemplate() |
|
|
115 |
{ |
|
|
116 |
return 'SensioDistributionBundle:Configurator/Step:doctrine.html.twig'; |
|
|
117 |
} |
|
|
118 |
|
|
|
119 |
/** |
|
|
120 |
* @return array |
|
|
121 |
*/ |
|
|
122 |
static public function getDriverKeys() |
|
|
123 |
{ |
|
|
124 |
return array_keys(static::getDrivers()); |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
/** |
|
|
128 |
* @return array |
|
|
129 |
*/ |
|
|
130 |
static public function getDrivers() |
|
|
131 |
{ |
|
|
132 |
return array( |
|
|
133 |
'pdo_mysql' => 'MySQL (PDO)', |
|
|
134 |
'pdo_sqlite' => 'SQLite (PDO)', |
|
|
135 |
'pdo_pgsql' => 'PosgreSQL (PDO)', |
|
|
136 |
'oci8' => 'Oracle (native)', |
|
|
137 |
'ibm_db2' => 'IBM DB2 (native)', |
|
|
138 |
'pdo_oci' => 'Oracle (PDO)', |
|
|
139 |
'pdo_ibm' => 'IBM DB2 (PDO)', |
|
|
140 |
'pdo_sqlsrv' => 'SQLServer (PDO)', |
|
|
141 |
); |
|
|
142 |
} |
|
|
143 |
} |