summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Filesystem/Create.php20
-rw-r--r--src/Filesystem/CreateDirectory.php25
-rw-r--r--src/Filesystem/CreateFile.php25
-rw-r--r--src/Script/Command/Site.php80
-rw-r--r--src/Script/Console.php16
5 files changed, 166 insertions, 0 deletions
diff --git a/src/Filesystem/Create.php b/src/Filesystem/Create.php
new file mode 100644
index 0000000..a1891db
--- /dev/null
+++ b/src/Filesystem/Create.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Filesystem;
+
+abstract class Create
+{
+ protected $filename;
+ protected $thing;
+
+ public function __construct(string $filename)
+ {
+ $this->filename = $filename;
+
+ if (!is_writable(dirname($filename))) {
+ throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename);
+ }
+ }
+
+ abstract public function excecute();
+}
diff --git a/src/Filesystem/CreateDirectory.php b/src/Filesystem/CreateDirectory.php
new file mode 100644
index 0000000..0c45c6c
--- /dev/null
+++ b/src/Filesystem/CreateDirectory.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Filesystem;
+
+use App\Filesystem\Create;
+
+class CreateDirectory extends Create
+{
+ protected $filename;
+ protected $thing = "directory";
+
+ public function __construct(string $filename)
+ {
+ parent::__construct($filename);
+
+ if (file_exists($filename)) {
+ throw new \Exception('Directory already exists at: ' . $filename);
+ }
+ }
+
+ public function excecute()
+ {
+ echo "execute";
+ }
+}
diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php
new file mode 100644
index 0000000..f41d4b9
--- /dev/null
+++ b/src/Filesystem/CreateFile.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Filesystem;
+
+use App\Filesystem\Create;
+
+class CreateFile extends Create
+{
+ protected $filename;
+ protected $thing = "file";
+
+ public function __construct(string $filename)
+ {
+ parent::__construct($filename);
+
+ if (file_exists($filename)) {
+ throw new \Exception('File already exists at: ' . $filename);
+ }
+ }
+
+ public function excecute()
+ {
+ echo "execute";
+ }
+}
diff --git a/src/Script/Command/Site.php b/src/Script/Command/Site.php
new file mode 100644
index 0000000..8a6a8e7
--- /dev/null
+++ b/src/Script/Command/Site.php
@@ -0,0 +1,80 @@
+<?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/Console.php b/src/Script/Console.php
new file mode 100644
index 0000000..926f41f
--- /dev/null
+++ b/src/Script/Console.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Script;
+
+use Symfony\Component\Console\Application;
+use App\Script\Command\Site;
+
+class Console
+{
+ public function __construct()
+ {
+ $application = new Application();
+ $application->add(new Site());
+ $application->run();
+ }
+}