rougin /
combustor
| 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 Gutib <[email protected]> |
||
| 12 | */ |
||
| 13 | class Tools |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Checks whether the header and footer file exists. |
||
| 17 | * |
||
| 18 | * @return bool |
||
| 19 | */ |
||
| 20 | 3 | public static function hasLayout() |
|
| 21 | { |
||
| 22 | 3 | $header = APPPATH . 'views/layout/header.php'; |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 23 | 3 | $footer = APPPATH . 'views/layout/footer.php'; |
|
| 24 | |||
| 25 | 3 | 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'; |
|
|
0 ignored issues
–
show
|
|||
| 37 | 30 | $templatePath = __DIR__ . '/../Templates'; |
|
| 38 | |||
| 39 | // Gets data from application/config/config.php |
||
| 40 | 30 | $config = new Config('config', $configPath); |
|
| 41 | |||
| 42 | 30 | $config->set('composer_autoload', 138, $autoloadPath, 'string', true); |
|
| 43 | 30 | $config->set('index_page', 37, '', 'string'); |
|
| 44 | 30 | $config->set('encryption_key', 316, md5('rougin'), 'string'); |
|
| 45 | |||
| 46 | 30 | $config->save(); |
|
| 47 | |||
| 48 | // Gets data from application/config/autoload.php |
||
| 49 | 30 | $autoload = new Config('autoload', $configPath); |
|
| 50 | |||
| 51 | // Gets the currently included drivers. |
||
| 52 | 30 | $drivers = $autoload->get('drivers', 81, 'array'); |
|
| 53 | |||
| 54 | // Includes "session" driver. |
||
| 55 | 30 | if (! in_array('session', $drivers)) { |
|
| 56 | 30 | array_push($drivers, 'session'); |
|
| 57 | 20 | } |
|
| 58 | |||
| 59 | // Gets the currently included helpers |
||
| 60 | 30 | $defaultHelpers = [ 'form', 'url' ]; |
|
| 61 | 30 | $helpers = $autoload->get('helper', 91, 'array'); |
|
| 62 | |||
| 63 | 30 | foreach ($defaultHelpers as $helper) { |
|
| 64 | 30 | if (! in_array($helper, $helpers)) { |
|
| 65 | 30 | array_push($helpers, $helper); |
|
| 66 | 20 | } |
|
| 67 | 20 | } |
|
| 68 | |||
| 69 | 30 | $autoload->set('drivers', 81, $drivers, 'array'); |
|
| 70 | 30 | $autoload->set('helper', 91, $helpers, 'array'); |
|
| 71 | |||
| 72 | 30 | $autoload->save(); |
|
| 73 | |||
| 74 | $templates = [ |
||
| 75 | [ |
||
| 76 | 30 | 'file' => '.htaccess', |
|
| 77 | 'name' => 'Htaccess' |
||
| 78 | 20 | ], |
|
| 79 | [ |
||
| 80 | 30 | 'file' => APPPATH . 'config/pagination.php', |
|
| 81 | 10 | 'name' => 'Pagination' |
|
| 82 | 20 | ] |
|
| 83 | 20 | ]; |
|
| 84 | |||
| 85 | 30 | foreach ($templates as $template) { |
|
| 86 | 30 | $file = new File($template['file']); |
|
| 87 | 30 | $path = $templatePath . '/' . $template['name'] . '.tpl'; |
|
| 88 | |||
| 89 | 30 | if ($template['file'] == '.htaccess') { |
|
| 90 | 30 | $file->chmod(0777); |
|
| 91 | 20 | } |
|
| 92 | |||
| 93 | 30 | $file->putContents(file_get_contents($path)); |
|
| 94 | 30 | $file->close(); |
|
| 95 | 20 | } |
|
| 96 | 30 | } |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Checks whether the command is enabled or not in the current environment. |
||
| 100 | * |
||
| 101 | * @return bool |
||
| 102 | */ |
||
| 103 | 6 | public static function isCommandEnabled() |
|
| 104 | { |
||
| 105 | 6 | $doctrine = APPPATH . 'libraries/Doctrine.php'; |
|
|
0 ignored issues
–
show
|
|||
| 106 | 6 | $wildfire = APPPATH . 'libraries/Wildfire.php'; |
|
| 107 | |||
| 108 | 6 | return file_exists($doctrine) || file_exists($wildfire); |
|
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Strips the table schema from the table name. |
||
| 113 | * |
||
| 114 | * @param string $table |
||
| 115 | * @return string |
||
| 116 | */ |
||
| 117 | 27 | public static function stripTableSchema($table) |
|
| 118 | { |
||
| 119 | 27 | return (strpos($table, '.') !== false) |
|
| 120 | 19 | ? substr($table, strpos($table, '.') + 1) |
|
| 121 | 27 | : $table; |
|
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Strips the table schema from the table name. |
||
| 126 | * |
||
| 127 | * @param string $table |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | 3 | public static function strip_table_schema($table) |
|
| 131 | { |
||
| 132 | 3 | return self::stripTableSchema($table); |
|
| 133 | } |
||
| 134 | } |
||
| 135 |