| Conditions | 5 |
| Paths | 8 |
| Total Lines | 31 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 2 |
| 1 | <?php |
||
| 13 | public function handle(Configuration $config, array $data) |
||
|
|
|||
| 14 | { |
||
| 15 | // Writing htaccess file |
||
| 16 | $this->logger->info('CONFIGURING: Apache Rewrite Rules'); |
||
| 17 | |||
| 18 | if (APP_MODE === 'console') { |
||
| 19 | $rewrite_base = basename(DOCROOT); |
||
| 20 | } else { |
||
| 21 | $rewrite_base = ltrim(preg_replace('/\/install$/i', null, dirname($_SERVER['PHP_SELF'])), '/'); |
||
| 22 | } |
||
| 23 | |||
| 24 | $htaccess = str_replace( |
||
| 25 | '<!-- REWRITE_BASE -->', |
||
| 26 | $rewrite_base, |
||
| 27 | file_get_contents(INSTALL . '/includes/htaccess.txt') |
||
| 28 | ); |
||
| 29 | |||
| 30 | // If the step can override, replace the entire .htaccess file. |
||
| 31 | if (file_exists(DOCROOT . "/.htaccess") && $this->override) { |
||
| 32 | $this->logger->info('CONFIGURING: Replacing existing .htaccess file'); |
||
| 33 | $file_mode = 'w'; |
||
| 34 | } else { |
||
| 35 | $file_mode = 'a'; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $config->get('write_mode', 'file'), $file_mode)) { |
||
| 39 | throw new Exception('Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT); |
||
| 40 | } |
||
| 41 | |||
| 42 | return true; |
||
| 43 | } |
||
| 44 | } |
||
| 45 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: