Skip to content

Commit 3edd10c

Browse files
Add add command and tidy up
1 parent 4b4231b commit 3edd10c

File tree

8 files changed

+666
-94
lines changed

8 files changed

+666
-94
lines changed

composer.lock

Lines changed: 530 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kickoff

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env php
22
<?php
3+
34
use Symfony\Component\Console\Application;
5+
use Club\KickoffInstaller\Console\AddCommand;
46
use Club\KickoffInstaller\Console\NewCommand;
57
use Club\KickoffInstaller\Console\ConfigCommand;
68

@@ -10,7 +12,8 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
1012
require __DIR__.'/vendor/autoload.php';
1113
}
1214

13-
$app = new Application('CraftCMS Installer', '1.0.0');
15+
$app = new Application('CraftCMS Installer', '1.1.0');
1416
$app->add(new NewCommand);
17+
$app->add(new AddCommand);
1518
$app->add(new ConfigCommand);
1619
$app->run();

src/Console/AddCommand.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Club\KickoffInstaller\Console;
4+
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
class AddCommand extends InstallationCommand
10+
{
11+
/**
12+
* Configure the command.
13+
*/
14+
protected function configure()
15+
{
16+
$this->setName('add')
17+
->setDescription('Add a framework installation to an existing project')
18+
->addArgument('framework', InputArgument::REQUIRED);
19+
}
20+
21+
/**
22+
* Execute the command.
23+
*
24+
* @param InputInterface $input
25+
* @param OutputInterface $output
26+
*/
27+
protected function execute(InputInterface $input, OutputInterface $output)
28+
{
29+
$installerClass = $this->getInstallerClass(
30+
$input->getArgument('framework')
31+
);
32+
33+
$installer = new $installerClass($input, $output, getcwd());
34+
$installer->install();
35+
36+
$output->writeln("<comment>`{$installer->name()}` added to your project. Happy coding!</comment>");
37+
}
38+
}

src/Console/InstallationCommand.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Club\KickoffInstaller\Console;
4+
5+
use InvalidArgumentException;
6+
use Symfony\Component\Console\Command\Command;
7+
8+
abstract class InstallationCommand extends Command
9+
{
10+
/**
11+
* Available installers.
12+
*
13+
* @return array An array of available installer class names
14+
*/
15+
protected function installers()
16+
{
17+
return [
18+
'CraftCms' => \Club\KickoffInstaller\Installers\CraftCms\Installer::class,
19+
];
20+
}
21+
22+
/**
23+
* Get the full class name of an installer.
24+
*
25+
* @param string $framework Framework short-name
26+
*
27+
* @return string Installer class name
28+
*/
29+
protected function getInstallerClass($framework)
30+
{
31+
$installers = $this->installers();
32+
33+
if (!array_key_exists($framework, $installers)) {
34+
throw new InvalidArgumentException("An installer for `$framework` does not exist.");
35+
}
36+
37+
return $installers[$framework];
38+
}
39+
}

src/Console/NewCommand.php

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<?php
2+
23
namespace Club\KickoffInstaller\Console;
34

4-
use InvalidArgumentException;
5-
use Symfony\Component\Console\Command\Command;
65
use Symfony\Component\Console\Input\InputOption;
76
use Symfony\Component\Console\Input\InputArgument;
87
use Symfony\Component\Console\Input\InputInterface;
98
use Symfony\Component\Console\Output\OutputInterface;
109
use Club\KickoffInstaller\Installers\Kickoff\Installer as KickoffInstaller;
1110

