-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
383 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace Kathamo\App\CommandManager; | ||
|
||
class Manager | ||
class Helper | ||
{ | ||
public function input($label) | ||
{ | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Kathamo\App\Commands; | ||
|
||
trait CommandHelper | ||
{ | ||
protected $input = []; | ||
protected $root_path; | ||
protected $target_path; | ||
|
||
public function input($label) | ||
{ | ||
return readline( | ||
sprintf(" %s%s %s", "\033[1;34m", $label, "\033[0m") | ||
); | ||
} | ||
|
||
protected function getConfig() | ||
{ | ||
if (! is_file($this->root_path . "/configs/config.php")) { | ||
throw new \Exception("Config file not found."); | ||
} | ||
return require $this->root_path . "/configs/config.php"; | ||
} | ||
|
||
protected function generateFile($template) | ||
{ | ||
$data = array_merge($this->input, $this->getConfig()); | ||
$data['namespace_suffix'] = ""; | ||
if (! empty($data['input_path'])) { | ||
$data['namespace_suffix'] = "\\" . str_replace("/", "\\", $data['input_path']); | ||
} | ||
|
||
$controller_template = dirname(__DIR__) . "/templates/partials/$template"; | ||
$mustache = new \Mustache_Engine(array('entity_flags' => ENT_QUOTES)); | ||
$file_content = $mustache->render(file_get_contents($controller_template), $data); | ||
|
||
$this->create($data, $file_content); | ||
} | ||
|
||
protected function create($data, $file_content) | ||
{ | ||
$controller_dir = $this->target_path . $data['input_path']; | ||
if (! empty($data['input_path']) && ! is_dir($controller_dir)) { | ||
mkdir($controller_dir); | ||
} | ||
if (is_dir($controller_dir)) { | ||
$target_path = $controller_dir . "/"; | ||
} | ||
|
||
$file = fopen( | ||
$target_path . $data['input_class_name'] . ".php", "w" | ||
); | ||
fwrite($file, $file_content); | ||
fclose($file); | ||
} | ||
} |
24 changes: 18 additions & 6 deletions
24
src/CommandManager/Scaffold.php → src/Commands/Creation/Scaffold.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
namespace Kathamo\App\Commands\Creation; | ||
|
||
use Kathamo\App\Commands\CommandHelper; | ||
use Kathamo\App\Services\CreateTemplateFiles; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class Template extends Command | ||
{ | ||
use CommandHelper; | ||
|
||
private $kathamo_path = '/var/www/html/wp-content/plugins/kathamo'; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('create create:template') | ||
->setDescription('Cli for Kathamo framework.'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
new CreateTemplateFiles($this->kathamo_path); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
<?php | ||
namespace Kathamo\App\Commands; | ||
|
||
use Kathamo\App\CommandManager\Scaffold; | ||
use Kathamo\App\CommandManager\Template; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Application; | ||
use Kathamo\App\Commands\Creation\Scaffold; | ||
use Kathamo\App\Commands\Creation\Template; | ||
use Kathamo\App\Commands\Make\MakeController; | ||
use Kathamo\App\Commands\Make\MakeMigration; | ||
use Kathamo\App\Commands\Make\MakeService; | ||
|
||
class KathamoCLI extends Command | ||
class KathamoCLI | ||
{ | ||
protected function configure() | ||
public function __construct() | ||
{ | ||
$this->setName('create') | ||
->setDescription('Cli for Kathamo framework.') | ||
->addOption('new') | ||
->addOption('template'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
if ($input->getOption('new')) { | ||
new Scaffold(); | ||
} | ||
$app = new Application(); | ||
$app->add(new Scaffold()); | ||
$app->add(new Template()); | ||
|
||
if ($input->getOption('template')) { | ||
new Template(); | ||
} | ||
$app->add(new MakeMigration()); | ||
$app->add(new MakeController()); | ||
$app->add(new MakeService()); | ||
$app->add(new MakeMigration()); | ||
|
||
return Command::SUCCESS; | ||
$app->run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Kathamo\App\Commands\Make; | ||
|
||
use Kathamo\App\Commands\CommandHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class MakeController extends Command | ||
{ | ||
use CommandHelper; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('make make:controller') | ||
->setDescription('New Controller for plugin') | ||
->setAliases(['make:c']); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->getInput(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
public function getInput() | ||
{ | ||
$this->root_path = getcwd(); | ||
$this->target_path = $this->root_path . "/app/Controllers/"; | ||
$this->input['input_class_name'] = $this->input("Controller Name:"); | ||
$this->input['input_path'] = $this->input("Path [app/Controllers/]:"); | ||
|
||
$this->generateFile('Controller_php.mustache'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Kathamo\App\Commands\Make; | ||
|
||
use Kathamo\App\Commands\CommandHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class MakeMiddleware extends Command | ||
{ | ||
use CommandHelper; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('make make:middleware') | ||
->setDescription('New Middleware for plugin') | ||
->setAliases(['make:mw']); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->getInput(); | ||
$this->generateMiddleware(); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
public function getInput() | ||
{ | ||
$this->root_path = getcwd(); | ||
$this->target_path = $this->root_path . "/app/Controllers/Middleware/"; | ||
$this->input['input_class_name'] = $this->input("Middleware Class Name:"); | ||
$this->input['middleware_key'] = $this->input("Middleware key:"); | ||
$this->input['input_path'] = $this->input("Path [app/Controllers/Middleware]:"); | ||
} | ||
|
||
private function generateMiddleware() | ||
{ | ||
$data = $this->input; | ||
$config_data = $this->getConfig($this->root_path); | ||
$middware_list = $config_data['middlewares']; | ||
$middleware_name = $config_data['namaspace_root'] . "\App\Controllers\Middleware\\" . $data['input_class_name']; | ||
$middware_list[$data['middleware_key']] = $middleware_name; | ||
|
||
$this->writeConfig($middware_list); | ||
$this->generateFile('Middleware_php.mustache'); | ||
} | ||
|
||
private function writeConfig($data) | ||
{ | ||
$schema = ''; | ||
foreach ($data as $key => $i) { | ||
$schema .= "'$key' => $i::class,\n\t\t"; | ||
} | ||
|
||
$controller_template = dirname(__DIR__) . '/templates/partials/config_php.mustache'; | ||
$mustache = new \Mustache_Engine(); | ||
$file_content = $mustache->render( | ||
file_get_contents($controller_template), | ||
['middleware_list' => $schema] | ||
); | ||
|
||
$filesystem = new Filesystem; | ||
$filesystem->dumpFile($this->root_path . '/Configs/config.php', $file_content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Kathamo\App\Commands\Make; | ||
|
||
use Kathamo\App\Commands\CommandHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class MakeMigration extends Command | ||
{ | ||
use CommandHelper; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('make make:migration') | ||
->setDescription('New Migration class for plugin') | ||
->setAliases(['make:m']); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->getInput(); | ||
$this->generateFile('Migration_php.mustache'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
public function getInput() | ||
{ | ||
$this->root_path = getcwd(); | ||
$this->target_path = $this->root_path . "/Database/Migrations/"; | ||
$this->input['input_class_name'] = $this->input("Migration Name:"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Kathamo\App\Commands\Make; | ||
|
||
use Kathamo\App\Commands\CommandHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class MakeService extends Command | ||
{ | ||
use CommandHelper; | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('make make:service') | ||
->setDescription('New Service for plugin') | ||
->setAliases(['make:s']); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->getInput(); | ||
$this->generateFile('Service_php.mustache'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
public function getInput() | ||
{ | ||
$this->root_path = getcwd(); | ||
$this->target_path = getcwd() . "/app/Services/"; | ||
$this->input['input_class_name'] = $this->input("Service Name:"); | ||
$this->input['input_path'] = $this->input("Path [app/Services/]:"); | ||
} | ||
} |
Oops, something went wrong.