1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Installer;
13
14 use ICanBoogie\Errors;
15
16 17 18
19 class CoreConfigRequirement extends Requirement
20 {
21 public function __construct()
22 {
23 $this->title = t('requirement.core_config.title');
24 $this->description = t
25 (
26 'requirement.core_config.description', array
27 (
28 'action' => new TellMeMore('core_config'),
29 'data' => '<textarea class="span8" readonly="readonly">' . \ICanBoogie\escape($this->get_data()) . '</textarea>'
30 )
31 );
32 }
33
34 35 36
37 public function __invoke(Errors $errors)
38 {
39 $pathname = WEBSITE_CONFIG_DIR . 'core.php';
40
41 if (file_exists($pathname))
42 {
43 return;
44 }
45
46 if (is_writable($pathname))
47 {
48 file_put_contents($pathname, $data);
49
50 return;
51 }
52
53 $errors['core_config'] = t('requirement.core_config.error.not_writable', array('pathname' => \ICanBoogie\strip_root($pathname)));
54 }
55
56 public function get_data()
57 {
58 global $core;
59
60 $options = $core->session->install['database'];
61
62 $name = $options['name'];
63 $host = $options['host'] ?: 'localhost';
64 $username = $options['username'];
65 $password = $options['password'];
66 $prefix = $options['prefix'];
67
68 return <<<EOT
69 <?php
70
71 return array
72 (
73 'connections' => array
74 (
75 'primary' => array
76 (
77 'dsn' => 'mysql:dbname=$name;host=$host',
78 'username' => '$username',
79 'password' => '$password',
80 '#timezone' => '+00.00',
81 '#table_name_prefix' => '$prefix'
82 )
83 ),
84
85 'modules paths' => array
86 (
87 \$path . 'modules'
88 )
89 );
90 EOT;
91 }
92 }