12-
class NewCommand extends Command
11+
class NewCommand extends InstallationCommand
1312
{
1413
/**
1514
* Configure the command.
16-
*
17-
* @return void
1815
*/
1916
protected function configure()
2017
{
@@ -24,41 +21,11 @@ protected function configure()
2421
->addOption('clean', null, InputOption::VALUE_NONE, 'If set, Kickoff will be omitted from the install');
2522
}
2623

27-
/**
28-
* Available installers.
29-
*
30-
* @return array An array of available installer class names.
31-
*/
32-
protected function installers()
33-
{
34-
return [
35-
'CraftCms' => \Club\KickoffInstaller\Installers\CraftCms\Installer::class,
36-
];
37-
}
38-
39-
/**
40-
* Get the full class name of an installer.
41-
*
42-
* @param string $framework Framework short-name.
43-
* @return string Installer class name.
44-
*/
45-
protected function getInstallerClass($framework)
46-
{
47-
$installers = $this->installers();
48-
49-
if (!array_key_exists($framework, $installers)) {
50-
throw new InvalidArgumentException("An installer for `$framework` does not exist.");
51-
}
52-
53-
return $installers[$framework];
54-
}
55-
5624
/**
5725
* Execute the command.
5826
*
59-
* @param InputInterface $input
60-
* @param OutputInterface $output
61-
* @return void
27+
* @param InputInterface $input
28+
* @param OutputInterface $output
6229
*/
6330
protected function execute(InputInterface $input, OutputInterface $output)
6431
{

src/Installers/CraftCms/Installer.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Installer extends BaseInstaller
2828
protected $downloadTo = 'craft.zip';
2929

3030
/**
31-
* Configurable directories to path constant mappings
31+
* Configurable directories to path constant mappings.
3232
*
3333
* @var array
3434
*/
@@ -41,7 +41,7 @@ class Installer extends BaseInstaller
4141
];
4242

4343
/**
44-
* Commands to run when Kickoff isn't installed
44+
* Commands to run when Kickoff isn't installed.
4545
*
4646
* @return array An array of commands
4747
*/
@@ -63,7 +63,7 @@ public function clean()
6363
}
6464

6565
/**
66-
* Commands to run once the framework has been downloaded
66+
* Commands to run once the framework has been downloaded.
6767
*
6868
* @return array An array of commands
6969
*/
@@ -79,9 +79,7 @@ protected function kickoff()
7979
}
8080

8181
/**
82-
* Runs when the installation process is complete
83-
*
84-
* @return void
82+
* Runs when the installation process is complete.
8583
*/
8684
protected function complete()
8785
{
@@ -91,8 +89,7 @@ protected function complete()
9189
/**
9290
* Move Craft Directories in to those defined in the configuration file.
9391
*
94-
* @param object $mappings An object of directory mappings
95-
* @return void
92+
* @param object $mappings An object of directory mappings
9693
*/
9794
protected function moveCraftDirectories($mappings)
9895
{
@@ -125,25 +122,20 @@ protected function moveCraftDirectories($mappings)
125122

126123
/**
127124
* Swap the default Kickoff index file with the Craft index file.
128-
*
129-
* @return void
130125
*/
131126
protected function swapIndexFile()
132127
{
133128
$this->output->writeln('<info>Moving Front Controller...</info>');
134129

135130
$this->runCommands([
136131
'mv tmp/public/index.php ./public/',
137-
'rm public/index.html',
138132
]);
139133

140134
$this->output->writeln('<comment>Front Controller moved!</comment>');
141135
}
142136

143137
/**
144-
* Inject custom directory mappings into the Craft index file
145-
*
146-
* @return void
138+
* Inject custom directory mappings into the Craft index file.
147139
*/
148140
protected function updateFrontController()
149141
{
@@ -156,10 +148,9 @@ protected function updateFrontController()
156148
}
157149

158150
/**
159-
* Install PHPDotEnv Library
151+
* Install PHPDotEnv Library.
160152
*
161-
* @param object $mappings An object of directory mappings
162-
* @return void
153+
* @param object $mappings An object of directory mappings
163154
*/
164155
protected function installPhpDotEnv($mappings)
165156
{
@@ -181,14 +172,13 @@ protected function installPhpDotEnv($mappings)
181172
}
182173

183174
/**
184-
* Replace path names in the Craft index file
175+
* Replace path names in the Craft index file.
185176
*
186-
* @param object $mappings An object of directory mappings
187-
* @return void
177+
* @param object $mappings An object of directory mappings
188178
*/
189179
protected function replacePaths($mappings)
190180
{
191-
$commands = [];
181+
$commands = [];
192182
foreach (self::$pathConstants as $key => $constant) {
193183
if (isset($mappings->$key)) {
194184
$path = str_replace('/', '\/', "../{$mappings->$key}/");

0 commit comments

Comments
 (0)