summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhil Burton <phil@d3r.com>2017-08-21 18:58:05 +0100
committerPhil Burton <phil@d3r.com>2017-08-21 18:58:05 +0100
commit31ac8bccdae86eeb150cb396c44ee88427120e3e (patch)
tree29526c559aab90170b036a1801a17785c2a9479c /src
parent0ed82a2c6ffd8e981d9dd388306379941ecb5720 (diff)
wip
Diffstat (limited to 'src')
-rw-r--r--src/Filesystem/Create.php25
-rw-r--r--src/Filesystem/CreateDirectory.php22
-rw-r--r--src/Filesystem/CreateFile.php23
-rw-r--r--src/Script/Command/Site.php80
-rw-r--r--src/Script/Command/Site/Create.php99
5 files changed, 167 insertions, 82 deletions
diff --git a/src/Filesystem/Create.php b/src/Filesystem/Create.php
index a1891db..45b09fd 100644
--- a/src/Filesystem/Create.php
+++ b/src/Filesystem/Create.php
@@ -2,11 +2,36 @@
namespace App\Filesystem;
+
+/**
+ * Base class for creating filesystem things
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
abstract class Create
{
+ /**
+ * Filename to create
+ *
+ * @var string
+ * @author Phil Burton <phil@d3r.com>
+ */
protected $filename;
+
+ /**
+ * Thing we're creating, used for messages
+ *
+ * @var string
+ * @author Phil Burton <phil@d3r.com>
+ */
protected $thing;
+ /**
+ * Set filename on object and check we can wirte to the Directory
+ *
+ * @param string $filename
+ * @author Phil Burton <phil@d3r.com>
+ */
public function __construct(string $filename)
{
$this->filename = $filename;
diff --git a/src/Filesystem/CreateDirectory.php b/src/Filesystem/CreateDirectory.php
index 0c45c6c..2af53d7 100644
--- a/src/Filesystem/CreateDirectory.php
+++ b/src/Filesystem/CreateDirectory.php
@@ -4,11 +4,26 @@ namespace App\Filesystem;
use App\Filesystem\Create;
+/**
+ * Class to create a new directory
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
class CreateDirectory extends Create
{
- protected $filename;
+ /**
+ * Thing we're creating
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
protected $thing = "directory";
+ /**
+ * Check if the directory already exists
+ *
+ * @param string $filename
+ * @author Phil Burton <phil@d3r.com>
+ */
public function __construct(string $filename)
{
parent::__construct($filename);
@@ -18,6 +33,11 @@ class CreateDirectory extends Create
}
}
+ /**
+ * Create the new directory
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
public function excecute()
{
echo "execute";
diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php
index f41d4b9..7fed65c 100644
--- a/src/Filesystem/CreateFile.php
+++ b/src/Filesystem/CreateFile.php
@@ -4,11 +4,27 @@ namespace App\Filesystem;
use App\Filesystem\Create;
+/**
+ * Class to create a new file
+ *
+ * @param string $filename [description]
+ * @author Phil Burton <phil@d3r.com>
+ */
class CreateFile extends Create
{
- protected $filename;
+ /**
+ * Thing we're creating
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
protected $thing = "file";
+ /**
+ * Check if the file already exists
+ *
+ * @param string $filename
+ * @author Phil Burton <phil@d3r.com>
+ */
public function __construct(string $filename)
{
parent::__construct($filename);
@@ -18,6 +34,11 @@ class CreateFile extends Create
}
}
+ /**
+ * Create the new file
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
public function excecute()
{
echo "execute";
diff --git a/src/Script/Command/Site.php b/src/Script/Command/Site.php
deleted file mode 100644
index 8a6a8e7..0000000
--- a/src/Script/Command/Site.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-namespace App\Script\Command;
-
-use Symfony\Component\Console\Command\Command as SyCommand;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Input\InputArgument;
-use Symfony\Component\Console\Helper\ProgressBar;
-use App\Filesystem\CreateFile;
-use App\Filesystem\CreateDirectory;
-
-class Site extends SyCommand
-{
- protected function configure()
- {
- $this
- ->addArgument('name', InputArgument::REQUIRED, 'The name of the new site.');
-
- $this
- ->addArgument('domain', InputArgument::REQUIRED, 'The domain name of the new site.');
-
- $this
- ->setName('site:create')
- ->setDescription('Create a new site.')
- ->setHelp('This command allows you to create a new site.')
- ;
- }
-
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $taskCount = 6;
- $output->writeln(
- 'Creating new site with domain: '
- . $input->getArgument('domain')
- . ' and name: '
- . $input->getArgument('name')
- );
-
- $progressBar = new ProgressBar($output, $taskCount);
- $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message%');
- $progressBar->setFormat('custom');
- $progressBar->setMessage('Starting...');
- $progressBar->start();
- $progressBar->setMessage('Running pre-flight checks');
-
- $progressBar->advance();
- try {
- $create = new \App\Filesystem\CreateFile(DIPPER_ROOT . '/foo.test');
- $create = new \App\Filesystem\CreateDirectory(DIPPER_ROOT);
- sleep(1);
- } catch (\Exception $e) {
- $output->writeln('Error with pre-flight checks');
- $output->writeln($e->getMessage());
- exit;
- }
-
- $progressBar->advance();
- $progressBar->setMessage('Creating directory structure');
- sleep(1);
-
- $progressBar->advance();
- $progressBar->setMessage('Creating nginx config');
- sleep(1);
-
- $progressBar->advance();
- $progressBar->setMessage('Creating default index.php');
- sleep(1);
-
- $progressBar->advance();
- $progressBar->setMessage('Creating nginx config');
- sleep(1);
-
- $progressBar->advance();
- $progressBar->finish();
-
- $output->writeln('');
- $output->writeln('Complete');
- }
-}
diff --git a/src/Script/Command/Site/Create.php b/src/Script/Command/Site/Create.php
new file mode 100644
index 0000000..2526d2e
--- /dev/null
+++ b/src/Script/Command/Site/Create.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace App\Script\Command;
+
+use Symfony\Component\Console\Command\Command as SyCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Helper\ProgressBar;
+use App\Filesystem\CreateFile;
+use App\Filesystem\CreateDirectory;
+
+/**
+ * A new Symfony command for creating a new site deployment
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
+class Create extends SyCommand
+{
+ /**
+ * Configure the command
+ *
+ * @author Phil Burton <phil@d3r.com>
+ */
+ protected function configure()
+ {
+ $this->addArgument('name', InputArgument::REQUIRED, 'The name of the new site.');
+ $this->addArgument('domain', InputArgument::REQUIRED, 'The domain name of the new site.');
+
+ $this
+ ->setName('site:create')
+ ->setDescription('Create a new site.')
+ ->setHelp('This command allows you to create a new site.');
+ }
+
+ /**
+ * Run the command
+ *
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @author Phil Burton <phil@d3r.com>
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $taskCount = 6;
+
+ $name = $input->getArgument('name');
+ $domain = $input->getArgument('domain');
+
+ $output->writeln(
+ 'Creating new site with domain: '
+ . $input->getArgument('domain')
+ . ' and name: '
+ . $input->getArgument('name')
+ );
+
+ // Set-up progress bar
+ $progressBar = new ProgressBar($output, $taskCount);
+ $progressBar->setFormatDefinition('custom', ' %current%/%max% -- %message%');
+ $progressBar->setFormat('custom');
+ $progressBar->setMessage('Starting...');
+ $progressBar->start();
+ $progressBar->setMessage('Running pre-flight checks');
+
+ // Construct the file commands so we run checks first
+ $progressBar->advance();
+
+ $tasks = [];
+
+ try {
+ $tasks['Creating site directory'] = new \App\Filesystem\CreateDirectory(SITES_ROOT . $name);
+ $tasks['Creating logs directory'] = new \App\Filesystem\CreateDirectory(SITES_ROOT . $name . '/logs');
+ $tasks['Creating access log file'] = new \App\Filesystem\CreateFile(SITES_ROOT . $name . '/logs/' . $name . '.access_log');
+ $tasks['Creating error log file'] = new \App\Filesystem\CreateFile(SITES_ROOT . $name . '/logs/' . $name . '.errors_log');
+ $tasks['Creating web folder'] = new \App\Filesystem\CreateDirectory(SITES_ROOT . $name . '/web');
+ $tasks['Creating directory index.php'] = new \App\Filesystem\CreateFile(SITES_ROOT . $name . '/web/index.php');
+ $tasks['Creating nginx config file'] = new \App\Filesystem\CreateFile(CONFIG_ROOT . $name . '.conf');
+ } catch (\Exception $e) {
+ $output->writeln('Error with pre-flight checks');
+ $output->writeln($e->getMessage());
+ exit;
+ }
+
+ foreach ($tasks as $message => $task) {
+ // Create file in web root for execution
+ $progressBar->advance();
+ $progressBar->setMessage($message);
+ $task->execute();
+ sleep(1);
+ }
+
+
+ // Finish up
+ $progressBar->advance();
+ $progressBar->finish();
+ $output->writeln('');
+ $output->writeln('Complete');
+ }
+}