|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Combustor\Common; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Tools |
|
7
|
|
|
* |
|
8
|
|
|
* Provides a list of multi-purpose functions for Combustor. |
|
9
|
|
|
* |
|
10
|
|
|
* @package Combustor |
|
11
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Tools |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Checks whether the header and footer file exists. |
|
17
|
|
|
* |
|
18
|
|
|
* @return bool |
|
19
|
|
|
*/ |
|
20
|
6 |
|
public static function hasLayout() |
|
21
|
|
|
{ |
|
22
|
6 |
|
$header = APPPATH . 'views/layout/header.php'; |
|
23
|
6 |
|
$footer = APPPATH . 'views/layout/footer.php'; |
|
24
|
|
|
|
|
25
|
6 |
|
return file_exists($header) && file_exists($footer); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* "Ignites" the post installation process. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
30 |
|
public static function ignite() |
|
34
|
|
|
{ |
|
35
|
30 |
|
$autoloadPath = 'realpath(\'vendor\') . \'/autoload.php\''; |
|
36
|
30 |
|
$configPath = APPPATH . 'config'; |
|
37
|
|
|
|
|
38
|
|
|
// Gets data from application/config/config.php |
|
39
|
30 |
|
$config = new Config('config', $configPath); |
|
40
|
|
|
|
|
41
|
30 |
|
$config->set('composer_autoload', 132, $autoloadPath, 'string', true); |
|
42
|
30 |
|
$config->set('index_page', 31, '', 'string'); |
|
43
|
30 |
|
$config->set('encryption_key', 310, md5('rougin'), 'string'); |
|
44
|
|
|
|
|
45
|
30 |
|
$config->save(); |
|
46
|
|
|
|
|
47
|
|
|
// Gets data from application/config/autoload.php |
|
48
|
30 |
|
$autoload = new Config('autoload', $configPath); |
|
49
|
|
|
|
|
50
|
|
|
// Gets the currently included drivers. |
|
51
|
30 |
|
$drivers = $autoload->get('drivers', 75, 'array'); |
|
52
|
|
|
|
|
53
|
|
|
// Includes "session" driver. |
|
54
|
30 |
|
if ( ! in_array('session', $drivers)) { |
|
55
|
30 |
|
array_push($drivers, 'session'); |
|
56
|
30 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
// Gets the currently included helpers |
|
59
|
30 |
|
$defaultHelpers = [ 'form', 'url' ]; |
|
60
|
30 |
|
$helpers = $autoload->get('helpers', 85, 'array'); |
|
61
|
|
|
|
|
62
|
30 |
|
foreach ($defaultHelpers as $helper) { |
|
63
|
30 |
|
if ( ! in_array($helper, $helpers)) { |
|
64
|
30 |
|
array_push($helpers, $helper); |
|
65
|
30 |
|
} |
|
66
|
30 |
|
} |
|
67
|
|
|
|
|
68
|
30 |
|
$autoload->set('drivers', 75, $drivers, 'array'); |
|
69
|
30 |
|
$autoload->set('helper', 85, $helpers, 'array'); |
|
70
|
|
|
|
|
71
|
30 |
|
$autoload->save(); |
|
72
|
|
|
|
|
73
|
|
|
// Creates a new .htaccess file if it does not exists. |
|
74
|
30 |
|
if ( ! file_exists('.htaccess')) { |
|
75
|
30 |
|
$htaccess = new File('.htaccess'); |
|
76
|
30 |
|
$template = new File(__DIR__ . '/../Templates/Htaccess.template'); |
|
77
|
|
|
|
|
78
|
30 |
|
$htaccess->putContents($template->getContents()); |
|
79
|
30 |
|
$htaccess->chmod(0777); |
|
80
|
|
|
|
|
81
|
30 |
|
$htaccess->close(); |
|
82
|
30 |
|
$template->close(); |
|
83
|
30 |
|
} |
|
84
|
|
|
|
|
85
|
30 |
|
$paginationPath = APPPATH . 'config/pagination.php'; |
|
86
|
|
|
|
|
87
|
|
|
// Creates a configuration for the Pagination library. |
|
88
|
30 |
|
if ( ! file_exists($paginationPath)) { |
|
89
|
30 |
|
$pagination = new File($paginationPath); |
|
90
|
30 |
|
$template = new File(__DIR__ . '/../Templates/Pagination.template'); |
|
91
|
|
|
|
|
92
|
30 |
|
$pagination->putContents($template->getContents()); |
|
93
|
|
|
|
|
94
|
30 |
|
$pagination->close(); |
|
95
|
30 |
|
$template->close(); |
|
96
|
30 |
|
} |
|
97
|
30 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Checks whether the command is enabled or not in the current environment. |
|
101
|
|
|
* |
|
102
|
|
|
* @return bool |
|
103
|
|
|
*/ |
|
104
|
6 |
|
public static function isCommandEnabled() |
|
105
|
|
|
{ |
|
106
|
6 |
|
return self::isWildfireEnabled() || self::isDoctrineEnabled(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Checks if Doctrine exists. |
|
111
|
|
|
* |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
3 |
|
public static function isDoctrineEnabled() |
|
115
|
|
|
{ |
|
116
|
3 |
|
return file_exists(APPPATH . 'libraries/Doctrine.php'); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Checks if Wildfire exists. |
|
121
|
|
|
* |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
6 |
|
public static function isWildfireEnabled() |
|
125
|
|
|
{ |
|
126
|
6 |
|
return file_exists(APPPATH . 'libraries/Wildfire.php'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Strips the table schema from the table name. |
|
131
|
|
|
* |
|
132
|
|
|
* @param string $table |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
27 |
|
public static function stripTableSchema($table) |
|
136
|
|
|
{ |
|
137
|
27 |
|
return (strpos($table, '.') !== false) |
|
138
|
27 |
|
? substr($table, strpos($table, '.') + 1) |
|
139
|
27 |
|
: $table; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Strips the table schema from the table name. |
|
144
|
|
|
* |
|
145
|
|
|
* @param string $table |
|
146
|
|
|
* @return string |
|
147
|
|
|
*/ |
|
148
|
3 |
|
public static function strip_table_schema($table) |
|
149
|
|
|
{ |
|
150
|
3 |
|
return self::stripTableSchema($table); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|