Compare commits
No commits in common. "f24ce58b8590666582c629bb68e224d64f395a90" and "95f56a04d3fdf79c23f852e76bcb4726237c5bfa" have entirely different histories.
f24ce58b85
...
95f56a04d3
@ -15,7 +15,6 @@ use http\Message;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
use Itguild\Tables\ViewJsonTable;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\App;
|
||||
use kernel\Controller;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
||||
@ -63,7 +62,6 @@ class UserController extends Controller{
|
||||
{
|
||||
// $users = User::where(['role' => 1])->get();
|
||||
$users = User::all();
|
||||
//App::$header->add("asd", "asd");
|
||||
|
||||
$this->cgView->render("user/index.php", ['users' => $users]);
|
||||
}
|
||||
|
@ -5,9 +5,5 @@ $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
include_once __DIR__ . "/bootstrap/db.php";
|
||||
include_once __DIR__ . "/bootstrap/header.php";
|
||||
const ROOT_DIR = __DIR__;
|
||||
const KERNEL_DIR = __DIR__ . "/kernel";
|
||||
const CONSOLE_DIR = __DIR__ . "/kernel/console";
|
||||
|
||||
|
||||
|
@ -1,3 +1,18 @@
|
||||
<?php
|
||||
|
||||
\kernel\App::$db = new \kernel\Database();
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
|
||||
$capsule = new Capsule;
|
||||
$capsule->addConnection([
|
||||
'driver' => $_ENV['DB_DRIVER'],
|
||||
'host' => $_ENV['DB_HOST'],
|
||||
'database' => $_ENV['DB_NAME'],
|
||||
'username' => $_ENV['DB_USER'],
|
||||
'password' => $_ENV['DB_PASSWORD'],
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
]);
|
||||
// Setup the Eloquent ORM…
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
\kernel\App::$header = new \kernel\Header();
|
@ -4,15 +4,13 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"illuminate/database": "^11.14",
|
||||
"illuminate/filesystem": "^11.18.1",
|
||||
"craft-group/phroute": "^2.1",
|
||||
"vlucas/phpdotenv": "^5.6",
|
||||
"twig/twig": "^3.0",
|
||||
"twbs/bootstrap": "5.0.2",
|
||||
"itguild/tables": "^0.1.3",
|
||||
"madesimple/php-form-validator": "^2.9",
|
||||
"itguild/forms": "^0.1.1",
|
||||
"samejack/php-argv": "dev-master"
|
||||
"itguild/forms": "^0.1.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
202
composer.lock
generated
202
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "05960b2d73dd4ee5a824e5a9416486b2",
|
||||
"content-hash": "6f3aaa23fb01733bc2ac85dfaaf0dec3",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@ -603,73 +603,6 @@
|
||||
},
|
||||
"time": "2024-07-26T06:18:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/filesystem",
|
||||
"version": "v11.18.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/illuminate/filesystem.git",
|
||||
"reference": "43b8d2af61dd6ca882e192fa4ca803d2294d4507"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/illuminate/filesystem/zipball/43b8d2af61dd6ca882e192fa4ca803d2294d4507",
|
||||
"reference": "43b8d2af61dd6ca882e192fa4ca803d2294d4507",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/collections": "^11.0",
|
||||
"illuminate/contracts": "^11.0",
|
||||
"illuminate/macroable": "^11.0",
|
||||
"illuminate/support": "^11.0",
|
||||
"php": "^8.2",
|
||||
"symfony/finder": "^7.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-fileinfo": "Required to use the Filesystem class.",
|
||||
"ext-ftp": "Required to use the Flysystem FTP driver.",
|
||||
"ext-hash": "Required to use the Filesystem class.",
|
||||
"illuminate/http": "Required for handling uploaded files (^7.0).",
|
||||
"league/flysystem": "Required to use the Flysystem local driver (^3.0.16).",
|
||||
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^3.0).",
|
||||
"league/flysystem-ftp": "Required to use the Flysystem FTP driver (^3.0).",
|
||||
"league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^3.0).",
|
||||
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
|
||||
"symfony/filesystem": "Required to enable support for relative symbolic links (^7.0).",
|
||||
"symfony/mime": "Required to enable support for guessing extensions (^7.0)."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "11.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"functions.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Illuminate\\Filesystem\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "The Illuminate Filesystem package.",
|
||||
"homepage": "https://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"time": "2024-06-28T20:10:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "illuminate/macroable",
|
||||
"version": "v11.18.1",
|
||||
@ -1341,59 +1274,6 @@
|
||||
},
|
||||
"time": "2020-08-27T05:07:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "samejack/php-argv",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/samejack/php-argv.git",
|
||||
"reference": "0551f0f7fd38a5e9dcb316d5cc9028cdd62b21ac"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/samejack/php-argv/zipball/0551f0f7fd38a5e9dcb316d5cc9028cdd62b21ac",
|
||||
"reference": "0551f0f7fd38a5e9dcb316d5cc9028cdd62b21ac",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-coveralls/php-coveralls": "*@stable",
|
||||
"phpunit/phpunit": "~4.8|~5.7",
|
||||
"squizlabs/php_codesniffer": "*@stable"
|
||||
},
|
||||
"default-branch": true,
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"samejack\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "SJ",
|
||||
"email": "sj@toright.com",
|
||||
"homepage": "http://blog.toright.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "PHP CLI arguments parse.",
|
||||
"homepage": "https://github.com/samejack/php-argv",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"php"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/samejack/php-argv/issues",
|
||||
"source": "https://github.com/samejack/php-argv/tree/1.0.3"
|
||||
},
|
||||
"time": "2020-07-15T12:28:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/clock",
|
||||
"version": "v7.1.1",
|
||||
@ -1535,70 +1415,6 @@
|
||||
],
|
||||
"time": "2024-04-18T09:32:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v7.1.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/finder.git",
|
||||
"reference": "717c6329886f32dc65e27461f80f2a465412fdca"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca",
|
||||
"reference": "717c6329886f32dc65e27461f80f2a465412fdca",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/filesystem": "^6.4|^7.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Finder\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/finder/tree/v7.1.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-24T07:08:44+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.30.0",
|
||||
@ -1916,16 +1732,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/translation",
|
||||
"version": "v7.1.3",
|
||||
"version": "v7.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/translation.git",
|
||||
"reference": "8d5e50c813ba2859a6dfc99a0765c550507934a1"
|
||||
"reference": "cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/8d5e50c813ba2859a6dfc99a0765c550507934a1",
|
||||
"reference": "8d5e50c813ba2859a6dfc99a0765c550507934a1",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3",
|
||||
"reference": "cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1990,7 +1806,7 @@
|
||||
"description": "Provides tools to internationalize your application",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/translation/tree/v7.1.3"
|
||||
"source": "https://github.com/symfony/translation/tree/v7.1.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -2006,7 +1822,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-26T12:41:01+00:00"
|
||||
"time": "2024-05-31T14:57:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/translation-contracts",
|
||||
@ -2377,9 +2193,7 @@
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"samejack/php-argv": 20
|
||||
},
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "vendor/autoload.php";
|
||||
require 'bootstrap.php';
|
||||
|
||||
\kernel\console\ConsoleApp::create()->setArgv($argv)->load()->run();
|
40
index.php
40
index.php
@ -6,4 +6,42 @@ ini_set("display_errors", true);
|
||||
require_once "vendor/autoload.php";
|
||||
require 'bootstrap.php';
|
||||
|
||||
\kernel\App::create()->load()->run();
|
||||
use app\controllers\MainController;
|
||||
use app\controllers\UserController;
|
||||
use app\controllers\QuestionController;
|
||||
use app\controllers\AnswerController;
|
||||
use app\controllers\PostController;
|
||||
use app\helpers\Debug;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
$router = new RouteCollector();
|
||||
$router->get('/', [MainController::class, 'actionIndex']);
|
||||
$router->get('/example', [MainController::class, 'actionExample']);
|
||||
$router->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
$router->group(["prefix" => "user"], function (RouteCollector $router){
|
||||
$router->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
||||
$router->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
||||
$router->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
||||
$router->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
||||
$router->any('/update/{id}', [\app\controllers\UserController::class, 'actionUpdate']);
|
||||
$router->any("/edit/{id}", [\app\controllers\UserController::class, 'actionEdit']);
|
||||
$router->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
|
||||
});
|
||||
$router->group(["prefix" => "post"], function (RouteCollector $router){
|
||||
$router->get('/', [\app\controllers\PostController::class, 'actionIndex']);
|
||||
$router->get('/create', [\app\controllers\PostController::class, 'actionCreate']);
|
||||
$router->post("/", [\app\controllers\PostController::class, 'actionAdd']);
|
||||
$router->get('/{id}', [\app\controllers\PostController::class, 'actionView']);
|
||||
$router->any('/update/{id}', [\app\controllers\PostController::class, 'actionUpdate']);
|
||||
$router->any("/edit/{id}", [\app\controllers\PostController::class, 'actionEdit']);
|
||||
$router->get('/delete/{id}', [\app\controllers\PostController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
|
||||
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
|
||||
|
||||
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||
|
||||
|
||||
// Print out the value returned from the dispatched function
|
||||
echo $response;
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace kernel;
|
||||
|
||||
|
||||
|
||||
use app\helpers\Debug;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
class App
|
||||
{
|
||||
|
||||
static string $responseType = ResponseType::TEXT_HTML;
|
||||
|
||||
static CgRouteCollector $collector;
|
||||
|
||||
static Header $header;
|
||||
|
||||
public static Database $db;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$dispatcher = new Dispatcher(App::$collector->getData());
|
||||
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||
//header('Content-Type: ' . App::$responseType);
|
||||
App::$header->set();
|
||||
echo $response;
|
||||
}
|
||||
|
||||
public function load(): static
|
||||
{
|
||||
App::$collector = new CgRouteCollector();
|
||||
$this->setRouting();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRouting(): void
|
||||
{
|
||||
include ROOT_DIR . "/rout.php";
|
||||
}
|
||||
|
||||
public static function create(): App
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace kernel;
|
||||
|
||||
|
||||
use Phroute\Phroute\Route;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
class CgRouteCollector extends RouteCollector
|
||||
{
|
||||
public function crud($route, $handler, array $filters = []): CgRouteCollector
|
||||
{
|
||||
$this->addRoute(Route::GET, $route, array_merge($handler, ['actionIndex']), $filters);
|
||||
$this->addRoute(Route::GET, $route . '/{id}', array_merge($handler, ['actionView']), $filters);
|
||||
$this->addRoute(Route::POST, $route, array_merge($handler, ['actionStore']), $filters);
|
||||
$this->addRoute(Route::DELETE, $route, array_merge($handler, ['actionDelete']), $filters);
|
||||
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||
}
|
||||
|
||||
public function gridView($route, $handler, array $filters = []): CgRouteCollector
|
||||
{
|
||||
$this->addRoute(Route::GET, $route, array_merge($handler, ['actionIndex']), $filters);
|
||||
$this->addRoute(Route::GET, $route . '/{id}', array_merge($handler, ['actionView']), $filters);
|
||||
$this->addRoute(Route::ANY, $route . '/create', array_merge($handler, ['actionStore']), $filters);
|
||||
$this->addRoute(Route::POST, $route . '/delete', array_merge($handler, ['actionDelete']), $filters);
|
||||
return $this->addRoute(Route::ANY, $route . '/update/{id}', array_merge($handler, ['actionEdit']), $filters);
|
||||
}
|
||||
|
||||
public function authorization($route, $handler, array $filters = [])
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
public function exclude($action)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
public function console($route, $handler, array $filters = []): void
|
||||
{
|
||||
$this->addRoute(Route::GET, $route, $handler, $filters);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: kirill
|
||||
* Date: 03.08.19
|
||||
* Time: 23:51
|
||||
*/
|
||||
|
||||
namespace kernel;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
use Illuminate\Container\Container;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
class Database
|
||||
{
|
||||
/** @var Builder $capsule */
|
||||
public Builder $schema;
|
||||
|
||||
/** @var Capsule $capsule */
|
||||
public Capsule $capsule;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->capsule = new Capsule;
|
||||
$this->capsule->addConnection([
|
||||
'driver' => $_ENV['DB_DRIVER'],
|
||||
'host' => $_ENV['DB_HOST'],
|
||||
'database' => $_ENV['DB_NAME'],
|
||||
'username' => $_ENV['DB_USER'],
|
||||
'password' => $_ENV['DB_PASSWORD'],
|
||||
'charset' => $_ENV['DB_CHARSET'],
|
||||
'collation' => $_ENV['DB_COLLATION'],
|
||||
'prefix' => $_ENV['DB_PREFIX'],
|
||||
]);
|
||||
// Setup the Eloquent ORM…
|
||||
|
||||
$this->capsule->setAsGlobal();
|
||||
|
||||
$this->capsule->bootEloquent();
|
||||
|
||||
$this->schema = $this->capsule->schema();
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: kirill
|
||||
* Date: 16.06.19
|
||||
* Time: 0:22
|
||||
*/
|
||||
|
||||
namespace kernel;
|
||||
|
||||
|
||||
class Header
|
||||
{
|
||||
protected $list = [];
|
||||
|
||||
public function add($key, $value)
|
||||
{
|
||||
$this->list[$key] = $value;
|
||||
}
|
||||
|
||||
public function set()
|
||||
{
|
||||
foreach ($this->list as $key=>$v){
|
||||
header($key . ": " . $v);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: kirill
|
||||
* Date: 15.06.19
|
||||
* Time: 0:44
|
||||
*/
|
||||
|
||||
namespace kernel;
|
||||
|
||||
|
||||
class ResponseType
|
||||
{
|
||||
|
||||
const TEXT_HTML = 'text/html';
|
||||
const APPLICATION_JSON = 'application/json';
|
||||
const MULTIPART_FORM_DATA = 'multipart/form-data';
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace kernel\console;
|
||||
|
||||
|
||||
use Illuminate\Database\Migrations\MigrationCreator;
|
||||
|
||||
class CgMigrationCreator extends MigrationCreator
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the path to the stubs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function stubPath(): string
|
||||
{
|
||||
return ROOT_DIR . '/kernel/console/migrations/stubs';
|
||||
}
|
||||
|
||||
public static function getCustomStubPath(): string
|
||||
{
|
||||
return ROOT_DIR . '/kernel/console/migrations/stubs';
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace kernel\console;
|
||||
|
||||
|
||||
use app\helpers\Debug;
|
||||
use kernel\App;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
class ConsoleApp extends App
|
||||
{
|
||||
public array $argv;
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
if(!$rout = $this->getRout()){
|
||||
echo "Not found \n";
|
||||
exit();
|
||||
}
|
||||
$dispatcher = new Dispatcher(App::$collector->getData());
|
||||
$response = $dispatcher->dispatch('GET', $rout);
|
||||
echo $response;
|
||||
}
|
||||
|
||||
public function setArgv($argv): static
|
||||
{
|
||||
$this->argv = $argv;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRouting(): void
|
||||
{
|
||||
include CONSOLE_DIR . "/routs/cli.php";
|
||||
}
|
||||
|
||||
private function getRout()
|
||||
{
|
||||
if(isset($this->argv[1])){
|
||||
return $this->argv[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function create(): ConsoleApp
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace kernel\console;
|
||||
|
||||
|
||||
use kernel\console\Out;
|
||||
use samejack\PHP\ArgvParser;
|
||||
|
||||
class ConsoleController
|
||||
{
|
||||
public Out $out;
|
||||
protected array $argv;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->out = new Out();
|
||||
$argv = $_SERVER['argv'];
|
||||
unset($argv[0]);
|
||||
unset($argv[1]);
|
||||
if(!empty($argv)){
|
||||
$argvParser = new ArgvParser();
|
||||
$tmp = implode(" ", $argv);
|
||||
$this->argv = $argvParser->parseConfigs($tmp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace kernel\console;
|
||||
|
||||
|
||||
class Out
|
||||
{
|
||||
private $foreground_colors = array();
|
||||
private $background_colors = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Set up shell colors
|
||||
$this->foreground_colors['black'] = '0;30';
|
||||
$this->foreground_colors['dark_gray'] = '1;30';
|
||||
$this->foreground_colors['blue'] = '0;34';
|
||||
$this->foreground_colors['light_blue'] = '1;34';
|
||||
$this->foreground_colors['green'] = '0;32';
|
||||
$this->foreground_colors['light_green'] = '1;32';
|
||||
$this->foreground_colors['cyan'] = '0;36';
|
||||
$this->foreground_colors['light_cyan'] = '1;36';
|
||||
$this->foreground_colors['red'] = '0;31';
|
||||
$this->foreground_colors['light_red'] = '1;31';
|
||||
$this->foreground_colors['purple'] = '0;35';
|
||||
$this->foreground_colors['light_purple'] = '1;35';
|
||||
$this->foreground_colors['brown'] = '0;33';
|
||||
$this->foreground_colors['yellow'] = '1;33';
|
||||
$this->foreground_colors['light_gray'] = '0;37';
|
||||
$this->foreground_colors['white'] = '1;37';
|
||||
|
||||
$this->background_colors['black'] = '40';
|
||||
$this->background_colors['red'] = '41';
|
||||
$this->background_colors['green'] = '42';
|
||||
$this->background_colors['yellow'] = '43';
|
||||
$this->background_colors['blue'] = '44';
|
||||
$this->background_colors['magenta'] = '45';
|
||||
$this->background_colors['cyan'] = '46';
|
||||
$this->background_colors['light_gray'] = '47';
|
||||
}
|
||||
|
||||
// Returns colored string
|
||||
public function get($string, $foreground_color = null, $background_color = null)
|
||||
{
|
||||
$colored_string = "";
|
||||
|
||||
// Check if given foreground color found
|
||||
if (isset($this->foreground_colors[$foreground_color])) {
|
||||
$colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m";
|
||||
}
|
||||
// Check if given background color found
|
||||
if (isset($this->background_colors[$background_color])) {
|
||||
$colored_string .= "\033[" . $this->background_colors[$background_color] . "m";
|
||||
}
|
||||
|
||||
// Add string and end coloring
|
||||
$colored_string .= $string . "\033[0m";
|
||||
|
||||
return $colored_string;
|
||||
}
|
||||
|
||||
public function r($string, $foreground_color = null, $background_color = null)
|
||||
{
|
||||
echo $this->get($string, $foreground_color, $background_color) . "\n";
|
||||
}
|
||||
|
||||
// Returns all foreground color names
|
||||
public function getForegroundColors()
|
||||
{
|
||||
return array_keys($this->foreground_colors);
|
||||
}
|
||||
|
||||
// Returns all background color names
|
||||
public function getBackgroundColors()
|
||||
{
|
||||
return array_keys($this->background_colors);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\console\controllers;
|
||||
|
||||
use kernel\console\ConsoleController;
|
||||
|
||||
class MainController extends ConsoleController
|
||||
{
|
||||
|
||||
public function indexAction(): void
|
||||
{
|
||||
$this->out->r("Привет", "green");
|
||||
}
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace kernel\console\controllers;
|
||||
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use kernel\App;
|
||||
use kernel\console\CgMigrationCreator;
|
||||
use kernel\console\ConsoleController;
|
||||
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
|
||||
use Illuminate\Database\Migrations\MigrationCreator;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
|
||||
class MigrationController extends ConsoleController
|
||||
{
|
||||
//create migrations table
|
||||
public function actionCreateMigrationTable(): void
|
||||
{
|
||||
try {
|
||||
App::$db->schema->create('migration', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('migration', 255);
|
||||
$table->integer('batch');
|
||||
});
|
||||
$this->out->r("Success", 'green');
|
||||
}
|
||||
catch (\Exception $e){
|
||||
$this->out->r($e->getMessage(), 'red');
|
||||
}
|
||||
}
|
||||
|
||||
// create migrations
|
||||
public function actionCreate(): void
|
||||
{
|
||||
try {
|
||||
if (!isset($this->argv['name'])) {
|
||||
throw new \Exception('Missing migration "--name" specified');
|
||||
}
|
||||
$m = new CgMigrationCreator(new Filesystem(), CgMigrationCreator::getCustomStubPath());
|
||||
|
||||
$path = $this->argv['path'] ?? 'migrations';
|
||||
|
||||
$res = $m->create(
|
||||
$this->argv['name'],
|
||||
ROOT_DIR . '/' . $path,
|
||||
$this->argv['table'] ?? null,
|
||||
!isset($this->argv['update'])
|
||||
);
|
||||
$this->out->r(basename($res) . " created", 'green');
|
||||
} catch (\Exception $e) {
|
||||
$this->out->r('Message: ' .$e->getMessage(), 'red');
|
||||
}
|
||||
}
|
||||
|
||||
//execute migrations
|
||||
public function actionRun(): void
|
||||
{
|
||||
try {
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
//$migrationPaths = array_merge(App::$migrationsPaths, [ROOT_DIR . '/migrations']);
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
$res = $m->run($migrationPaths);
|
||||
foreach ($res as $re){
|
||||
$this->out->r(basename($re), 'green');
|
||||
}
|
||||
}
|
||||
catch (\Exception $e){
|
||||
$this->out->r('Message: ' .$e->getMessage(), 'red');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRollback(): void
|
||||
{
|
||||
try {
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
//$migrationPaths = array_merge(App::$migrationsPaths, [WORKSPACE_DIR . '/console/migrations']);
|
||||
$migrationPaths = [ROOT_DIR . '/console/migrations'];
|
||||
$res = $m->rollback($migrationPaths);
|
||||
foreach ($res as $re){
|
||||
$this->out->r(basename($re), 'green');
|
||||
}
|
||||
}
|
||||
catch (\Exception $e){
|
||||
$this->out->r('Message: ' .$e->getMessage(), 'red');
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DummyClass extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use core\App;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DummyClass extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
App::$db->schema->create('DummyTable', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
App::$db->schema->dropIfExists('DummyTable');
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('{{ table }}', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('{{ table }}');
|
||||
}
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('{{ table }}', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('{{ table }}', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
use core\App;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DummyClass extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
App::$db->schema->table('DummyTable', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
App::$db->schema->table('DummyTable', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->console("hello", [\kernel\console\controllers\MainController::class, "indexAction"]);
|
||||
|
||||
App::$collector->group(["prefix" => "migration"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('run', [\kernel\console\controllers\MigrationController::class, 'actionRun']);
|
||||
App::$collector->console('init', [\kernel\console\controllers\MigrationController::class, 'actionCreateMigrationTable']);
|
||||
App::$collector->console('create', [\kernel\console\controllers\MigrationController::class, 'actionCreate']);
|
||||
App::$collector->console('rollback', [\kernel\console\controllers\MigrationController::class, 'actionRollback']);
|
||||
});
|
||||
|
8
m.php
8
m.php
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
use _migrations\AnswerMigration;
|
||||
use _migrations\PostMigration;
|
||||
use _migrations\QuestionMigration;
|
||||
use _migrations\UserMigration;
|
||||
use migrations\AnswerMigration;
|
||||
use migrations\PostMigration;
|
||||
use migrations\QuestionMigration;
|
||||
use migrations\UserMigration;
|
||||
|
||||
require_once __DIR__ . "/vendor/autoload.php";
|
||||
require_once __DIR__ . "/bootstrap.php";
|
||||
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('some', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('some');
|
||||
}
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace _migrations;
|
||||
namespace migrations;
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace _migrations;
|
||||
namespace migrations;
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace _migrations;
|
||||
namespace migrations;
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace _migrations;
|
||||
namespace migrations;
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
29
rout.php
29
rout.php
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
use app\controllers\MainController;
|
||||
use kernel\App;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
|
||||
App::$collector->get('/', [MainController::class, 'actionIndex']);
|
||||
App::$collector->get('/example', [MainController::class, 'actionExample']);
|
||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){
|
||||
App::$collector->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\app\controllers\UserController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\app\controllers\UserController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\app\controllers\UserController::class, 'actionDelete']);
|
||||
});
|
||||
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
|
||||
App::$collector->get('/', [\app\controllers\PostController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\app\controllers\PostController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\app\controllers\PostController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\app\controllers\PostController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\app\controllers\PostController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\app\controllers\PostController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\app\controllers\PostController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user