|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Combustor\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
7
|
|
|
|
|
8
|
|
|
use Rougin\Combustor\Common\Tools; |
|
9
|
|
|
use Rougin\Combustor\Common\Commands\InstallCommand; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Install Wildfire Command |
|
13
|
|
|
* |
|
14
|
|
|
* Installs Wildfire for CodeIgniter |
|
15
|
|
|
* |
|
16
|
|
|
* @package Combustor |
|
17
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class InstallWildfireCommand extends InstallCommand |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $library = 'wildfire'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Executes the command. |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
30
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
31
|
|
|
* @return object|\Symfony\Component\Console\Output\OutputInterface |
|
32
|
|
|
*/ |
|
33
|
12 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
// Adds Wildfire.php to the "libraries" directory |
|
36
|
12 |
|
$autoload = file_get_contents(APPPATH . 'config/autoload.php'); |
|
37
|
12 |
|
$lines = explode(PHP_EOL, $autoload); |
|
38
|
|
|
|
|
39
|
12 |
|
$pattern = '/\$autoload\[\'libraries\'\] = array\((.*?)\)/'; |
|
40
|
|
|
|
|
41
|
12 |
|
preg_match_all($pattern, $lines[60], $match); |
|
42
|
|
|
|
|
43
|
12 |
|
$libraries = explode(', ', end($match[1])); |
|
44
|
|
|
|
|
45
|
12 |
View Code Duplication |
if ( ! in_array('\'wildfire\'', $libraries)) { |
|
|
|
|
|
|
46
|
12 |
|
array_push($libraries, '\'wildfire\''); |
|
47
|
|
|
|
|
48
|
12 |
|
$libraries = array_filter($libraries); |
|
49
|
|
|
|
|
50
|
12 |
|
$pattern = '/\$autoload\[\'libraries\'\] = array\([^)]*\);/'; |
|
51
|
12 |
|
$replacement = '$autoload[\'libraries\'] = array(' . implode(', ', $libraries) . ');'; |
|
52
|
|
|
|
|
53
|
12 |
|
$lines[60] = preg_replace($pattern, $replacement, $lines[60]); |
|
54
|
|
|
|
|
55
|
12 |
|
file_put_contents(APPPATH . 'config/autoload.php', implode(PHP_EOL, $lines)); |
|
56
|
12 |
|
} |
|
57
|
|
|
|
|
58
|
12 |
|
$file = fopen(APPPATH . 'libraries/Wildfire.php', 'wb'); |
|
59
|
12 |
|
$wildfire = $this->renderer->render('Libraries/Wildfire.template'); |
|
60
|
|
|
|
|
61
|
12 |
|
file_put_contents(APPPATH . 'libraries/Wildfire.php', $wildfire); |
|
62
|
12 |
|
fclose($file); |
|
63
|
|
|
|
|
64
|
12 |
|
Tools::ignite(); |
|
65
|
|
|
|
|
66
|
12 |
|
$message = 'Wildfire is now installed successfully!'; |
|
67
|
|
|
|
|
68
|
12 |
|
return $output->writeln('<info>'.$message.'</info>'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.