Commit 2d83844e authored by m.jooibar's avatar m.jooibar
Browse files

add model

parent 7de8b33b
......@@ -12,4 +12,6 @@ abstract class Listener
{
$this->input = $input;
}
abstract public function boot();
}
\ No newline at end of file
......@@ -301,7 +301,7 @@ class Route
}
}
self::$JK_MODULES = $this->modules = $foundedModules;
$autoload['autoload']['psr-4'] = [];
if (sizeof($foundedModules) >= 1) {
......@@ -420,10 +420,10 @@ class Route
}
}
}
$this->User = \Joonika\Modules\Users\Users::getUser(self::JK_LOGINID(), $this);
$middleWare = new kernel(self::JK_LOGINID(), $this);
$middleWare->dispatch();
if ($_SERVER['SCRIPT_NAME'] != "dev") {
$this->User = \Joonika\Modules\Users\Users::getUser(self::JK_LOGINID(), $this);
$middleWare = new kernel(self::JK_LOGINID(), $this);
$middleWare->dispatch();
self::sendRequestToController();
if (FS::isExistIsFileIsReadable(self::JK_SITE_PATH() . 'themes' . self::DS() . self::JK_THEME() . self::DS() . 'inc' . self::DS() . "foot.php")) {
$this->View->foot_file = self::JK_SITE_PATH() . 'themes' . self::DS() . self::JK_THEME() . self::DS() . 'inc' . self::DS() . "foot.php";
......
......@@ -121,6 +121,18 @@ class AppCommand extends Command
]
]
],
"module:event" => [
"title" => "create new event for module",
"arguments" => ["name", 'moduleName'],
],
"module:listener" => [
"title" => "create new listener for module",
"arguments" => ["name", 'moduleName'],
],
"module:model" => [
"title" => "create new model for module",
"arguments" => ["name", 'moduleName', 'tableName'],
],
"module:test" => [
"title" => "create new test for module",
"arguments" => ["name", 'moduleName'],
......@@ -266,7 +278,7 @@ class AppCommand extends Command
} else {
FS::mkDir(JK_SITE_PATH() . "storage");
}
$this->output->writeln("all files installed");
}
......
......@@ -181,6 +181,154 @@ class module extends baseCommand
FS::filePutContent($filePath, $getSample);
}
public function model()
{
$name = $this->checkInputArguments('name');
$moduleName = strtolower($this->checkInputArguments('moduleName'));
$tableName = strtolower($this->checkInputArguments('tableName'));
$this->ask('Please enter model name ( you can exit with Ctrl + C )', $name, true);
$this->ask('Please enter module name ( you can exit with Ctrl + C )', $moduleName, true);
$this->ask('Please enter table name ( you can exit with Ctrl + C )', $tableName, false);
$this->checkModuleIsValid($moduleName);
$namespace = "Modules\\$moduleName\Models";
\Joonika\FS::mkDir(__DIR__ . "/../../../../../modules/" . $moduleName . "/Models", 0777, true);
$mkDir = __DIR__ . "/../../../../../modules/" . $moduleName . "/Models";
$getSample = FS::fileGetContent(__dir__ . "/../templates/files/model/model.txt");
$getSample = str_replace("{namespace}", $namespace, $getSample);
$getSample = str_replace("{name}", ucfirst($name), $getSample);
if ($tableName) {
$getSample = str_replace("{tableName}", $tableName, $getSample);
} else {
$tableName = '';
$last_letter = strtolower($name[strlen($name) - 1]);
switch ($last_letter) {
case 'y':
$tableName = substr($name, 0, -1) . 'ies';
break;
case 's':
$tableName = $name . 'es';
break;
default:
$tableName = $name . 's';
break;
}
$getSample = str_replace("{tableName}", $tableName, $getSample);
}
$filePath = $mkDir . '/' . ucfirst($name) . '.php';
FS::filePutContent($filePath, $getSample);
}
public function event()
{
$name = $this->checkInputArguments('name');
$moduleName = strtolower($this->checkInputArguments('moduleName'));
$this->ask('Please enter event name ( you can exit with Ctrl + C )', $name, true);
$this->ask('Please enter module name ( you can exit with Ctrl + C )', $moduleName, true);
$this->checkModuleIsValid($moduleName);
$namespace = "Modules\\$moduleName\Events";
$providerNamespace = "Modules\\$moduleName\Providers";
\Joonika\FS::mkDir(__DIR__ . "/../../../../../modules/" . $moduleName . "/Events", 0777, true);
\Joonika\FS::mkDir(__DIR__ . "/../../../../../modules/" . $moduleName . "/Providers", 0777, true);
$path = explode('\\', $name);
$name = array_pop($path);
$mkDir = __DIR__ . "/../../../../../modules/" . $moduleName . "/Events";
$providerMkDir = __DIR__ . "/../../../../../modules/" . $moduleName . "/Providers";
if (sizeof($path) > 0) {
foreach ($path as $folder) {
$mkDir = $mkDir . '/' . $folder;
if (!\Joonika\FS::isDir($mkDir)) {
\Joonika\FS::mkDir($mkDir, 0777);
}
}
}
$getSample = FS::fileGetContent(__dir__ . "/../templates/files/eventListener/events.txt");
$path = sizeof($path) > 0 ? '\\' . join('\\', $path) : '';
$getSample = str_replace("{namespace}", $namespace . $path, $getSample);
$getSample = str_replace("{name}", $name, $getSample);
$filePath = $mkDir . '/' . $name . '.php';
FS::filePutContent($filePath, $getSample);
//------------- create eventListener file
if (!FS::isExistIsFileIsReadable(__DIR__ . "/../../../../../modules/" . $moduleName . "/Providers/EventListener.php")) {
$getSample = FS::fileGetContent(__dir__ . "/../templates/files/eventListener/eventListener.txt");
$getSample = str_replace("{namespace}", $providerNamespace, $getSample);
$getSample = str_replace("{name}", 'EventListener', $getSample);
$filePath = $providerMkDir . '/EventListener.php';
FS::filePutContent($filePath, $getSample);
}
}
public function listener()
{
$name = $this->checkInputArguments('name');
$moduleName = strtolower($this->checkInputArguments('moduleName'));
$this->ask('Please enter listener name ( you can exit with Ctrl + C )', $name, true);
$this->ask('Please enter module name ( you can exit with Ctrl + C )', $moduleName, true);
$this->checkModuleIsValid($moduleName);
$namespace = "Modules\\$moduleName\Listeners";
$providerNamespace = "Modules\\$moduleName\Providers";
\Joonika\FS::mkDir(__DIR__ . "/../../../../../modules/" . $moduleName . "/Listeners", 0777, true);
\Joonika\FS::mkDir(__DIR__ . "/../../../../../modules/" . $moduleName . "/Providers", 0777, true);
$path = explode('\\', $name);
$name = array_pop($path);
$mkDir = __DIR__ . "/../../../../../modules/" . $moduleName . "/Listeners";
$providerMkDir = __DIR__ . "/../../../../../modules/" . $moduleName . "/Providers";
if (sizeof($path) > 0) {
foreach ($path as $folder) {
$mkDir = $mkDir . '/' . $folder;
if (!\Joonika\FS::isDir($mkDir)) {
\Joonika\FS::mkDir($mkDir, 0777);
}
}
}
$getSample = FS::fileGetContent(__dir__ . "/../templates/files/eventListener/listenere.txt");
$path = sizeof($path) > 0 ? '\\' . join('\\', $path) : '';
$getSample = str_replace("{namespace}", $namespace . $path, $getSample);
$getSample = str_replace("{name}", $name, $getSample);
$filePath = $mkDir . '/' . $name . '.php';
FS::filePutContent($filePath, $getSample);
//------------- create eventListener file
if (!FS::isExistIsFileIsReadable(__DIR__ . "/../../../../../modules/" . $moduleName . "/Providers/EventListener.php")) {
$getSample = FS::fileGetContent(__dir__ . "/../templates/files/eventListener/eventListener.txt");
$getSample = str_replace("{namespace}", $providerNamespace, $getSample);
$getSample = str_replace("{name}", 'EventListener', $getSample);
$filePath = $providerMkDir . '/EventListener.php';
FS::filePutContent($filePath, $getSample);
}
}
public function controller()
{
$name = $this->checkInputArguments('name');
......
<?php
namespace {namespace};
use Joonika\EventListener\EventListenerScaffold;
class {name} extends EventListenerScaffold
{
// $list property is required
public $list = [
'event class namespace' => [
'listener class namespace',
'listener class namespace',
'listener class namespace',
'.',
'.',
'.',
'.'
],
];
}
<?php
namespace {namespace};
use Joonika\EventListener\Events;
class {name} extends Events
{
}
\ No newline at end of file
<?php
namespace {namespace};
use Joonika\EventListener\Listener;
class {name} extends Listener
{
// boot method is required
public function boot()
{
// TODO: Implement boot() method.
}
}
<?php
namespace {namespace};
use Joonika\Model\Model;
class {name} extends Model
{
protected $table = "{tableName}";
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment