aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2020-04-01 12:49:07 +0200
committerWilly Micieli <micieli@laposte.net>2020-04-01 12:49:07 +0200
commitf0a6f2f9b80d4e0ac2e45ef3bbbb8b9be8949172 (patch)
treef515bcd8106d262ce6c976f8be08d4fd2d4c6537
parent34c1ed65e772971dfb8193a63bc3cf6f8ba966cb (diff)
downloadeywa-omaticayas.zip
eywa-omaticayas.tar.gz
fix: fix bugs clean code add code verificationsomaticayas
-rw-r--r--app/Application.php13
-rwxr-xr-xapp/Console/Hello.php1
-rw-r--r--app/Console/Init/Configure.php43
-rw-r--r--app/Controllers/Admin/AdminController.php63
-rw-r--r--app/Controllers/Auth/AuthController.php35
-rw-r--r--app/Controllers/Demo/Demo.php16
-rwxr-xr-xapp/Controllers/Email/WriteController.php104
-rw-r--r--app/Controllers/Home/HomeController.php14
-rw-r--r--app/Forms/Auth/LoginForm.php13
-rw-r--r--app/Forms/UsersForm.php6
-rw-r--r--app/Forms/Write/ContactForm.php1
-rw-r--r--[-rwxr-xr-x]app/Middleware/Security/Ip.php (renamed from app/Middleware/IpMiddleware.php)6
-rw-r--r--app/Models/Auth/Authentication.php (renamed from app/Models/User.php)4
-rw-r--r--app/Models/Users/Users.php15
-rw-r--r--app/Views/Auth/home.html (renamed from app/Views/Home/404.php)0
-rw-r--r--app/Views/Auth/home.php5
-rw-r--r--app/Views/Auth/login.html1
-rw-r--r--app/Views/Auth/login.php3
-rw-r--r--app/Views/Home/404.html0
-rw-r--r--app/Views/Home/hello.html (renamed from app/Views/Home/hello.php)0
-rw-r--r--app/Views/Home/home.html3
-rwxr-xr-xapp/Views/Home/home.php18
-rw-r--r--app/Views/layout.php1
-rw-r--r--[-rwxr-xr-x]app/Views/maintenance.php18
-rwxr-xr-xcomposer.json16
-rwxr-xr-xdb/Migrations/AddPhoneToUsers.php1
-rwxr-xr-xdb/Migrations/CreateAuthTable.php8
-rwxr-xr-xdb/Migrations/CreateUsersTable.php1
-rwxr-xr-xdb/Seeds/AuthSeeder.php10
-rwxr-xr-xdb/Seeds/UserSeeder.php12
-rwxr-xr-xeywa/Application/App.php35
-rwxr-xr-xeywa/Application/Environment/Env.php10
-rwxr-xr-xeywa/Application/Eywa.php15
-rwxr-xr-xeywa/Application/Zen.php843
-rwxr-xr-xeywa/Cache/FileCache.php17
-rwxr-xr-xeywa/Cache/MemcacheCache.php6
-rwxr-xr-xeywa/Cache/RedisCache.php2
-rwxr-xr-xeywa/Collection/Collect.php23
-rwxr-xr-xeywa/Configuration/Config.php25
-rwxr-xr-xeywa/Console/App/AppSend.php110
-rwxr-xr-xeywa/Console/App/Coverage.php52
-rwxr-xr-xeywa/Console/App/Dkim.php62
-rwxr-xr-xeywa/Console/App/Key.php3
-rwxr-xr-xeywa/Console/App/Serve.php50
-rwxr-xr-xeywa/Console/App/TestCommand.php52
-rwxr-xr-xeywa/Console/Cache/ClearCache.php6
-rwxr-xr-xeywa/Console/Console.php20
-rwxr-xr-xeywa/Console/Database/CleanDatabase.php6
-rwxr-xr-xeywa/Console/Database/DropTable.php223
-rwxr-xr-xeywa/Console/Database/ExportDatabase.php8
-rwxr-xr-xeywa/Console/Database/Grant.php1
-rwxr-xr-xeywa/Console/Database/ImportDatabase.php10
-rwxr-xr-xeywa/Console/Database/InstallDatabase.php135
-rwxr-xr-xeywa/Console/Database/MigrateDatabase.php3
-rwxr-xr-xeywa/Console/Database/RollbackDatabase.php3
-rwxr-xr-xeywa/Console/Database/SeedDatabase.php52
-rwxr-xr-xeywa/Console/Database/ShowTable.php129
-rwxr-xr-xeywa/Console/Database/ShowUsers.php83
-rwxr-xr-xeywa/Console/Database/TruncateTable.php82
-rwxr-xr-xeywa/Console/Database/UninstallDatabase.php73
-rwxr-xr-xeywa/Console/Generate/GenerateCommand.php41
-rwxr-xr-xeywa/Console/Generate/GenerateContainer.php8
-rwxr-xr-xeywa/Console/Generate/GenerateController.php32
-rwxr-xr-xeywa/Console/Generate/GenerateForm.php20
-rwxr-xr-xeywa/Console/Generate/GenerateMiddleware.php32
-rwxr-xr-xeywa/Console/Generate/GenerateMigration.php8
-rwxr-xr-xeywa/Console/Generate/GenerateModel.php42
-rwxr-xr-xeywa/Console/Generate/GenerateSeeds.php8
-rwxr-xr-xeywa/Console/Generate/GenerateTest.php10
-rwxr-xr-xeywa/Console/Generate/GenerateValidator.php8
-rwxr-xr-xeywa/Console/Generate/GenerateView.php34
-rwxr-xr-xeywa/Console/Get/Documentation.php92
-rwxr-xr-xeywa/Console/Get/Wanted.php73
-rwxr-xr-xeywa/Console/Lang/CreateCatalogues.php92
-rwxr-xr-xeywa/Console/Lang/UpdateCatalogues.php78
-rwxr-xr-xeywa/Console/Mode/DevMode.php2
-rwxr-xr-xeywa/Console/Mode/Maintenance.php67
-rwxr-xr-xeywa/Console/Mode/ProductionMode.php15
-rw-r--r--eywa/Console/Records/Records.php9
-rwxr-xr-xeywa/Console/Routes/AddRoute.php118
-rwxr-xr-xeywa/Console/Routes/FindRoute.php28
-rwxr-xr-xeywa/Console/Routes/ListRoute.php2
-rwxr-xr-xeywa/Console/Routes/RemoveRoute.php30
-rwxr-xr-xeywa/Console/Routes/UpdateRoute.php108
-rwxr-xr-xeywa/Console/Shell.php1
-rwxr-xr-xeywa/Database/Base/Base.php41
-rwxr-xr-xeywa/Database/Connexion/Connect.php95
-rwxr-xr-xeywa/Database/Connexion/Connexion.php14
-rwxr-xr-xeywa/Database/Import/Import.php3
-rwxr-xr-xeywa/Database/Migration/CreateMigrationTable.php7
-rw-r--r--eywa/Database/Migration/Evolution.php60
-rw-r--r--eywa/Database/Migration/Migrate.php95
-rwxr-xr-xeywa/Database/Migration/Migration.php14
-rw-r--r--eywa/Database/Model/Interact.php1
-rwxr-xr-xeywa/Database/Model/Model.php11
-rw-r--r--eywa/Database/Query/Records.php32
-rwxr-xr-xeywa/Database/Query/Sql.php224
-rwxr-xr-xeywa/Database/Seed/Seeder.php7
-rwxr-xr-xeywa/Database/Seed/Seeding.php2
-rw-r--r--eywa/Database/Table/Records.php3
-rwxr-xr-xeywa/Database/Table/Table.php222
-rwxr-xr-xeywa/Database/User/User.php1
-rwxr-xr-xeywa/Debug/Dumper.php5
-rwxr-xr-xeywa/Debug/HtmlDumper.php30
-rwxr-xr-xeywa/Detection/Detect.php15
-rwxr-xr-xeywa/Exception/Kedavra.php1
-rw-r--r--eywa/File/Assets.php11
-rwxr-xr-xeywa/File/File.php71
-rwxr-xr-xeywa/Html/Form/Form.php102
-rw-r--r--eywa/Html/Navigation/Navigation.php21
-rwxr-xr-xeywa/Html/Pagination/Pagination.php20
-rwxr-xr-xeywa/Http/Controller/Controller.php4
-rw-r--r--eywa/Http/Controller/Crud.php5
-rwxr-xr-xeywa/Http/Curl/Curl.php1
-rwxr-xr-xeywa/Http/Middleware/Middleware.php1
-rwxr-xr-xeywa/Http/Parameter/Uploaded/UploadedFile.php32
-rwxr-xr-xeywa/Http/Parameter/Uploaded/UploadedFileInterface.php11
-rwxr-xr-xeywa/Http/Request/Request.php55
-rwxr-xr-xeywa/Http/Request/ServerRequest.php9
-rwxr-xr-xeywa/Http/Response/JsonResponse.php2
-rwxr-xr-xeywa/Http/Response/RedirectResponse.php3
-rwxr-xr-xeywa/Http/Response/Response.php16
-rwxr-xr-xeywa/Http/Routing/RouteResult.php42
-rwxr-xr-xeywa/Http/Routing/Router.php71
-rw-r--r--eywa/Http/Server/Http.php3
-rwxr-xr-xeywa/Http/View/View.php411
-rwxr-xr-xeywa/Ioc/Container.php1
-rwxr-xr-xeywa/Ioc/Ioc.php229
-rwxr-xr-xeywa/Message/Email/Write.php45
-rwxr-xr-xeywa/Message/Flash/Flash.php4
-rwxr-xr-xeywa/Security/Authentication/Auth.php278
-rw-r--r--eywa/Security/Authentication/AuthInterface.php10
-rwxr-xr-xeywa/Security/Crypt/Crypter.php26
-rwxr-xr-xeywa/Security/Csrf/Csrf.php27
-rwxr-xr-xeywa/Security/Hashing/Hash.php6
-rwxr-xr-xeywa/Security/Middleware/CsrfMiddleware.php1
-rwxr-xr-xeywa/Session/ArraySession.php1
-rwxr-xr-xeywa/Session/Session.php1
-rwxr-xr-xeywa/Testing/Unit.php13
-rwxr-xr-xeywa/Time/Timing.php3
-rwxr-xr-xeywa/Validate/Validator.php93
-rwxr-xr-xgrumphp.yml2
-rwxr-xr-xhelpers/admin.php261
-rwxr-xr-xhelpers/const.php75
-rwxr-xr-xhelpers/web.php32
-rwxr-xr-xioc/Admin/Admin.php1
-rw-r--r--ioc/App.php1
-rw-r--r--ioc/Dev/Dev.php1
-rwxr-xr-xioc/Web/Web.php6
-rw-r--r--phpcs.xml15
-rwxr-xr-xshaolin2
-rw-r--r--tests/Container/IocTest.php23
-rw-r--r--tests/Helpers/AdminTest.php104
-rw-r--r--tests/Helpers/WebTest.php28
-rw-r--r--tests/Html/FormTest.php9
-rw-r--r--tests/Http/RequestTest.php46
-rw-r--r--tests/Http/RouterTest.php1
-rw-r--r--tests/Security/AuthTest.php39
-rwxr-xr-xweb/index.php2
159 files changed, 3725 insertions, 2963 deletions
diff --git a/app/Application.php b/app/Application.php
index b291a25..3741e5b 100644
--- a/app/Application.php
+++ b/app/Application.php
@@ -1,6 +1,5 @@
<?php
-
namespace App;
use Eywa\Application\App;
@@ -58,8 +57,16 @@ class Application
* @param User $user
* @param Env $env
*/
- public function __construct(Connect $connect, Base $base, Flash $flash, Request $request, Table $table, App $app, User $user, Env $env)
- {
+ public function __construct(
+ Connect $connect,
+ Base $base,
+ Flash $flash,
+ Request $request,
+ Table $table,
+ App $app,
+ User $user,
+ Env $env
+ ) {
$this->connect = $connect;
$this->base = $base;
$this->flash = $flash;
diff --git a/app/Console/Hello.php b/app/Console/Hello.php
index 5f881ce..44abdcd 100755
--- a/app/Console/Hello.php
+++ b/app/Console/Hello.php
@@ -1,6 +1,5 @@
<?php
-
namespace App\Console;
use Symfony\Component\Console\Command\Command;
diff --git a/app/Console/Init/Configure.php b/app/Console/Init/Configure.php
new file mode 100644
index 0000000..a74f9e7
--- /dev/null
+++ b/app/Console/Init/Configure.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Console\Init;
+
+use Eywa\File\File;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+class Configure extends Command
+{
+ protected static $defaultName = 'app:configure';
+
+ protected function configure(): void
+ {
+ $this->setDescription('generate startup file');
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output): int
+ {
+ $x = collect();
+ $io = new SymfonyStyle($input, $output);
+
+ $x->push(copy('.env.example', '.env'));
+ $x->push(
+ (new File(base('config', 'mode.yaml'), EMPTY_AND_WRITE_FILE_MODE))
+ ->write("mode: up\nconnexion: dev")->flush()
+ );
+
+
+
+
+ if ($x->ok()) {
+ $io->success('the app is ready to use');
+ return 0;
+ }
+
+ $io->error('Configguration problem has been found');
+
+ return 1;
+ }
+}
diff --git a/app/Controllers/Admin/AdminController.php b/app/Controllers/Admin/AdminController.php
deleted file mode 100644
index 53688fe..0000000
--- a/app/Controllers/Admin/AdminController.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-namespace App\Controllers\Admin {
-
- use Eywa\Http\Controller\Crud;
- use Eywa\Http\Request\Request;
- use Eywa\Http\Response\Response;
-
- class AdminController extends Crud
- {
- protected static string $layout = 'admin';
-
- protected static string $directory = 'Admin';
-
- /**
- * @inheritDoc
- */
- public function before_action(Request $request): void
- {
- // TODO: Implement before_action() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_action(Request $request): void
- {
- // TODO: Implement after_action() method.
- }
-
- /**
- * @inheritDoc
- */
- public function destroy(Request $request): Response
- {
- // TODO: Implement destroy() method.
- }
-
- /**
- * @inheritDoc
- */
- public function update(Request $request): Response
- {
- // TODO: Implement update() method.
- }
-
- /**
- * @inheritDoc
- */
- public function create(Request $request): Response
- {
- // TODO: Implement create() method.
- }
-
- /**
- * @inheritDoc
- */
- public function show(Request $request): Response
- {
- // TODO: Implement show() method.
- }
- }
-}
diff --git a/app/Controllers/Auth/AuthController.php b/app/Controllers/Auth/AuthController.php
index f28ab14..70a6a8a 100644
--- a/app/Controllers/Auth/AuthController.php
+++ b/app/Controllers/Auth/AuthController.php
@@ -3,8 +3,11 @@
namespace App\Controllers\Auth {
use App\Forms\Auth\LoginForm;
+ use App\Models\Auth\Authentication;
+ use Eywa\Exception\Kedavra;
use Eywa\Http\Controller\Controller;
use Eywa\Http\Request\Request;
+ use Eywa\Http\Response\Response;
class AuthController extends Controller
{
@@ -15,7 +18,7 @@ namespace App\Controllers\Auth {
/**
* @inheritDoc
*/
- public function before_action(Request $request): void
+ public function before(Request $request): void
{
// TODO: Implement before_action() method.
}
@@ -23,24 +26,46 @@ namespace App\Controllers\Auth {
/**
* @inheritDoc
*/
- public function after_action(Request $request): void
+ public function after(Request $request): void
{
// TODO: Implement after_action() method.
}
+ /**
+ * @param Request $request
+ * @return Response
+ * @throws Kedavra
+ */
public function logout(Request $request)
{
- return $this->auth()->logout();
+ return $this->auth(Authentication::class)->logout();
}
- public function show_home(Request $request)
+
+ /**
+ * @param Request $request
+ * @return Response
+ * @throws Kedavra
+ */
+ public function showHome(Request $request)
{
return $this->view('home', 'Welcome', 'wecome');
}
- public function show_login_form(Request $request)
+
+ /**
+ * @param Request $request
+ * @return Response
+ * @throws Kedavra
+ */
+ public function showLoginForm(Request $request)
{
$form = $this->form(LoginForm::class);
return $this->view('login', 'Login', 'Connexion for members', compact('form'));
}
+
+ /**
+ * @param Request $request
+ * @return Response
+ */
public function login(Request $request)
{
return $this->check(LoginForm::class, $request);
diff --git a/app/Controllers/Demo/Demo.php b/app/Controllers/Demo/Demo.php
index 5e47ed8..5f283b1 100644
--- a/app/Controllers/Demo/Demo.php
+++ b/app/Controllers/Demo/Demo.php
@@ -10,5 +10,21 @@ namespace App\Controllers\Demo {
protected static string $layout = 'layout';
protected static string $directory = 'Demo';
+
+ /**
+ * @inheritDoc
+ */
+ public function before(Request $request): void
+ {
+ // TODO: Implement before() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after(Request $request): void
+ {
+ // TODO: Implement after() method.
+ }
}
}
diff --git a/app/Controllers/Email/WriteController.php b/app/Controllers/Email/WriteController.php
index 1923160..0598f92 100755
--- a/app/Controllers/Email/WriteController.php
+++ b/app/Controllers/Email/WriteController.php
@@ -10,118 +10,22 @@ namespace App\Controllers\Email {
protected static string $layout = 'layout';
protected static string $directory = 'Email';
-
-
- /**
- * @inheritDoc
- */
- public function before_validation(Request $request)
- {
- // TODO: Implement before_validation() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_validation(Request $request)
- {
- // TODO: Implement after_validation() method.
- }
-
- /**
- * @inheritDoc
- */
- public function before_save(Request $request)
- {
- // TODO: Implement before_save() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_save(Request $request)
- {
- // TODO: Implement after_save() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_commit(Request $request)
- {
- // TODO: Implement after_commit() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_rollback(Request $request)
- {
- // TODO: Implement after_rollback() method.
- }
- /**
- * @inheritDoc
- */
- public function before_update(Request $request)
- {
- // TODO: Implement before_update() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_update(Request $request)
- {
- // TODO: Implement after_update() method.
- }
-
- /**
- * @inheritDoc
- */
- public function before_action(Request $request):void
- {
- // TODO: Implement before_action() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_action(Request $request):void
- {
- // TODO: Implement after_action() method.
- }
-
- /**
- * @inheritDoc
- */
- public function before_create(Request $request)
- {
- // TODO: Implement before_create() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_create(Request $request)
- {
- // TODO: Implement after_create() method.
- }
/**
* @inheritDoc
*/
- public function before_destroy(Request $request)
+ public function before(Request $request): void
{
- // TODO: Implement before_destroy() method.
+ // TODO: Implement before() method.
}
/**
* @inheritDoc
*/
- public function after_destroy(Request $request)
+ public function after(Request $request): void
{
- // TODO: Implement after_destroy() method.
+ // TODO: Implement after() method.
}
}
}
diff --git a/app/Controllers/Home/HomeController.php b/app/Controllers/Home/HomeController.php
index f5dffab..38a016f 100644
--- a/app/Controllers/Home/HomeController.php
+++ b/app/Controllers/Home/HomeController.php
@@ -2,8 +2,7 @@
namespace App\Controllers\Home {
- use App\Forms\Auth\LoginForm;
- use App\Models\User;
+ use App\Models\Users\Users;
use Eywa\Exception\Kedavra;
use Eywa\Http\Controller\Controller;
use Eywa\Http\Request\Request;
@@ -18,22 +17,23 @@ namespace App\Controllers\Home {
/**
* @inheritDoc
*/
- public function before_action(Request $request): void
+ public function before(Request $request): void
{
}
/**
* @inheritDoc
*/
- public function after_action(Request $request): void
+ public function after(Request $request): void
{
}
- public function not_found()
+ public function notFound()
{
return $this->view('404', 'not found', 'error');
}
+
/**
*
* @param Request $request
@@ -45,14 +45,14 @@ namespace App\Controllers\Home {
*/
public function home(Request $request): Response
{
- $users = User::all();
+ $users = Users::all();
return $this->view('home', 'A library to make mvc website', 'The core of shaolin', compact('users'));
}
public function hello(Request $request): Response
{
- return $this->view('hello', 'say hello', 'hello', ['name'=> $request->args()->get('name', 'jean')]);
+ return $this->view('hello', 'say hello', 'hello', ['name' => $request->args()->get('name', 'jean')]);
}
}
}
diff --git a/app/Forms/Auth/LoginForm.php b/app/Forms/Auth/LoginForm.php
index 1780fba..b66529d 100644
--- a/app/Forms/Auth/LoginForm.php
+++ b/app/Forms/Auth/LoginForm.php
@@ -1,8 +1,8 @@
<?php
-
namespace App\Forms\Auth;
+use App\Models\Auth\Authentication;
use Eywa\Html\Form\Form;
use Eywa\Http\Request\Request;
use Eywa\Http\Response\Response;
@@ -34,7 +34,10 @@ class LoginForm extends Form
*/
public function make(): string
{
- return $this->start()->add('username', 'text', 'username')->add('password', 'password', 'password')->get('Login');
+ return $this->start()
+ ->add('username', 'text', 'username')
+ ->add('password', 'password', 'password')
+ ->get('Login');
}
@@ -43,7 +46,11 @@ class LoginForm extends Form
*/
public function success(Request $request): Response
{
- return (new Auth(new Session()))->login($request->request()->get('username'), $request->request()->get('password'));
+ return (new Auth(new Session(), Authentication::class))
+ ->login(
+ $request->request()->get('username'),
+ $request->request()->get('password')
+ );
}
/**
diff --git a/app/Forms/UsersForm.php b/app/Forms/UsersForm.php
index 4fc3c1e..2728157 100644
--- a/app/Forms/UsersForm.php
+++ b/app/Forms/UsersForm.php
@@ -1,6 +1,5 @@
<?php
-
namespace App\Forms;
use Eywa\Html\Form\Form;
@@ -35,7 +34,10 @@ class UsersForm extends Form
*/
public function make(): string
{
- return $this->start()->add('username', 'text', 'your username', 'must be uniq', ['autofocus'=> 'autofocus'])->add('bio', 'textarea', 'your bio')->get();
+ return $this->start()
+ ->add('username', 'text', 'your username', 'must be uniq', ['autofocus' => 'autofocus'])
+ ->add('bio', 'textarea', 'your bio')
+ ->get();
}
diff --git a/app/Forms/Write/ContactForm.php b/app/Forms/Write/ContactForm.php
index 479537c..2ab4412 100644
--- a/app/Forms/Write/ContactForm.php
+++ b/app/Forms/Write/ContactForm.php
@@ -1,6 +1,5 @@
<?php
-
namespace App\Forms\Write;
use Eywa\Html\Form\Form;
diff --git a/app/Middleware/IpMiddleware.php b/app/Middleware/Security/Ip.php
index 3b96079..a07ffd5 100755..100644
--- a/app/Middleware/IpMiddleware.php
+++ b/app/Middleware/Security/Ip.php
@@ -1,12 +1,11 @@
<?php
-
-namespace App\Middleware {
+namespace App\Middleware\Security {
use Eywa\Http\Middleware\Middleware;
use Eywa\Http\Request\ServerRequest;
- class IpMiddleware extends Middleware
+ class Ip extends Middleware
{
/**
@@ -14,6 +13,7 @@ namespace App\Middleware {
*/
public function check(ServerRequest $request): void
{
+ // TODO: Implement check() method.
}
}
}
diff --git a/app/Models/User.php b/app/Models/Auth/Authentication.php
index ef70987..1c8b0bf 100644
--- a/app/Models/User.php
+++ b/app/Models/Auth/Authentication.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Models
+namespace App\Models\Auth
{
use Eywa\Database\Model\Model;
- class User extends Model
+ class Authentication extends Model
{
protected static string $table = 'auth';
diff --git a/app/Models/Users/Users.php b/app/Models/Users/Users.php
new file mode 100644
index 0000000..500e30c
--- /dev/null
+++ b/app/Models/Users/Users.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Models\Users
+{
+
+ use Eywa\Database\Model\Model;
+
+ class Users extends Model
+ {
+ protected static string $table = 'users';
+
+ protected static int $limit = 20;
+ }
+
+}
diff --git a/app/Views/Home/404.php b/app/Views/Auth/home.html
index e69de29..e69de29 100644
--- a/app/Views/Home/404.php
+++ b/app/Views/Auth/home.html
diff --git a/app/Views/Auth/home.php b/app/Views/Auth/home.php
deleted file mode 100644
index 487bf48..0000000
--- a/app/Views/Auth/home.php
+++ /dev/null
@@ -1,5 +0,0 @@
-<ul>
- <li>@link(logout:logout:link)</li>
-</ul>
-
-@history \ No newline at end of file
diff --git a/app/Views/Auth/login.html b/app/Views/Auth/login.html
new file mode 100644
index 0000000..2de9df1
--- /dev/null
+++ b/app/Views/Auth/login.html
@@ -0,0 +1 @@
+@print($form) \ No newline at end of file
diff --git a/app/Views/Auth/login.php b/app/Views/Auth/login.php
deleted file mode 100644
index e428078..0000000
--- a/app/Views/Auth/login.php
+++ /dev/null
@@ -1,3 +0,0 @@
-@print($form)
-
-@history \ No newline at end of file
diff --git a/app/Views/Home/404.html b/app/Views/Home/404.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/Views/Home/404.html
diff --git a/app/Views/Home/hello.php b/app/Views/Home/hello.html
index 866dfb0..866dfb0 100644
--- a/app/Views/Home/hello.php
+++ b/app/Views/Home/hello.html
diff --git a/app/Views/Home/home.html b/app/Views/Home/home.html
new file mode 100644
index 0000000..21c639c
--- /dev/null
+++ b/app/Views/Home/home.html
@@ -0,0 +1,3 @@
+@foreach($users as $user)
+ <p>{{ $user->id }}</p>
+@endforeach \ No newline at end of file
diff --git a/app/Views/Home/home.php b/app/Views/Home/home.php
deleted file mode 100755
index 9477100..0000000
--- a/app/Views/Home/home.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<h1>welcome</h1>
-
-<ul>
- <li>@link(login:connexion:link)</li>
-</ul>
-
-@ago(2020-02-17)
-@foreach($users as $user)
- @continue($user->id == 1)
- @if($user->id == 3)
- @continue
- @else
- <li>{{ $user->id }}</li>
- @endif
-
-@endforeach
-
-@history \ No newline at end of file
diff --git a/app/Views/layout.php b/app/Views/layout.php
index c261d7f..b890782 100644
--- a/app/Views/layout.php
+++ b/app/Views/layout.php
@@ -15,6 +15,5 @@
@flash
<?= $content ?? ''?>
</main>
- @js(app)
</body>
</html> \ No newline at end of file
diff --git a/app/Views/maintenance.php b/app/Views/maintenance.php
index 9dfb1ee..6209300 100755..100644
--- a/app/Views/maintenance.php
+++ b/app/Views/maintenance.php
@@ -1 +1,17 @@
-site in maintenance \ No newline at end of file
+<!DOCTYPE html>
+<html lang="<?= $lang ?? 'en' ?>">
+<head>
+ <title><?= $title ?? '' ?></title>
+
+ <meta name="description" content="<?= $description ?? '' ?>">
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel='shortcut icon' href='/favicon.ico'/>
+ @css(app)
+</head>
+<body>
+<main class="container">
+ <?= $content ?? ''?>
+</main>
+</body>
+</html> \ No newline at end of file
diff --git a/composer.json b/composer.json
index b99d9ce..91d619e 100755
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,6 @@
"scrivo/highlight.php": "^9.17",
"fzaninotto/faker": "^1.9",
"nesbot/carbon": "^2.27",
- "codedungeon/phpunit-result-printer": "^0.26.2",
"symfony/process": "^5.0",
"sinergi/browser-detector": "^6.1",
"mobiledetect/mobiledetectlib": "^2.8",
@@ -31,7 +30,7 @@
"ext-mbstring": "*",
"ext-session": "*",
"ext-memcache": "*",
- "php-parallel-lint/php-parallel-lint": "^1.1"
+ "maximebf/debugbar": "^1.16"
},
"authors": [
{
@@ -57,20 +56,17 @@
"helpers/admin.php"
]
},
- "scripts": {
- "test": "phpunit --coverage-html coverage",
- "coverage" : "php -S localhost:8000 -t coverage",
- "serve" : "php -S localhost:3000 -t web",
- "send" : "git push origin --all && git push origin --tags && cd coverage && git add . && git commit -m 'send' && git push origin --all"
- },
"require-dev": {
"symfony/var-dumper": "^5.0",
- "phpunit/phpunit": "^8.5",
+ "phpunit/phpunit": "9.0",
"phpro/grumphp": "^0.18.0",
"phpstan/phpstan": "^0.12.14",
"maglnet/composer-require-checker": "^2.1",
"infection/infection": "^0.15.3",
"sensiolabs/security-checker": "^6.0",
- "friendsofphp/php-cs-fixer": "^2.16"
+ "codedungeon/phpunit-result-printer": "^0.27.0",
+ "friendsofphp/php-cs-fixer": "^2.16",
+ "squizlabs/php_codesniffer": "^3.5",
+ "php-parallel-lint/php-parallel-lint": "^1.1"
}
}
diff --git a/db/Migrations/AddPhoneToUsers.php b/db/Migrations/AddPhoneToUsers.php
index b215139..5628f29 100755
--- a/db/Migrations/AddPhoneToUsers.php
+++ b/db/Migrations/AddPhoneToUsers.php
@@ -1,6 +1,5 @@
<?php
-
namespace Evolution\Migrations {
diff --git a/db/Migrations/CreateAuthTable.php b/db/Migrations/CreateAuthTable.php
index 8aa7e5d..8125f99 100755
--- a/db/Migrations/CreateAuthTable.php
+++ b/db/Migrations/CreateAuthTable.php
@@ -1,6 +1,5 @@
<?php
-
namespace Evolution\Migrations {
@@ -26,7 +25,12 @@ namespace Evolution\Migrations {
public function up(): bool
{
- return $this->add('id', 'primary')->add('username', 'varchar', 255, ['UNIQUE','NOT NULL'])->add('email', 'varchar', 255, ['UNIQUE','NOT NULL'])->add('password', 'varchar', 255, ['NOT NULL'])->create();
+ return $this
+ ->add('id', 'primary')
+ ->add('username', 'varchar', 255, ['UNIQUE','NOT NULL'])
+ ->add('email', 'varchar', 255, ['UNIQUE','NOT NULL'])
+ ->add('password', 'varchar', 255, ['NOT NULL'])
+ ->create();
}
public function down(): bool
diff --git a/db/Migrations/CreateUsersTable.php b/db/Migrations/CreateUsersTable.php
index fd31033..5f870b5 100755
--- a/db/Migrations/CreateUsersTable.php
+++ b/db/Migrations/CreateUsersTable.php
@@ -1,6 +1,5 @@
<?php
-
namespace Evolution\Migrations {
diff --git a/db/Seeds/AuthSeeder.php b/db/Seeds/AuthSeeder.php
index bee6fc5..f612e91 100755
--- a/db/Seeds/AuthSeeder.php
+++ b/db/Seeds/AuthSeeder.php
@@ -1,6 +1,5 @@
<?php
-
namespace Evolution\Seeds {
use Eywa\Database\Seed\Seeder;
@@ -28,17 +27,16 @@ namespace Evolution\Seeds {
switch ($column) {
case 'username':
$seeder->set($column, $generator->name());
- break;
+ break;
case 'email':
$seeder->set($column, $generator->email);
- break;
+ break;
case 'password':
$seeder->set($column, secure_password('00000000'));
- break;
+ break;
default:
$seeder->primary($column);
- break;
-
+ break;
}
}
}
diff --git a/db/Seeds/UserSeeder.php b/db/Seeds/UserSeeder.php
index bce3154..e1c4563 100755
--- a/db/Seeds/UserSeeder.php
+++ b/db/Seeds/UserSeeder.php
@@ -1,6 +1,5 @@
<?php
-
namespace Evolution\Seeds {
@@ -29,17 +28,16 @@ namespace Evolution\Seeds {
switch ($column) {
case 'username':
$seeder->set($column, $generator->name());
- break;
+ break;
case 'email':
$seeder->set($column, $generator->email);
- break;
+ break;
case 'phone':
$seeder->set($column, $generator->phoneNumber);
- break;
+ break;
default:
- $seeder->primary($column);
- break;
-
+ $seeder->primary($column);
+ break;
}
}
}
diff --git a/eywa/Application/App.php b/eywa/Application/App.php
index 82a30bb..206096c 100755
--- a/eywa/Application/App.php
+++ b/eywa/Application/App.php
@@ -109,7 +109,10 @@ namespace Eywa\Application {
*/
public function view(string $view, string $title, string $description, array $args = []): Response
{
- return (new Response((new View($view, $title, $description, $args, static::$layout, static::$directory))->render()))->send();
+ return (
+ new Response(
+ (new View($view, $title, $description, $args, static::$layout, static::$directory))->render()
+ ))->send();
}
/**
@@ -170,7 +173,18 @@ namespace Eywa\Application {
}
if (equal($this->config('mode', 'mode'), 'down')) {
- return (new Response((new View('maintenance', HTTP_SERVICE_UNAVAILABLE_TEXT, 'Site in maintenance, we comming soon'))->render(), '', 503, ['Retry-After'=> 600]))->send();
+ return
+ (new Response(
+ (new View(
+ 'maintenance',
+ HTTP_SERVICE_UNAVAILABLE_TEXT,
+ 'We comming soon'
+ ))
+ ->render(),
+ '',
+ 503,
+ ['Retry-After' => 600]
+ ))->send();
}
return (new Router(ServerRequest::generate()))->run();
@@ -193,14 +207,18 @@ namespace Eywa\Application {
$success ? $this->flash(SUCCESS, $message) : $this->flash(FAILURE, $message);
}
- return not_cli() ? (new RedirectResponse($this->request()->server()->get('HTTP_REFERER')))->send() : (new RedirectResponse('/'))->send();
+ return not_cli()
+ ? (new RedirectResponse(
+ $this->request()->server()->get('HTTP_REFERER')
+ ))->send()
+ : (new RedirectResponse('/'))->send();
}
/**
* @inheritDoc
*
*/
- public function to(string $route, array $route_args= [], string $message = '', bool $success = true): Response
+ public function to(string $route, array $route_args = [], string $message = '', bool $success = true): Response
{
if (def($message)) {
$success ? $this->flash(SUCCESS, $message) : $this->flash(FAILURE, $message);
@@ -257,9 +275,9 @@ namespace Eywa\Application {
/**
* @inheritDoc
*/
- public function auth(): Auth
+ public function auth(string $model): Auth
{
- return new Auth(new Session());
+ return new Auth(new Session(), $model);
}
/**
@@ -364,7 +382,7 @@ namespace Eywa\Application {
*/
public function form(string $form): string
{
- return class_exists($form) && method_exists($form, 'make') ? (new $form)->make() : '';
+ return class_exists($form) && method_exists($form, 'make') ? (new $form())->make() : '';
}
/**
@@ -372,7 +390,8 @@ namespace Eywa\Application {
*/
public function check(string $form, Request $request): Response
{
- return class_exists($form) && method_exists($form, 'validate') ? (new $form)->validate($request)->call() : new Response('Form has not been found');
+ return class_exists($form) && method_exists($form, 'validate')
+ ? (new $form())->validate($request)->call() : new Response('Form has not been found');
}
}
}
diff --git a/eywa/Application/Environment/Env.php b/eywa/Application/Environment/Env.php
index 29b9525..9aad4f2 100755
--- a/eywa/Application/Environment/Env.php
+++ b/eywa/Application/Environment/Env.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Application\Environment {
@@ -31,7 +32,14 @@ namespace Eywa\Application\Environment {
$this->env = Dotenv::create($repository, base(), '.env');
$this->env->load();
- $this->env->required(['CACHE_TIME_DIVISER','CACHE_DIRECTORY','CACHE_TTL','DEBUG','DB_DRIVER','DB_HOST','DB_PORT','DB_NAME', 'DB_USERNAME', 'DB_PASSWORD','DEVELOP_DB_DRIVER','DEVELOP_DB_HOST','DEVELOP_DB_PORT','DEVELOP_DB_NAME', 'DEVELOP_DB_USERNAME', 'DEVELOP_DB_PASSWORD','APP_NAME','APP_KEY','CIPHER','TRANSLATOR_EMAIL']);
+ $this->env->required(
+ [ 'CACHE_TIME_DIVISER','CACHE_DIRECTORY','CACHE_TTL',
+ 'DEBUG','DB_DRIVER','DB_HOST','DB_NAME', 'DB_USERNAME',
+ 'DB_PASSWORD','DEVELOP_DB_DRIVER','DEVELOP_DB_HOST',
+ 'DEVELOP_DB_NAME', 'DEVELOP_DB_USERNAME', 'DEVELOP_DB_PASSWORD',
+ 'APP_NAME','APP_KEY','CIPHER','TRANSLATOR_EMAIL'
+ ]
+ );
}
/**
diff --git a/eywa/Application/Eywa.php b/eywa/Application/Eywa.php
index f1e5326..6015b89 100755
--- a/eywa/Application/Eywa.php
+++ b/eywa/Application/Eywa.php
@@ -101,7 +101,7 @@ namespace Eywa\Application {
* @throws Kedavra
*
*/
- public function response(string $content, int $status = 200, array $headers = [], string $url =''): Response;
+ public function response(string $content, int $status = 200, array $headers = [], string $url = ''): Response;
/**
*
@@ -194,10 +194,15 @@ namespace Eywa\Application {
*
* Get and instance of autentication
*
+ * @param string $model
+ *
* @return Auth
*
+ * @throws Kedavra
+ * @throws Exception
+ *
*/
- public function auth(): Auth;
+ public function auth(string $model): Auth;
/**
*
@@ -326,7 +331,7 @@ namespace Eywa\Application {
*
*
*/
- public function view(string $view, string $title, string $description, array $args =[]): Response;
+ public function view(string $view, string $title, string $description, array $args = []): Response;
/**
*
@@ -398,7 +403,7 @@ namespace Eywa\Application {
* @throws Kedavra
*
*/
- public function back(string $message ='', bool $success = true): Response;
+ public function back(string $message = '', bool $success = true): Response;
/**
*
@@ -412,7 +417,7 @@ namespace Eywa\Application {
* @return Response
* @throws Kedavra
*/
- public function to(string $route, array $route_args = [], string $message ='', bool $success = true): Response;
+ public function to(string $route, array $route_args = [], string $message = '', bool $success = true): Response;
/**
*
diff --git a/eywa/Application/Zen.php b/eywa/Application/Zen.php
index c755299..780aeff 100755
--- a/eywa/Application/Zen.php
+++ b/eywa/Application/Zen.php
@@ -7,848 +7,5 @@ namespace Eywa\Application {
class Zen
{
-
-
- /**
- *
- * To create a field with the tinyint type
- *
- * @var string
- *
- */
- const TINYINT = 'tinyint';
-
- /**
- *
- * To create a field with the smallint type
- *
- * @var string
- *
- */
- const SMALLINT = 'smallint';
-
- /**
- *
- * To create a field with the mediumint type
- *
- * @var string
- *
- */
- const MEDIUMINT = 'mediumint';
-
- /**
- *
- * To create a field with the int type
- *
- * @var string
- *
- */
- const INT = 'int';
-
- /**
- *
- * To create a field with the real type
- *
- * @var string
- *
- */
- const REAL = 'real';
-
- /**
- * To create a field with the serial type
- *
- * @var string
- */
- const SERIAL = 'serial';
-
- /**
- *
- * To create a field with the big serial type
- *
- * @var string
- *
- */
- const BIG_SERIAL = 'big serial';
-
- /**
- *
- * To create a field with the bit varying type
- *
- * @var string
- *
- */
- const BIT_VARYING = 'bit varying';
-
- /**
- *
- * To create a field with the boolean type
- *
- * @var string
- *
- */
- const BOOLEAN = 'boolean';
-
- /**
- *
- * To create a field with the box type
- *
- * @var string
- *
- */
- const BOX = 'box';
-
- /**
- *
- * To create a field with the bitea type
- *
- * @var string
- *
- */
- const BITEA = 'bitea';
-
- /**
- *
- * To create a field with the character varying type
- *
- * @var string
- *
- */
- const CHARACTER_VARYING = 'character varying';
-
- /**
- *
- * To create a field with the character type
- *
- * @var string
- *
- */
- const CHARACTER = 'character';
-
- /**
- *
- * To create a field with the cidr type
- *
- * @var string
- *
- */
- const CIDR = 'cidr';
-
- /**
- *
- * To create a field with the circle type
- *
- * @var string
- *
- */
- const CIRCLE = 'circle';
-
- /**
- *
- * To create a field with the float8 type
- *
- * @var string
- *
- */
- const FLOAT8 = 'float8';
-
- /**
- *
- * To create a field with the inet type
- *
- * @var string
- *
- */
- const INET = 'inet';
-
- /**
- *
- * To create a field with the interval type
- *
- * @var string
- *
- */
- const INTERVAL = 'interval';
-
- /**
- *
- * To create a field with the line type
- *
- * @var string
- *
- */
- const LINE = 'line';
-
- /**
- *
- * To create a field with the lseg type
- *
- * @var string
- *
- */
- const LSEG = 'lseg';
-
- /**
- *
- * To create a field with the macaddr type
- *
- * @var string
- *
- */
- const MACADDR = 'macaddr';
-
- /**
- *
- * To create a field with the macaddr8 type
- *
- * @var string
- *
- */
- const MACADDR8 = 'macaddr8';
-
- /**
- *
- * To create a field with the money type
- *
- * @var string
- *
- */
- const MONEY = 'money';
-
- /**
- *
- * To create a field with the path type
- *
- * @var string
- *
- */
- const PATH = 'path';
-
- /**
- *
- * To create a field with the point type
- *
- * @var string
- *
- */
- const POINT = 'point';
-
- /**
- *
- * To create a field with the polygon type
- *
- * @var string
- *
- */
- const POLYGON = 'polygon';
-
- /**
- *
- * To create a field with the time type
- *
- * @var string
- *
- */
- const TIME = 'time';
-
- /**
- *
- * To create a field with the tsquery type
- *
- * @var string
- *
- */
- const TSQUERY = 'tsquery';
-
- /**
- *
- * To create a field with the tsvector type
- *
- * @var string
- *
- */
- const TSVECTOR = 'tsvector';
-
- /**
- *
- * To create a field with the uuid type
- *
- * @var string
- *
- */
- const UUID = 'uuid';
-
- /**
- *
- * To create a field with the xml type
- *
- * @var string
- *
- */
- const XML = 'xml';
-
- /**
- *
- * To create a field with the integer type
- *
- * @var string
- *
- */
- const INTEGER = 'integer';
-
- /**
- *
- * To create a field with the bigint type
- *
- * @var string
- *
- */
- const BIGINT = 'bigint';
-
- /**
- *
- * To create a field with the numeric type
- *
- * @var string
- *
- */
- const NUMERIC = 'numeric';
-
- /**
- *
- * To create a field with the decimal type
- *
- * @var string
- *
- */
- const DECIMAL = 'decimal';
-
- /**
- *
- * To create a field with the bit type
- *
- * @var string
- *
- */
- const BIT = 'bit';
-
- /**
- *
- * To create a field with the date type
- *
- * @var string
- *
- */
- const DATE = 'date';
-
- /**
- *
- * To create a field with the datetime type
- *
- * @var string
- */
- const DATETIME = 'datetime';
-
- /**
- *
- * To create a field with the timestamp type
- *
- * @var string
- *
- */
- const TIMESTAMP = 'timestamp';
-
- /**
- *
- * To create a field with the char type
- *
- * @var string
- *
- */
- const CHAR = 'char';
-
- /**
- *
- * To create a field with the varchar type
- *
- * @var string
- *
- */
- const VARCHAR = 'varchar';
-
- /**
- *
- * To create a field with the enum type
- *
- * @var string
- *
- */
- const ENUM = 'enum';
-
- /**
- *
- * To create a field with the text type
- *
- * @var string
- *
- */
- const TEXT = 'text';
-
- /**
- *
- * To create a field with the longtext type
- *
- * @var string
- *
- */
- const LONGTEXT = 'longtext';
-
- /**
- *
- * To create a field with the blob type
- *
- * @var string
- *
- */
- const BLOB = 'blob';
-
- /**
- *
- * To create a field with the varbinary type
- *
- * @var string
- *
- */
- const VARBINARY = 'varbinary';
-
- /**
- *
- * To create a field with the mediumblob type
- *
- * @var string
- *
- */
- const MEDIUMBLOB = 'mediumblob';
-
- /**
- *
- * To create a field with the mediumtext type
- *
- * @var string
- *
- */
- const MEDIUMTEXT = 'mediumtext';
-
- /**
- *
- * To create a field with the longblob type
- *
- * @var string
- *
- */
- const LONGBLOB = 'longblob';
-
- /**
- *
- * To create a field with the null type
- *
- * @var string
- *
- */
- const NULL = 'NULL';
-
- /**
- *
- * To create a field with the not null type
- *
- * @var string
- *
- */
- const NOT_NULL = 'NOT NULL';
-
- /**
- *
- * To create a field with the none type
- *
- * @var string
- *
- */
- const NONE = 'none';
-
- /**
- *
- * To create a field with the number type
- *
- * @var string
- *
- */
- const NUMBER = 'number';
-
- /**
- *
- * To create a field with the varchar2 type
- *
- * @var string
- */
- const VARCHAR2 = 'varchar2';
-
- /**
- *
- * To create a field with the year type
- *
- * @var string
- */
- const YEAR = 'year';
-
- /**
- *
- * To create a field with the time type
- *
- * @var string
- *
- */
- const TIMESTAMP_WITH_TIME_ZONE = 'timestamp with time zone';
-
- /**
- *
- * To create a field with the time type
- *
- * @var string
- *
- */
- const TIMESTAMP_WITHOUT_TIME_ZONE = 'timestamp without time zone';
-
- /**
- *
- * To create a field with the time type
- *
- * @var string
- *
- */
- const TIME_WITH_TIME_ZONE = 'time with time zone';
-
- /**
- *
- * To create a field with the time type
- *
- * @var string
- *
- */
- const TIME_WITHOUT_TIME_ZONE = 'time without time zone';
-
- /**
- *
- * To create a field with the double presition type
- *
- * @var string
- *
- */
- const DOUBLE_PRECISION = 'double precision';
-
- /**
- *
- * To create a field with the double type
- *
- * @var string
- *
- */
- const DOUBLE = 'double';
-
- /**
- *
- * To create a field with the smallserial type
- *
- * @var string
- *
- */
- const SMALL_SERIAL = 'smallserial';
-
- /**
- *
- * To create a field with the int2 type
- *
- * @var string
- *
- */
- const INT2 = 'int2';
-
- /**
- *
- * To create a field with the int4 type
- *
- * @var string
- *
- */
- const INT4 = 'int4';
-
- /**
- *
- * To create a fied with the int4range type
- *
- * @var string
- *
- */
- const INT4_RANGE = 'int4range';
-
- /**
- *
- * To create a fied with the int8range type
- *
- * @var string
- *
- */
- const INT8_RANGE = 'int8range';
-
- /**
- *
- * To create a fied with the numrange type
- *
- * @var string
- *
- */
- const NUMRANGE = 'numrange';
-
- /**
- *
- * To create a fied with the tsrange type
- *
- * @var string
- *
- */
- const TSRANGE = 'tsrange';
-
- /**
- *
- * To create a fied with the tstzrange type
- *
- * @var string
- *
- */
- const TSTZRANGE = 'tstzrange';
-
- /**
- *
- * To create a fied with the int4range type
- *
- * @var string
- *
- */
- const DATE_RANGE = 'daterange';
-
- /**
- *
- * To create a field with the int8 type
- *
- * @var string
- */
- const INT8 = 'int8';
-
- /**
- *
- * To create a field with the float type
- *
- * @var string
- *
- */
- const FLOAT = 'float';
-
- /**
- *
- * To create a field with the binary type
- *
- * @var string
- *
- */
- const BINARY = 'binary';
-
- /**
- *
- * To create a field with the tinytext type
- *
- * @var string
- *
- */
- const TINYTEXT = 'tinytext';
-
- /**
- *
- * To create a field with the set type
- *
- * @var string
- *
- */
- const SET = 'set';
-
- /**
- *
- * To create a field with the json type
- *
- * @var string
- *
- */
- const JSON = 'json';
-
- /**
- *
- * To create a field with the jsonb type
- *
- * @var string
- *
- */
- const JSONB = 'jsonb';
-
- /**
- *
- * To create a field with the geometry type
- *
- * @var string
- *
- */
- const GEOMETRY = 'geometry';
-
- /**
- *
- * To create a fiel with the linestring type
- *
- * @var string
- *
- */
- const LINESTRING = 'linestring';
-
- /**
- *
- * To create a field with the multipoint type
- *
- * @var string
- *
- */
- const MULTIPOINT = 'multipoint';
-
- /**
- *
- * To create a field with the multilinestring type
- *
- * @var string
- *
- */
- const MULTILINESTRING = 'multilinestring';
-
- /**
- *
- * To create a field with the multipolygon type
- *
- * @var string
- *
- */
- const MULTIPOLYGON = 'multipolygon';
-
- /**
- *
- * To create a field with the geometrycollection type
- *
- * @var string
- *
- */
- const GEOMETRYCOLLECTION = 'geometrycollection';
-
- /**
- *
- * All boolean type
- *
- * @var array
- *
- */
- const BOOL = [ self::BOOLEAN ];
-
- /**
- *
- * All json types
- *
- * @var array
- *
- */
- const JSONS = [ self::JSON ];
-
- /**
- *
- * ALl date types
- *
- * @var array
- *
- */
- const DATE_TYPES = [ self::DATE, self::DATETIME, self::INTERVAL, self::TIME, self::TIMESTAMP, self::YEAR, self::INTERVAL, self::TIMESTAMP_WITH_TIME_ZONE, self::TIMESTAMP_WITHOUT_TIME_ZONE, self::TIME_WITH_TIME_ZONE, self::TIME_WITHOUT_TIME_ZONE ];
-
- /**
- *
- * All spacial types
- *
- * @var array
- *
- */
- const SPACIAL_TYPES = [ self::GEOMETRY, self::POINT, self::LINESTRING, self::POLYGON, self::MULTIPOINT, self::MULTILINESTRING, self::MULTIPOLYGON, self::GEOMETRYCOLLECTION ];
-
- /**
- *
- * All number types
- *
- * @var array
- *
- */
- const NUMERIC_TYPES = [ self::INT, self::INTEGER, self::DECIMAL, self::DOUBLE_PRECISION, self::BIGINT, self::REAL, self::DOUBLE, self::NUMERIC, self::BIG_SERIAL, self::BIT, self::SERIAL, self::SMALL_SERIAL, self::BIG_SERIAL, self::INT2, self::INT4, self::INT8, self::FLOAT, self::TINYINT, self::SMALLINT, self::MEDIUMINT ];
-
- /**
- *
- * All text types
- *
- * @var array
- *
- */
- const TEXT_TYPES = [ self::VARCHAR, self::CHAR, self::BINARY, self::VARBINARY, self::CHARACTER_VARYING, self::CHARACTER, self::BLOB, self::MEDIUMBLOB, self::ENUM, self::SET, self::TEXT, self::MEDIUMTEXT, self::TINYTEXT, self::TEXT, self::MEDIUMTEXT, self::LONGTEXT ];
-
- const ALL_TYPES = [
- self::DATE, self::DATETIME, self::INTERVAL, self::TIME, self::TIMESTAMP, self::YEAR, self::INTERVAL, self::TIMESTAMP_WITH_TIME_ZONE, self::TIMESTAMP_WITHOUT_TIME_ZONE, self::TIME_WITH_TIME_ZONE, self::TIME_WITHOUT_TIME_ZONE, self::GEOMETRY, self::POINT, self::LINESTRING, self::POLYGON, self::MULTIPOINT, self::MULTILINESTRING, self::MULTIPOLYGON, self::GEOMETRYCOLLECTION, self::INT, self::INTEGER, self::DECIMAL, self::DOUBLE_PRECISION, self::BIGINT, self::REAL, self::DOUBLE, self::NUMERIC, self::BIG_SERIAL, self::BIT, self::SERIAL, self::SMALL_SERIAL, self::BIG_SERIAL, self::INT2, self::INT4, self::INT8, self::FLOAT, self::TINYINT, self::SMALLINT, self::MEDIUMINT, self::VARCHAR, self::CHAR, self::BINARY, self::VARBINARY, self::CHARACTER_VARYING, self::CHARACTER, self::BLOB, self::MEDIUMBLOB, self::ENUM, self::SET, self::TEXT, self::MEDIUMTEXT, self::TINYTEXT, self::TEXT, self::MEDIUMTEXT, self::LONGTEXT ];
-
- /**
- *
- * All floting point types
- *
- * @var array
- *
- */
- const FLOTING_POINT_TYPES = [ self::FLOAT, self::DOUBLE ];
-
- const MYSQL_TYPES = [
- // CHARACTER
- self::CHAR, self::VARCHAR, self::BINARY, self::VARBINARY, self::BLOB, self::TINYTEXT, self::MEDIUMTEXT, self::TEXT, self::LONGTEXT, self::ENUM, self::SET, // INTEGER TYPES
- self::INTEGER, self::INT, self::SMALLINT, self::TINYINT, self::MEDIUMINT, self::BIGINT, self::REAL, self::DOUBLE, self::DOUBLE_PRECISION, // FIXED POINT TYPE
- self::DECIMAL, self::NUMERIC, // FLOTING POINT TYPES
- self::FLOAT, self::DOUBLE, // DATE AND TIME TYPES
- self::DATE, self::TIME, self::DATETIME, self::TIMESTAMP, self::YEAR, // JSON TYPES
- self::JSON, // BIT TYPE
- self::BIT, // BOLLEAN TYPES
- self::BOOLEAN, // SPACIAL DATA TYPES
- self::POINT, self::MULTIPOINT, self::LINESTRING, self::MULTILINESTRING, self::GEOMETRY, self::POLYGON, self::MULTIPOLYGON, self::GEOMETRYCOLLECTION ];
-
- /**
- *
- * All postgresql types
- *
- * @var array
- *
- */
- const POSTGRESQL_TYPES = [
- // CHARACTER
- self::CHAR, self::VARCHAR, self::CHARACTER_VARYING, self::TEXT, self::CHARACTER, // INTEGER TYPES
- self::SMALLINT, self::INTEGER, self::BIGINT, self::DECIMAL, self::NUMERIC, self::REAL, self::DOUBLE_PRECISION, self::SMALL_SERIAL, self::SERIAL, self::BIG_SERIAL, // FIXED POINT TYPE
- self::DECIMAL, self::NUMERIC, // FLOTING POINT TYPES
- self::FLOAT, self::DOUBLE, self::XML, self::MONEY, // RANGE TYPES
- self::INT4_RANGE, self::INT8_RANGE, self::NUMRANGE, self::TSRANGE, self::TSTZRANGE, self::DATE_RANGE, // DATE AND TIME TYPES
- self::TIMESTAMP, self::TIMESTAMP_WITHOUT_TIME_ZONE, self::TIMESTAMP_WITH_TIME_ZONE, self::DATE, self::TIME, self::TIME_WITHOUT_TIME_ZONE, self::TIME_WITH_TIME_ZONE, self::INTERVAL, // JSON TYPES
- self::JSON, self::JSONB, self::TSQUERY, self::TSVECTOR, // BIT TYPE
- self::BITEA, // BOLLEAN TYPES
- self::BOOLEAN, // NETWORKS TYPES
- self::CIDR, self::INET, self::MACADDR, self::MACADDR8, self::UUID, // SPACIAL DATA TYPES
- self::POINT, self::LINE, self::LSEG, self::BOX, self::PATH, self::POLYGON, self::CIRCLE, ];
-
- const SQLITE_TYPES = [ self::NULL, self::INTEGER, self::REAL, self::TEXT, self::BLOB, self::NUMERIC, self::NONE ];
}
}
diff --git a/eywa/Cache/FileCache.php b/eywa/Cache/FileCache.php
index 3493cb1..859b74a 100755
--- a/eywa/Cache/FileCache.php
+++ b/eywa/Cache/FileCache.php
@@ -64,7 +64,22 @@ namespace Eywa\Cache {
public function clear(): bool
{
$x = function () {
- return array_merge(files(base('cache', '*.php')), files(base('cache', '*', '*.php')));
+ return array_merge(
+ files(
+ base('cache', '*.html')
+ ),
+ files(
+ base('cache', '*', '*.html')
+ ),
+ array_merge(
+ files(
+ base('cache', '*.php')
+ ),
+ files(
+ base('cache', '*', '*.php')
+ )
+ )
+ );
};
foreach ($x() as $file) {
unlink($file);
diff --git a/eywa/Cache/MemcacheCache.php b/eywa/Cache/MemcacheCache.php
index 88334b7..90a467b 100755
--- a/eywa/Cache/MemcacheCache.php
+++ b/eywa/Cache/MemcacheCache.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Eywa\Cache {
- use \Memcache;
+ use Memcache;
class MemcacheCache implements CacheInterface
{
@@ -14,7 +14,7 @@ namespace Eywa\Cache {
*/
private Memcache $cache;
- public function __construct(string $host ='localhost', int $port = 11211, bool $persistent =true)
+ public function __construct(string $host = 'localhost', int $port = 11211, bool $persistent = true)
{
$this->cache = new Memcache();
$this->cache->addServer($host, $port, $persistent);
@@ -43,7 +43,7 @@ namespace Eywa\Cache {
*/
public function destroy(string $key): bool
{
- return $this->has($key) ? $this->cache->delete($key): false;
+ return $this->has($key) ? $this->cache->delete($key) : false;
}
/**
diff --git a/eywa/Cache/RedisCache.php b/eywa/Cache/RedisCache.php
index 09ac6d9..cdba02d 100755
--- a/eywa/Cache/RedisCache.php
+++ b/eywa/Cache/RedisCache.php
@@ -13,7 +13,7 @@ namespace Eywa\Cache {
*/
private Redis $redis;
- public function __construct(string $host = 'localhost', int $port =6379)
+ public function __construct(string $host = 'localhost', int $port = 6379)
{
$this->redis = new Redis();
$this->redis->connect($host, $port);
diff --git a/eywa/Collection/Collect.php b/eywa/Collection/Collect.php
index a001f08..c858de0 100755
--- a/eywa/Collection/Collect.php
+++ b/eywa/Collection/Collect.php
@@ -2,7 +2,6 @@
declare(strict_types=1);
-
namespace Eywa\Collection {
@@ -18,7 +17,7 @@ namespace Eywa\Collection {
* @var array<mixed>
*
*/
- private array $data = [];
+ private array $data ;
/**
*
@@ -85,7 +84,7 @@ namespace Eywa\Collection {
* @return int|mixed|string
*
*/
- public function first_key()
+ public function firstKey()
{
return array_key_first($this->data);
}
@@ -96,7 +95,7 @@ namespace Eywa\Collection {
* @return int|mixed|string
*
*/
- public function last_key()
+ public function lastKey()
{
return array_key_last($this->data);
}
@@ -260,7 +259,7 @@ namespace Eywa\Collection {
* @return mixed
*
*/
- public function value_before_key(string $key)
+ public function valueBeforeKey(string $key)
{
if ($this->has($key)) {
foreach ($this->data as $k => $v) {
@@ -377,7 +376,7 @@ namespace Eywa\Collection {
* @return bool
*
*/
- public function has_not($key): bool
+ public function hasNot($key): bool
{
return !$this->has($key);
}
@@ -823,7 +822,7 @@ namespace Eywa\Collection {
public function del(array $data): Collect
{
foreach ($data as $datum) {
- $this->exist($datum) ? $this->remove_value([$datum]) : $this->remove([$datum]);
+ $this->exist($datum) ? $this->removeValue([$datum]) : $this->remove([$datum]);
}
return $this->checkout($this->all());
@@ -852,7 +851,7 @@ namespace Eywa\Collection {
* @return string
*
*/
- public function join_keys(string $glue = ','): string
+ public function joinKeys(string $glue = ','): string
{
return implode($glue, $this->keys()->all());
}
@@ -866,7 +865,7 @@ namespace Eywa\Collection {
*/
public function ok(): bool
{
- return $this->not_exist(false);
+ return $this->notExist(false);
}
/**
@@ -906,7 +905,7 @@ namespace Eywa\Collection {
* @return bool
*
*/
- public function not_exist($value): bool
+ public function notExist($value): bool
{
return ! $this->exist($value);
}
@@ -1056,7 +1055,7 @@ namespace Eywa\Collection {
public function uniq(array $values): Collect
{
foreach ($values as $value) {
- if ($this->not_exist($value)) {
+ if ($this->notExist($value)) {
$this->push($value);
}
}
@@ -1108,7 +1107,7 @@ namespace Eywa\Collection {
* @return Collect
*
*/
- private function remove_value(array $values): Collect
+ private function removeValue(array $values): Collect
{
foreach ($values as $value) {
if (($key = array_search($value, $this->data)) !== false) {
diff --git a/eywa/Configuration/Config.php b/eywa/Configuration/Config.php
index 36f3345..8b091dd 100755
--- a/eywa/Configuration/Config.php
+++ b/eywa/Configuration/Config.php
@@ -30,14 +30,14 @@ namespace Eywa\Configuration {
* @var string
*
*/
- const EXT = '.yaml';
+ public const EXT = '.yaml';
/**
*
* The config.yaml filename
*
*/
- private string $filename;
+ private string $filename;
/**
*
@@ -63,11 +63,28 @@ namespace Eywa\Configuration {
{
$file = $this->path() . DIRECTORY_SEPARATOR . collect(explode('.', $file))->first() . self::EXT;
- is_false(file_exists($file), true, sprintf('The %s file has not been found in the %s directory', $file, $this->path()));
+ is_false(
+ file_exists($file),
+ true,
+ sprintf(
+ 'The %s file has not been found in the %s directory',
+ $file,
+ $this->path()
+ )
+ );
$this->values = collect(self::parseFile($file));
- is_false($this->values->has($key), true, sprintf('The %s key has not been found in the %s file in the %s directory', $key, $file, $this->path()));
+ is_false(
+ $this->values->has($key),
+ true,
+ sprintf(
+ 'The %s key has not been found in the %s file in the %s directory',
+ $key,
+ $file,
+ $this->path()
+ )
+ );
$this->filename = $file;
diff --git a/eywa/Console/App/AppSend.php b/eywa/Console/App/AppSend.php
index 6b15a6b..015ff8d 100755
--- a/eywa/Console/App/AppSend.php
+++ b/eywa/Console/App/AppSend.php
@@ -1,79 +1,79 @@
<?php
- namespace Eywa\Console\App
- {
- use Eywa\Console\Shell;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+namespace Eywa\Console\App
+{
+ use Eywa\Console\Shell;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class AppSend extends Command
- {
- protected static $defaultName = 'app:send';
+ class AppSend extends Command
+ {
+ protected static $defaultName = 'app:send';
- protected function configure():void
- {
- $this->setDescription('Send the application to the server');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Send the application to the server');
+ }
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- $io->success('Starting all tests');
- $x = new Shell(base('vendor', 'bin', 'grumphp') . ' run');
- if ($x->run()) {
- $io->success('Congratulations no errors has been found');
+ $io->success('Starting all tests');
+ $x = new Shell(base('vendor', 'bin', 'grumphp') . ' run');
+ if ($x->run()) {
+ $io->success('Congratulations no errors has been found');
- if (is_dir('.git')) {
- $io->success('Sending the application');
+ if (is_dir('.git')) {
+ $io->success('Sending the application');
- $remotes = [];
+ $remotes = [];
- exec('git remote -v', $remotes);
+ exec('git remote -v', $remotes);
- if (not_def($remotes)) {
- $io->error('No server remote has been found');
- return 1;
- }
- $all = collect();
+ if (not_def($remotes)) {
+ $io->error('No server remote has been found');
+ return 1;
+ }
+ $all = collect();
- foreach ($remotes as $remote) {
- $x = collect(explode("\t", $remote));
- $name = $x->first();
- $url = collect(explode(' ', $x->get(1)))->first();
+ foreach ($remotes as $remote) {
+ $x = collect(explode("\t", $remote));
+ $name = $x->first();
+ $url = collect(explode(' ', $x->get(1)))->first();
- $host = collect(explode(':', collect(explode('@', $url))->last()))->first();
+ $host = collect(explode(':', collect(explode('@', $url))->last()))->first();
- if ($all->has_not($name)) {
- $all->put($name, $host);
- }
+ if ($all->hasNot($name)) {
+ $all->put($name, $host);
}
+ }
- foreach ($all->all() as $name => $url) {
- $io->warning("Sending the application at the remote server called $name hosted at $url");
+ foreach ($all->all() as $name => $url) {
+ $io->warning(sprintf('Sending the application to %s', $url));
- if ((new Shell("git push $name --all && git push $name --tags"))->run()) {
- $io->success("The remote server called $name has been updated successfully");
- } else {
- $io->error("Please make sure you have the correct access rights and the repository exists");
- return 1;
- }
+ if ((new Shell(sprintf('git push %s --all && git push %s --tags', $name, $name)))->run()) {
+ $io->success(sprintf('The repository hosted at %s has been updated successfully', $url));
+ } else {
+ $io->error('Please make sure you have the correct access rights and the repository exists');
+ return 1;
}
-
- $io->warning('End of all remote servers found');
- $io->success('All remote servers has been updated successfully');
- return 0;
- } else {
- $io->error('We have not found git');
- return 1;
}
+
+ $io->warning('End of all remote servers found');
+ $io->success('All remote servers has been updated successfully');
+ return 0;
+ } else {
+ $io->error('We have not found git');
+ return 1;
}
- $io->error($x->get()->getOutput());
- return 1;
}
+ $io->error($x->get()->getOutput());
+ return 1;
}
}
+}
diff --git a/eywa/Console/App/Coverage.php b/eywa/Console/App/Coverage.php
index 5426792..7c683f0 100755
--- a/eywa/Console/App/Coverage.php
+++ b/eywa/Console/App/Coverage.php
@@ -1,37 +1,37 @@
<?php
- namespace Eywa\Console\App
- {
+namespace Eywa\Console\App
+{
- use Eywa\Console\Shell;
- use Eywa\Http\Server\Http;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Console\Shell;
+ use Eywa\Http\Server\Http;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class Coverage extends Command
- {
- protected static $defaultName = "app:coverage";
+ class Coverage extends Command
+ {
+ protected static $defaultName = "app:coverage";
- protected function configure():void
- {
- $this->setDescription('Run a server to show the code coverage');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Run a server to show the code coverage');
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return int|null
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- return (new Http($io, 'coverage', 8000))->run();
- }
+ return (new Http($io, 'coverage', 8000))->run();
}
}
+}
diff --git a/eywa/Console/App/Dkim.php b/eywa/Console/App/Dkim.php
index 7a101d1..935cfef 100755
--- a/eywa/Console/App/Dkim.php
+++ b/eywa/Console/App/Dkim.php
@@ -1,43 +1,47 @@
<?php
- namespace Eywa\Console\App
- {
+namespace Eywa\Console\App
+{
- use Eywa\Console\Shell;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Console\Shell;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class Dkim extends Command
- {
- protected static $defaultName = 'dkim:generate';
+ class Dkim extends Command
+ {
+ protected static $defaultName = 'dkim:generate';
- protected function configure():void
- {
- $this->setDescription('Generate dkim keys');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Generate dkim keys');
+ }
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
-
- $io->title('Generation of the dkim key');
-
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- if (file_exists('dkim.private.key')) {
- $io->error('The dkim keys already exist');
- return 1;
- }
+ $io->title('Generation of the dkim key');
- if ((new Shell('openssl genrsa -out dkim.private.key 1024'))->run() && (new Shell('openssl rsa -in dkim.private.key -out dkim.public.key -pubout -outform PEM'))->run()) {
- $io->success('The dkim keys will be used to sign all emails');
- return 0;
- }
- $io->error("Generation has failed");
+ if (file_exists('dkim.private.key')) {
+ $io->error('The dkim keys already exist');
return 1;
}
+
+ if (
+ (new Shell('openssl genrsa -out dkim.private.key 1024'))->run()
+ && (new Shell('openssl rsa -in dkim.private.key -out dkim.public.key -pubout -outform PEM'))
+ ->run()
+ ) {
+ $io->success('The dkim keys will be used to sign all emails');
+ return 0;
+ }
+
+ $io->error("Generation has failed");
+ return 1;
}
}
+}
diff --git a/eywa/Console/App/Key.php b/eywa/Console/App/Key.php
index 3de7859..5ed47d7 100755
--- a/eywa/Console/App/Key.php
+++ b/eywa/Console/App/Key.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\App;
use Eywa\Security\Crypt\Crypter;
@@ -13,7 +12,7 @@ class Key extends Command
{
protected static $defaultName = 'key:generate';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Generate app key');
}
diff --git a/eywa/Console/App/Serve.php b/eywa/Console/App/Serve.php
index a117b40..9041583 100755
--- a/eywa/Console/App/Serve.php
+++ b/eywa/Console/App/Serve.php
@@ -1,36 +1,36 @@
<?php
- namespace Eywa\Console\App
- {
+namespace Eywa\Console\App
+{
- use Eywa\Http\Server\Http;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Http\Server\Http;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class Serve extends Command
- {
- protected static $defaultName = "app:run";
+ class Serve extends Command
+ {
+ protected static $defaultName = "app:run";
- protected function configure():void
- {
- $this->setDescription('Run a development server');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Run a development server');
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return int|null
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- return (new Http($io))->run();
- }
+ return (new Http($io))->run();
}
}
+}
diff --git a/eywa/Console/App/TestCommand.php b/eywa/Console/App/TestCommand.php
index 8bb1190..1a49f5c 100755
--- a/eywa/Console/App/TestCommand.php
+++ b/eywa/Console/App/TestCommand.php
@@ -1,36 +1,36 @@
<?php
- namespace Eywa\Console\App
- {
- use Eywa\Console\Shell;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+namespace Eywa\Console\App
+{
+ use Eywa\Console\Shell;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class TestCommand extends Command
- {
- protected static $defaultName = 'app:test';
+ class TestCommand extends Command
+ {
+ protected static $defaultName = 'app:test';
- protected function configure():void
- {
- $this->setDescription('Test the application');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Test the application');
+ }
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
-
- $io->title('Executing grumphp please wait !');
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- $x = new Shell(base('vendor', 'bin', 'grumphp') . ' run');
- if ($x->run()) {
- $io->success('Congratulations no errors has been found');
- return 0;
- }
- $io->error($x->get()->getOutput());
+ $io->title('Executing grumphp please wait !');
- return 1;
+ $x = new Shell(base('vendor', 'bin', 'grumphp') . ' run');
+ if ($x->run()) {
+ $io->success('Congratulations no errors has been found');
+ return 0;
}
+ $io->error($x->get()->getOutput());
+
+ return 1;
}
}
+}
diff --git a/eywa/Console/Cache/ClearCache.php b/eywa/Console/Cache/ClearCache.php
index d0c7a6a..b8ca923 100755
--- a/eywa/Console/Cache/ClearCache.php
+++ b/eywa/Console/Cache/ClearCache.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Cache {
@@ -19,9 +18,10 @@ namespace Eywa\Console\Cache {
{
protected static $defaultName = 'cache:clear';
- protected function configure():void
+ protected function configure(): void
{
- $this->setDescription("Clean all cache systems")->addArgument('system', InputArgument::OPTIONAL, 'The cahe system name to clear');
+ $this->setDescription("Clean all cache systems")
+ ->addArgument('system', InputArgument::OPTIONAL, 'The cahe system name to clear');
}
/**
diff --git a/eywa/Console/Console.php b/eywa/Console/Console.php
index ae0875a..3498c88 100755
--- a/eywa/Console/Console.php
+++ b/eywa/Console/Console.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console {
@@ -26,19 +25,13 @@ namespace Eywa\Console {
use Eywa\Console\Database\UninstallDatabase;
use Eywa\Console\Generate\GenerateCommand;
use Eywa\Console\Generate\GenerateContainer;
- use Eywa\Console\Generate\GenerateController;
use Eywa\Console\Generate\GenerateForm;
use Eywa\Console\Generate\GenerateMiddleware;
- use Eywa\Console\Generate\GenerateMigration;
use Eywa\Console\Generate\GenerateModel;
- use Eywa\Console\Generate\GenerateSeeds;
- use Eywa\Console\Generate\GenerateTest;
use Eywa\Console\Generate\GenerateValidator;
use Eywa\Console\Generate\GenerateView;
use Eywa\Console\Get\Documentation;
use Eywa\Console\Get\Wanted;
- use Eywa\Console\Lang\CreateCatalogues;
- use Eywa\Console\Lang\UpdateCatalogues;
use Eywa\Console\Mode\DevMode;
use Eywa\Console\Mode\Maintenance;
use Eywa\Console\Mode\ProductionMode;
@@ -88,10 +81,15 @@ namespace Eywa\Console {
public function run(): int
{
$commands = [
- new CreateCatalogues(),new UpdateCatalogues(), new AddRoute(), new UpdateRoute(), new ListRoute(), new RemoveRoute(),new GenerateView(), new GenerateController(),new GenerateModel(),new GenerateMigration(),new GenerateSeeds(),new GenerateTest(),new GenerateMiddleware(),
- new ClearCache(), new Dkim(), new Serve(),new Key(),new SeedDatabase(),new Maintenance(), new ProductionMode(),new DevMode(),new MigrateDatabase(),new RollbackDatabase(),new Coverage(),new TruncateTable(),new ShowTable(),new DropTable(),new ImportDatabase(),new ExportDatabase(),new CleanDatabase(),
- new InstallDatabase(), new UninstallDatabase(),new ShowUsers(),new Documentation(),new Wanted(),new GenerateValidator(),new AppSend(),new TestCommand(),new GenerateCommand(),new FindRoute(),new Records\Records(),new GenerateContainer(),new GenerateForm()
- ];
+ new ClearCache(), new Dkim(), new Serve(),new Key(),new SeedDatabase(),new Maintenance(),
+ new ProductionMode(),new DevMode(),new MigrateDatabase(),new RollbackDatabase(),new Coverage(),
+ new TruncateTable(),new ShowTable(),new DropTable(),new ImportDatabase(),new ExportDatabase(),
+ new CleanDatabase(),new GenerateMiddleware(),new GenerateCommand(),new GenerateView(),
+ new InstallDatabase(), new UninstallDatabase(),new ShowUsers(),new Documentation(),new Wanted(),
+ new GenerateValidator(),new AppSend(),new TestCommand(),new GenerateCommand(),new FindRoute() ,
+ new ListRoute() , new AddRoute(), new RemoveRoute(), new UpdateRoute(),new Records\Records(),
+ new GenerateContainer(),new GenerateForm(),new GenerateModel()
+ ];
$this->add($commands)->add(commands());
diff --git a/eywa/Console/Database/CleanDatabase.php b/eywa/Console/Database/CleanDatabase.php
index 5d94cec..1897d72 100755
--- a/eywa/Console/Database/CleanDatabase.php
+++ b/eywa/Console/Database/CleanDatabase.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Database {
@@ -17,9 +16,10 @@ namespace Eywa\Console\Database {
{
protected static $defaultName = 'db:clean';
- protected function configure():void
+ protected function configure(): void
{
- $this->setDescription("Truncate all tables")->addArgument('env', InputArgument::REQUIRED, 'The base environment');
+ $this->setDescription("Truncate all tables")
+ ->addArgument('env', InputArgument::REQUIRED, 'The base environment');
}
/**
diff --git a/eywa/Console/Database/DropTable.php b/eywa/Console/Database/DropTable.php
index 74466c2..2752cb0 100755
--- a/eywa/Console/Database/DropTable.php
+++ b/eywa/Console/Database/DropTable.php
@@ -1,124 +1,131 @@
<?php
- namespace Eywa\Console\Database
+namespace Eywa\Console\Database
+{
+
+ use Eywa\Database\Table\Table;
+ use Eywa\Exception\Kedavra;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
+
+ class DropTable extends Command
{
+ protected static $defaultName = 'table:drop';
+
+ protected function configure(): void
+ {
+ $this->setDescription("Drop a table")
+ ->addArgument('table', InputArgument::REQUIRED, 'The table name')
+ ->addArgument('env', InputArgument::REQUIRED, 'The base environment');
+ }
- use Eywa\Database\Table\Table;
- use Eywa\Exception\Kedavra;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
-
- class DropTable extends Command
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
{
- protected static $defaultName = 'table:drop';
-
- protected function configure():void
- {
- $this->setDescription("Drop a table")->addArgument('table', InputArgument::REQUIRED, 'The table name')->addArgument('env', InputArgument::REQUIRED, 'The base environment');
+ $env = strval($input->getArgument('env'));
+
+ not_in(['dev','prod','any'], $env, true, "Only dev, prod or any must be used");
+
+ $io = new SymfonyStyle($input, $output);
+
+ $x = strval($input->getArgument('table'));
+
+ if (equal($env, 'dev')) {
+ $table = new Table(development(), $x);
+
+ if (not_def($table->show()->all())) {
+ $io->error('No tables has been found');
+ return 1;
+ }
+
+ if (is_false($table->exist())) {
+ $io->error(sprintf('The %s table not exist', $x));
+ return 1;
+ }
+ if ($table->drop()) {
+ $io->success(sprintf('The %s table has been removed successfully', $x));
+ return 0;
+ } else {
+ $io->error(sprintf('Failed to remove the %s table', $x));
+ return 1;
+ }
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws Kedavra
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $env = strval($input->getArgument('env'));
-
- not_in(['dev','prod','any'], $env, true, "Only dev, prod or any must be used");
-
- $io = new SymfonyStyle($input, $output);
-
- $x = strval($input->getArgument('table'));
-
- if (equal($env, 'dev')) {
- $table = new Table(development(), $x);
-
- if (not_def($table->show()->all())) {
- $io->error('No tables has been found');
- return 1;
- }
-
- if (is_false($table->exist())) {
- $io->error(sprintf('The %s table not exist', $x));
- return 1;
- }
- if ($table->drop()) {
- $io->success(sprintf('The %s table has been removed successfully', $x));
- return 0;
- } else {
- $io->error(sprintf('Failed to remove the %s table', $x));
- return 1;
- }
+ if (equal($env, 'prod')) {
+ $table = new Table(production(), $x);
+
+ if (not_def($table->show()->all())) {
+ $io->error('No tables has been found');
+ return 1;
}
- if (equal($env, 'prod')) {
- $table = new Table(production(), $x);
-
- if (not_def($table->show()->all())) {
- $io->error('No tables has been found');
- return 1;
- }
-
- if (is_false($table->exist())) {
- $io->error(sprintf('The %s table not exist', $x));
- return 1;
- }
- if ($table->drop()) {
- $io->success(sprintf('The %s table has been removed successfully', $x));
- return 0;
- } else {
- $io->error(sprintf('Failed to remove the %s table', $x));
- return 1;
- }
+ if (is_false($table->exist())) {
+ $io->error(sprintf('The %s table not exist', $x));
+ return 1;
+ }
+ if ($table->drop()) {
+ $io->success(sprintf('The %s table has been removed successfully', $x));
+ return 0;
+ } else {
+ $io->error(sprintf('Failed to remove the %s table', $x));
+ return 1;
}
+ }
+
+ if (equal($env, 'any')) {
+ $table = new Table(development(), $x);
- if (equal($env, 'any')) {
- $table = new Table(development(), $x);
-
- if (not_def($table->show()->all())) {
- $io->error('No tables has been found');
- return 1;
- }
-
- if (is_false($table->exist())) {
- $io->error(sprintf('The %s table not exist', $x));
- return 1;
- }
- if ($table->drop()) {
- $io->success(sprintf('The %s table has been removed successfully', $x));
- } else {
- $io->error(sprintf('Failed to remove the %s table', $x));
- return 1;
- }
-
- $table = new Table(production(), $x);
-
- if (not_def($table->show()->all())) {
- $io->error('No tables has been found');
- return 1;
- }
-
- if (is_false($table->exist())) {
- $io->error(sprintf('The %s table not exist', $x));
- return 1;
- }
- if ($table->drop()) {
- $io->success(sprintf('The %s table has been removed successfully', $x));
- } else {
- $io->error(sprintf('Failed to remove the %s table', $x));
- return 1;
- }
- $io->success(sprintf('The %s table has been deleted of the production and the development database', $x));
+ if (not_def($table->show()->all())) {
+ $io->error('No tables has been found');
+ return 1;
+ }
+
+ if (is_false($table->exist())) {
+ $io->error(sprintf('The %s table not exist', $x));
+ return 1;
+ }
+ if ($table->drop()) {
+ $io->success(sprintf('The %s table has been removed successfully', $x));
+ } else {
+ $io->error(sprintf('Failed to remove the %s table', $x));
+ return 1;
}
- $io->error("Environment is not valid");
- return 1;
+ $table = new Table(production(), $x);
+
+ if (not_def($table->show()->all())) {
+ $io->error('No tables has been found');
+ return 1;
+ }
+
+ if (is_false($table->exist())) {
+ $io->error(sprintf('The %s table not exist', $x));
+ return 1;
+ }
+ if ($table->drop()) {
+ $io->success(sprintf('The %s table has been removed successfully', $x));
+ } else {
+ $io->error(sprintf('Failed to remove the %s table', $x));
+ return 1;
+ }
+ $io->success(
+ sprintf(
+ 'The %s table has been deleted of the production and the development database',
+ $x
+ )
+ );
}
+
+ $io->error("Environment is not valid");
+ return 1;
}
}
+}
diff --git a/eywa/Console/Database/ExportDatabase.php b/eywa/Console/Database/ExportDatabase.php
index 1d7152d..8d6411f 100755
--- a/eywa/Console/Database/ExportDatabase.php
+++ b/eywa/Console/Database/ExportDatabase.php
@@ -19,10 +19,10 @@ namespace Eywa\Console\Database {
* @throws Kedavra
* @throws Exception
*/
- protected function configure():void
+ protected function configure(): void
{
$base = app()->connexion()->base();
- $this->setDescription("Export the $base base content into a sql file");
+ $this->setDescription(sprintf('Export the %s base content into a sql file', $base));
}
/**
@@ -36,11 +36,11 @@ namespace Eywa\Console\Database {
{
$io = new SymfonyStyle($input, $output);
if ((new Export(app()->connexion()))->dump()) {
- $io->success('The base was successfully saved');
+ $io->success(sprintf('The %s base has been exported successfully', app()->connexion()->base()));
return 0;
}
- $io->error('The export task has failed');
+ $io->error('Exportation has failed');
return 1;
}
}
diff --git a/eywa/Console/Database/Grant.php b/eywa/Console/Database/Grant.php
index 22079af..bed0209 100755
--- a/eywa/Console/Database/Grant.php
+++ b/eywa/Console/Database/Grant.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Database {
diff --git a/eywa/Console/Database/ImportDatabase.php b/eywa/Console/Database/ImportDatabase.php
index 1618e66..46313ee 100755
--- a/eywa/Console/Database/ImportDatabase.php
+++ b/eywa/Console/Database/ImportDatabase.php
@@ -19,10 +19,10 @@ namespace Eywa\Console\Database {
* @throws Kedavra
* @throws Exception
*/
- protected function configure():void
+ protected function configure(): void
{
$base = app()->connexion()->base();
- $this->setDescription("Import sql file content into the $base database");
+ $this->setDescription(sprintf('Import sql file content into the %s database', $base));
}
/**
@@ -37,13 +37,13 @@ namespace Eywa\Console\Database {
{
$io = new SymfonyStyle($input, $output);
if ((new Import(app()->connexion()))->import()) {
- $io->success('The import has successfully executed');
+ $io->success(sprintf('The %s base has been updated successfully', app()->connexion()->base()));
return 0;
}
- $file = app()->connexion()->base() .'.sql';
+ $file = app()->connexion()->base() . '.sql';
- $io->error("The $file file not exist or authentication problems");
+ $io->error(sprintf('The %s file not exist or authentication problems', $file));
return 1;
}
}
diff --git a/eywa/Console/Database/InstallDatabase.php b/eywa/Console/Database/InstallDatabase.php
index 7c24b81..27b530a 100755
--- a/eywa/Console/Database/InstallDatabase.php
+++ b/eywa/Console/Database/InstallDatabase.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Database {
use Exception;
@@ -40,13 +39,13 @@ namespace Eywa\Console\Database {
private string $routing_instance_created_successfully = 'The routing database has been created successfully';
- private string $routing_instance_creation_has_fail ='The creation of the routing database has failed please check if sqlite are running';
+ private string $routing_instance_creation_has_fail = 'The creation of the routing database has failed';
- private string $migration_tables_created_successfully ='All migrations tables has been created successfully';
+ private string $migration_tables_created_successfully = 'All migrations tables has been created successfully';
- private string $migration_tables_created_failed ='Creation of the migrations table has failed';
+ private string $migration_tables_created_failed = 'Creation of the migrations table has failed';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Create all databases and users rights');
}
@@ -61,15 +60,15 @@ namespace Eywa\Console\Database {
*/
public function execute(InputInterface $input, OutputInterface $output)
{
- $io = new SymfonyStyle($input, $output);
-
+ $io = new SymfonyStyle($input, $output);
- $prod = production()->info();
- $dev = development()->info();
-
- if ($io->confirm(sprintf('Are you sure to use the following as a production database ? <fg=black;bg=yellow>%s</>', $prod), false) && $io->confirm(sprintf('Are you sure to use the following as a development database ? <fg=black;bg=yellow>%s</>', $dev), false)) {
- return $this->create(strval(env('DEVELOP_DB_DRIVER', 'mysql')), strval(env('DB_DRIVER', 'mysql')), $io);
+ if ($io->confirm('Run the databases creation ?', true)) {
+ return $this->create(
+ strval(env('DEVELOP_DB_DRIVER', 'mysql')),
+ strval(env('DB_DRIVER', 'mysql')),
+ $io
+ );
}
$io->warning('Nothing has been done ! Modify the .env file and try again');
return 0;
@@ -85,7 +84,7 @@ namespace Eywa\Console\Database {
* @throws Exception
*/
- private function create(string $dev, string $prod, SymfonyStyle $io):int
+ private function create(string $dev, string $prod, SymfonyStyle $io): int
{
if (!is_dir(base('routes'))) {
mkdir(base('routes'));
@@ -94,38 +93,64 @@ namespace Eywa\Console\Database {
switch ($dev) {
case MYSQL:
do {
- $this->pass = $io->askQuestion((new Question($this->mysql_root_password_question, 'root'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->mysql_root_password_question, 'root'))
+ ->setHidden(true)
+ );
} while (!connect(MYSQL, '', 'root', $this->pass)->connected());
- if (connect(MYSQL, '', 'root', $this->pass)->create_database(strval(env('DEVELOP_DB_NAME', 'ikran')))) {
+ if (
+ connect(MYSQL, '', 'root', $this->pass)
+ ->createDatabase(strval(env('DEVELOP_DB_NAME', 'ikran')))
+ ) {
$io->success($this->dev_base_created_successfully);
} else {
$io->error($this->dev_base_created_fail);
return 1;
}
- if (connect(MYSQL, '', 'root', $this->pass)->create_user(strval(env('DEVELOP_DB_USERNAME', 'ikran')), strval(env('DEVELOP_DB_PASSWORD', 'ikran')), strval(env('DEVELOP_DB_NAME', 'ikran')))) {
+ if (
+ connect(MYSQL, '', 'root', $this->pass)
+ ->createUser(
+ strval(env('DEVELOP_DB_USERNAME', 'ikran')),
+ strval(env('DEVELOP_DB_PASSWORD', 'ikran')),
+ strval(env('DEVELOP_DB_NAME', 'ikran'))
+ )
+ ) {
$io->success($this->dev_user_created_successfully);
} else {
$io->error($this->dev_user_created_fail);
return 1;
}
- break;
+ break;
case POSTGRESQL:
do {
- $this->pass = $io->askQuestion((new Question($this->pgsql_root_password, 'postgres'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->pgsql_root_password, 'postgres'))
+ ->setHidden(true)
+ );
} while (!connect(POSTGRESQL, '', 'postgres', $this->pass)->connected());
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->create_database(strval(env('DEVELOP_DB_NAME', 'ikran')))) {
+
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->createDatabase(strval(env('DEVELOP_DB_NAME', 'ikran')))
+ ) {
$io->success($this->dev_base_created_successfully);
} else {
$io->error($this->dev_base_created_fail);
return 1;
}
-
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->create_user(strval(env('DEVELOP_DB_USERNAME', 'ikran')), strval(env('DEVELOP_DB_PASSWORD', 'ikran')), strval(env('DEVELOP_DB_NAME', 'ikran')))) {
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->createUser(
+ strval(env('DEVELOP_DB_USERNAME', 'ikran')),
+ strval(env('DEVELOP_DB_PASSWORD', 'ikran')),
+ strval(env('DEVELOP_DB_NAME', 'ikran'))
+ )
+ ) {
$io->success($this->dev_user_created_successfully);
} else {
$io->error($this->dev_user_created_fail);
@@ -133,79 +158,113 @@ namespace Eywa\Console\Database {
}
- break;
+ break;
default:
- if (connect(SQLITE, strval(env('DEVELOP_DB_NAME', 'ikran')))->connected()) {
+ if (connect(SQLITE, strval(env('DEVELOP_DB_NAME', 'ikran.sqlite3')))->connected()) {
$io->success($this->dev_base_created_successfully);
} else {
$io->error($this->dev_base_created_fail);
return 1;
}
- break;
-
+ break;
}
switch ($prod) {
case MYSQL:
-
if (!connect(MYSQL, '', 'root', $this->pass)->connected()) {
do {
- $this->pass = $io->askQuestion((new Question($this->mysql_root_password_question, 'root'))->setHidden(true));
+ $this->pass = $io->askQuestion((new Question($this->mysql_root_password_question, 'root'))
+ ->setHidden(true));
} while (!connect(MYSQL, '', 'root', $this->pass)->connected());
}
- if (connect(MYSQL, '', 'root', $this->pass)->create_database(strval(env('DB_NAME', 'eywa')))) {
+ if (
+ connect(MYSQL, '', 'mysql', $this->pass)
+ ->createDatabase(strval(env('DB_NAME', 'eywa')))
+ ) {
$io->success($this->prod_base_created_successfully);
} else {
$io->error($this->prod_base_created_fail);
return 1;
}
- if (connect(MYSQL, '', 'root', $this->pass)->create_user(strval(env('DB_USERNAME', 'eywa')), strval(env('DB_PASSWORD', 'eywa')), strval(env('DB_NAME', 'eywa')))) {
+ if (
+ connect(MYSQL, '', 'root', $this->pass)
+ ->createUser(
+ strval(env('DB_USERNAME', 'eywa')),
+ strval(env('DB_PASSWORD', 'eywa')),
+ strval(env('DB_NAME', 'eywa'))
+ )
+ ) {
$io->success($this->prod_user_created_successfully);
} else {
$io->error($this->prod_user_created_fail);
return 1;
}
- break;
+ break;
case POSTGRESQL:
-
if (!connect(POSTGRESQL, '', 'postgres', $this->pass)->connected()) {
do {
- $this->pass = $io->askQuestion((new Question($this->mysql_root_password_question, 'postgres'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->mysql_root_password_question, 'postgres'))
+ ->setHidden(true)
+ );
} while (!connect(POSTGRESQL, '', 'postgres', $this->pass)->connected());
}
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->create_database(strval(env('DB_NAME', 'eywa')))) {
+
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->createDatabase(strval(env('DB_NAME', 'eywa')))
+ ) {
$io->success($this->prod_base_created_successfully);
} else {
$io->error($this->prod_base_created_fail);
return 1;
}
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->create_user(strval(env('DB_USERNAME', 'eywa')), strval(env('DB_PASSWORD', 'eywa')), strval(env('DB_NAME', 'eywa')))) {
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->createUser(
+ strval(env('DB_USERNAME', 'eywa')),
+ strval(env('DB_PASSWORD', 'eywa')),
+ strval(env('DB_NAME', 'eywa'))
+ )
+ ) {
$io->success($this->prod_user_created_successfully);
} else {
$io->error($this->prod_user_created_fail);
return 1;
}
- break;
+ break;
default:
- if (connect(SQLITE, strval(env('DEVELOP_DB_NAME', 'ikran')))->connected()) {
+ if (connect(SQLITE, strval(env('DB_NAME', 'eywa.sqlite3')))->connected()) {
$io->success($this->prod_base_created_successfully);
} else {
$io->error($this->prod_base_created_fail);
return 1;
}
- break;
+ break;
}
if (connect(SQLITE, base('routes', 'web.sqlite3'))->connected()) {
$io->success($this->routing_instance_created_successfully);
- if (connect(SQLITE, base('routes', 'web.sqlite3'))->set('CREATE TABLE IF NOT EXISTS routes ( id INTEGER PRIMARY KEY AUTOINCREMENT, method TEXT(10) NOT NULL, name TEXT(255) NOT NULL UNIQUE,url TEXT(255) NOT NULL UNIQUE, controller TEXT(255) NOT NULL, directory TEXT(255) NOT NULL, action TEXT(255) NOT NULL, created_at DATETIME NOT NULL , updated_at DATETIME NOT NULL )')->execute()) {
+ if (
+ connect(SQLITE, base('routes', 'web.sqlite3'))
+ ->set('CREATE TABLE IF NOT EXISTS routes(
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ method TEXT(10) NOT NULL,
+ name TEXT(255) NOT NULL UNIQUE,
+ url TEXT(255) NOT NULL UNIQUE,
+ controller TEXT(255) NOT NULL,
+ directory TEXT(255) NOT NULL,
+ action TEXT(255) NOT NULL,
+ created_at DATETIME NOT NULL ,
+ updated_at DATETIME NOT NULL )')->execute()
+ ) {
$io->success('The routes table has been generated successfully');
} else {
$io->error('The creation of the routes table has failed');
diff --git a/eywa/Console/Database/MigrateDatabase.php b/eywa/Console/Database/MigrateDatabase.php
index da02f5a..84d197d 100755
--- a/eywa/Console/Database/MigrateDatabase.php
+++ b/eywa/Console/Database/MigrateDatabase.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Database {
@@ -16,7 +15,7 @@ namespace Eywa\Console\Database {
{
protected static $defaultName = 'db:migrate';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Run the migrations');
}
diff --git a/eywa/Console/Database/RollbackDatabase.php b/eywa/Console/Database/RollbackDatabase.php
index 5c5aca2..6a33eaf 100755
--- a/eywa/Console/Database/RollbackDatabase.php
+++ b/eywa/Console/Database/RollbackDatabase.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Database {
@@ -17,7 +16,7 @@ namespace Eywa\Console\Database {
protected static $defaultName = 'db:rollback';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Rollback the migrations')
->setHelp('php shaolin db:migrate env');
diff --git a/eywa/Console/Database/SeedDatabase.php b/eywa/Console/Database/SeedDatabase.php
index d241ea1..b72d6bf 100755
--- a/eywa/Console/Database/SeedDatabase.php
+++ b/eywa/Console/Database/SeedDatabase.php
@@ -1,35 +1,35 @@
<?php
- namespace Eywa\Console\Database
- {
+namespace Eywa\Console\Database
+{
- use Eywa\Database\Seed\Seeding;
- use ReflectionException;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Database\Seed\Seeding;
+ use ReflectionException;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class SeedDatabase extends Command
- {
- protected static $defaultName = 'db:seed';
+ class SeedDatabase extends Command
+ {
+ protected static $defaultName = 'db:seed';
- protected function configure():void
- {
- $this->setDescription("Seed the development database");
- }
+ protected function configure(): void
+ {
+ $this->setDescription("Seed the development database");
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws ReflectionException
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws ReflectionException
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- return Seeding::run($io);
- }
+ return Seeding::run($io);
}
}
+}
diff --git a/eywa/Console/Database/ShowTable.php b/eywa/Console/Database/ShowTable.php
index bbfd2c0..873d37c 100755
--- a/eywa/Console/Database/ShowTable.php
+++ b/eywa/Console/Database/ShowTable.php
@@ -1,82 +1,91 @@
<?php
- namespace Eywa\Console\Database
- {
-
- use Eywa\Database\Table\Table;
- use Eywa\Exception\Kedavra;
- use PDO;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
+namespace Eywa\Console\Database
+{
- class ShowTable extends Command
- {
- protected static $defaultName = 'table:list';
+ use Eywa\Database\Table\Table;
+ use Eywa\Exception\Kedavra;
+ use PDO;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
- /**
- * @var array<string>
- */
- private array $tables = [];
+ class ShowTable extends Command
+ {
+ protected static $defaultName = 'table:list';
- protected function configure(): void
- {
- $this->setDescription("List all tables found in the base")->addArgument('env', InputArgument::REQUIRED, 'The base environment');
- }
+ protected function configure(): void
+ {
+ $this->setDescription("List all tables found in the base")
+ ->addArgument('env', InputArgument::REQUIRED, 'The base environment');
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws Kedavra
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $table = new \Symfony\Component\Console\Helper\Table($output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $table = new \Symfony\Component\Console\Helper\Table($output);
- $env = strval($input->getArgument('env'));
+ $env = strval($input->getArgument('env'));
- not_in(['dev','prod'], $env, true, 'The env must be dev or prod');
+ not_in(['dev','prod'], $env, true, 'The env must be dev or prod');
- if (equal($env, 'dev')) {
- switch (development()->driver()) {
- case MYSQL:
- $table->setStyle('box')->setHeaders(['Table','Records','Collation','Creation','Update']);
- $table->setRows(development()->set('SELECT TABLE_NAME ,TABLE_ROWS,TABLE_COLLATION ,CREATE_TIME,UPDATE_TIME FROM information_schema.tables WHERE Table_schema=DATABASE();')->get(PDO::FETCH_ASSOC));
- $table->render();
+ if (equal($env, 'dev')) {
+ switch (development()->driver()) {
+ case MYSQL:
+ $table->setStyle('box')->setHeaders(['Table','Records','Collation','Creation','Update']);
+ $table->setRows(development()
+ ->set(
+ 'SELECT TABLE_NAME, TABLE_ROWS,TABLE_COLLATION
+ CREATE_TIME,UPDATE_TIME FROM information_schema.tables
+ WHERE Table_schema=DATABASE();'
+ )
+ ->get(PDO::FETCH_ASSOC));
+ $table->render();
break;
- case POSTGRESQL:
- $table->setStyle('box')->setHeaders(['Schema','Table','Records']);
- $table->setRows(development()->set('SELECT schemaname,relname,n_tup_ins FROM pg_stat_user_tables;')->get(PDO::FETCH_ASSOC));
- $table->render();
+ case POSTGRESQL:
+ $table->setStyle('box')->setHeaders(['Schema','Table','Records']);
+ $table->setRows(development()
+ ->set('SELECT schemaname,relname,n_tup_ins FROM pg_stat_user_tables;')
+ ->get(PDO::FETCH_ASSOC));
+ $table->render();
break;
- default:
- $this->tables = (new Table(development(), ''))->show()->all();
+ default:
+ $tables = (new Table(development(), ''))->show()->all();
break;
- }
}
+ }
- if (equal($env, 'prod')) {
- switch (production()->driver()) {
- case MYSQL:
- $table->setStyle('box')->setHeaders(['Table','Records','Collation','Creation','Update']);
- $table->setRows(production()->set('SELECT TABLE_NAME ,TABLE_ROWS,TABLE_COLLATION ,CREATE_TIME,UPDATE_TIME FROM information_schema.tables WHERE Table_schema=DATABASE();')->get(PDO::FETCH_ASSOC));
- $table->render();
+ if (equal($env, 'prod')) {
+ switch (production()->driver()) {
+ case MYSQL:
+ $table->setStyle('box')->setHeaders(['Table','Records','Collation','Creation','Update']);
+ $table->setRows(production()
+ ->set('SELECT TABLE_NAME ,TABLE_ROWS,TABLE_COLLATION ,CREATE_TIME,UPDATE_TIME
+ FROM information_schema.tables WHERE Table_schema=DATABASE();')
+ ->get(PDO::FETCH_ASSOC));
+ $table->render();
break;
- case POSTGRESQL:
- $table->setStyle('box')->setHeaders(['Schema','Table','Records']);
- $table->setRows(production()->set('SELECT schemaname,relname,n_tup_ins FROM pg_stat_user_tables;')->get(PDO::FETCH_ASSOC));
- $table->render();
+ case POSTGRESQL:
+ $table->setStyle('box')->setHeaders(['Schema','Table','Records']);
+ $table->setRows(production()
+ ->set('SELECT schemaname,relname,n_tup_ins FROM pg_stat_user_tables;')
+ ->get(PDO::FETCH_ASSOC));
+ $table->render();
break;
- default:
- $this->tables = (new Table(production(), ''))->show()->all();
+ default:
+ $tables = (new Table(production(), ''))->show()->all();
break;
- }
}
-
- return 0;
}
+
+ return 0;
}
}
+}
diff --git a/eywa/Console/Database/ShowUsers.php b/eywa/Console/Database/ShowUsers.php
index c73c2e3..0c3e99d 100755
--- a/eywa/Console/Database/ShowUsers.php
+++ b/eywa/Console/Database/ShowUsers.php
@@ -1,53 +1,54 @@
<?php
- namespace Eywa\Console\Database
- {
+namespace Eywa\Console\Database
+{
- use Eywa\Database\User\User;
- use Eywa\Exception\Kedavra;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Database\User\User;
+ use Eywa\Exception\Kedavra;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class ShowUsers extends Command
- {
- protected static $defaultName = 'users:show';
+ class ShowUsers extends Command
+ {
+ protected static $defaultName = 'users:show';
- protected function configure():void
- {
- $this->setDescription("List all users found in the base")->addArgument('env', InputArgument::REQUIRED, 'The base environment');
- }
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws Kedavra
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ protected function configure(): void
+ {
+ $this->setDescription("List all users found in the base")
+ ->addArgument('env', InputArgument::REQUIRED, 'The base environment');
+ }
- $env = strval($input->getArgument('env'));
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- not_in(['dev','prod'], $env, true, 'The env must be dev or prod');
+ $env = strval($input->getArgument('env'));
- if (equal($env, 'dev')) {
- $x = (new User(development()))->show()->all();
- } else {
- $x = (new User(production()))->show()->all();
- }
- if (not_def($x)) {
- $io->error("No users found");
- return 1;
- }
- foreach ($x as $table) {
- $io->success($table);
- }
+ not_in(['dev','prod'], $env, true, 'The env must be dev or prod');
- return 0;
+ if (equal($env, 'dev')) {
+ $x = (new User(development()))->show()->all();
+ } else {
+ $x = (new User(production()))->show()->all();
+ }
+ if (not_def($x)) {
+ $io->error("No users found");
+ return 1;
}
+ foreach ($x as $table) {
+ $io->success($table);
+ }
+
+ return 0;
}
}
+}
diff --git a/eywa/Console/Database/TruncateTable.php b/eywa/Console/Database/TruncateTable.php
index 5344539..da1bb9b 100755
--- a/eywa/Console/Database/TruncateTable.php
+++ b/eywa/Console/Database/TruncateTable.php
@@ -1,53 +1,55 @@
<?php
- namespace Eywa\Console\Database
- {
+namespace Eywa\Console\Database
+{
- use Eywa\Database\Connexion\Connect;
- use Eywa\Database\Table\Table;
- use Eywa\Exception\Kedavra;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Database\Connexion\Connect;
+ use Eywa\Database\Table\Table;
+ use Eywa\Exception\Kedavra;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class TruncateTable extends Command
- {
- protected static $defaultName = 'table:clear';
+ class TruncateTable extends Command
+ {
+ protected static $defaultName = 'table:clear';
- protected function configure():void
- {
- $this->setDescription("Truncate a table")->addArgument('table', InputArgument::REQUIRED, 'The table name')->addArgument('env', InputArgument::REQUIRED, 'The base environment');
- }
+ protected function configure(): void
+ {
+ $this->setDescription("Truncate a table")
+ ->addArgument('table', InputArgument::REQUIRED, 'The table name')
+ ->addArgument('env', InputArgument::REQUIRED, 'The base environment');
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws Kedavra
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- $env = strval($input->getArgument('env'));
- $table = strval($input->getArgument('table'));
- not_in(['dev','prod'], $env, true, 'The environement used is not valid');
+ $env = strval($input->getArgument('env'));
+ $table = strval($input->getArgument('table'));
+ not_in(['dev','prod'], $env, true, 'The environement used is not valid');
- if (equal($env, 'dev')) {
- $success = (new Table(development(), $table))->truncate();
- } else {
- $success = (new Table(production(), $table))->truncate();
- }
+ if (equal($env, 'dev')) {
+ $success = (new Table(development(), $table))->truncate();
+ } else {
+ $success = (new Table(production(), $table))->truncate();
+ }
- if ($success) {
- $io->success("The $table table has been successfully truncated");
- return 0;
- }
- $io->error("The truncate task for the $table table has failed");
- return 1;
+ if ($success) {
+ $io->success("The $table table has been successfully truncated");
+ return 0;
}
+ $io->error("The truncate task for the $table table has failed");
+ return 1;
}
}
+}
diff --git a/eywa/Console/Database/UninstallDatabase.php b/eywa/Console/Database/UninstallDatabase.php
index bd872dd..dafdc55 100755
--- a/eywa/Console/Database/UninstallDatabase.php
+++ b/eywa/Console/Database/UninstallDatabase.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Database {
use Exception;
@@ -42,7 +41,7 @@ namespace Eywa\Console\Database {
private string $routing_instance_creation_has_fail = 'The deletion of the routing database has failed';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Rollback the db:install command');
}
@@ -59,14 +58,12 @@ namespace Eywa\Console\Database {
{
$io = new SymfonyStyle($input, $output);
+ $confirm = $io->confirm(sprintf('Are you sure to remove all databases ?'), false);
-
- $prod = production()->info();
- $dev = development()->info();
-
- if ($io->confirm(sprintf('Are you sure to remove the following production database ? <fg=black;bg=yellow>%s</>', $prod), false) && $io->confirm(sprintf('Are you sure to remove the development database ? <fg=black;bg=yellow>%s</>', $dev), false)) {
- return $this->create(strval(env('DEVELOP_DB_DRIVER', 'mysql')), strval(env('DB_DRIVER', 'mysql')), $io);
+ if ($confirm) {
+ return $this->create(strval(env('DEVELOP_DB_DRIVER', 'mysql')), strval(env('DB_DRIVER', 'mysql')), $io);
}
+
$io->warning('Nothing has been done ! Modify the .env file and try again');
return 0;
}
@@ -80,23 +77,31 @@ namespace Eywa\Console\Database {
* @throws Kedavra
* @throws Exception
*/
-
- private function create(string $dev, string $prod, SymfonyStyle $io):int
+ private function create(string $dev, string $prod, SymfonyStyle $io): int
{
switch ($dev) {
case MYSQL:
do {
- $this->pass = $io->askQuestion((new Question($this->mysql_root_password_question, 'root'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->mysql_root_password_question, 'root'))
+ ->setHidden(true)
+ );
} while (!connect(MYSQL, '', 'root', $this->pass)->connected());
- if (connect(MYSQL, '', 'root', $this->pass)->remove_database(strval(env('DEVELOP_DB_NAME', 'ikran')))) {
+ if (
+ connect(MYSQL, '', 'root', $this->pass)
+ ->removeDatabase(strval(env('DEVELOP_DB_NAME', 'ikran')))
+ ) {
$io->success($this->dev_base_created_successfully);
} else {
$io->error($this->dev_base_created_fail);
return 1;
}
- if (connect(MYSQL, '', 'root', $this->pass)->remove_user(strval(env('DEVELOP_DB_USERNAME', 'ikran')))) {
+ if (
+ connect(MYSQL, '', 'root', $this->pass)
+ ->removeUser(strval(env('DEVELOP_DB_USERNAME', 'ikran')))
+ ) {
$io->success($this->dev_user_created_successfully);
} else {
$io->error($this->dev_user_created_fail);
@@ -106,17 +111,26 @@ namespace Eywa\Console\Database {
case POSTGRESQL:
do {
- $this->pass = $io->askQuestion((new Question($this->pgsql_root_password, 'postgres'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->pgsql_root_password, 'postgres'))
+ ->setHidden(true)
+ );
} while (!connect(POSTGRESQL, '', 'postgres', $this->pass)->connected());
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->remove_database(strval(env('DEVELOP_DB_NAME', 'ikran')))) {
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->removeDatabase(strval(env('DEVELOP_DB_NAME', 'ikran')))
+ ) {
$io->success($this->dev_base_created_successfully);
} else {
$io->error($this->dev_base_created_fail);
return 1;
}
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->remove_user(strval(env('DEVELOP_DB_USERNAME', 'ikran')))) {
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->removeUser(strval(env('DEVELOP_DB_USERNAME', 'ikran')))
+ ) {
$io->success($this->dev_user_created_successfully);
} else {
$io->error($this->dev_user_created_fail);
@@ -133,27 +147,28 @@ namespace Eywa\Console\Database {
return 1;
}
break;
-
}
switch ($prod) {
case MYSQL:
-
if (!connect(MYSQL, '', 'root', $this->pass)->connected()) {
do {
- $this->pass = $io->askQuestion((new Question($this->mysql_root_password_question, 'root'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->mysql_root_password_question, 'root'))
+ ->setHidden(true)
+ );
} while (!connect(MYSQL, '', 'root', $this->pass)->connected());
}
- if (connect(MYSQL, '', 'root', $this->pass)->remove_database(strval(env('DB_NAME', 'eywa')))) {
+ if (connect(MYSQL, '', 'root', $this->pass)->removeDatabase(strval(env('DB_NAME', 'eywa')))) {
$io->success($this->prod_base_created_successfully);
} else {
$io->error($this->prod_base_created_fail);
return 1;
}
- if (connect(MYSQL, '', 'root', $this->pass)->remove_user(strval(env('DB_USERNAME', 'eywa')))) {
+ if (connect(MYSQL, '', 'root', $this->pass)->removeUser(strval(env('DB_USERNAME', 'eywa')))) {
$io->success($this->prod_user_created_successfully);
} else {
$io->error($this->prod_user_created_fail);
@@ -162,20 +177,28 @@ namespace Eywa\Console\Database {
break;
case POSTGRESQL:
-
if (!connect(POSTGRESQL, '', 'postgres', $this->pass)->connected()) {
do {
- $this->pass = $io->askQuestion((new Question($this->pgsql_root_password, 'postgres'))->setHidden(true));
+ $this->pass = $io->askQuestion(
+ (new Question($this->pgsql_root_password, 'postgres'))
+ ->setHidden(true)
+ );
} while (!connect(POSTGRESQL, '', 'postgres', $this->pass)->connected());
}
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->remove_database(strval(env('DB_NAME', 'eywa')))) {
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->removeDatabase(strval(env('DB_NAME', 'eywa')))
+ ) {
$io->success($this->prod_base_created_successfully);
} else {
$io->error($this->prod_base_created_fail);
return 1;
}
- if (connect(POSTGRESQL, '', 'postgres', $this->pass)->remove_user(strval(env('DB_USERNAME', 'eywa')))) {
+ if (
+ connect(POSTGRESQL, '', 'postgres', $this->pass)
+ ->removeUser(strval(env('DB_USERNAME', 'eywa')))
+ ) {
$io->success($this->prod_user_created_successfully);
} else {
$io->error($this->prod_user_created_fail);
diff --git a/eywa/Console/Generate/GenerateCommand.php b/eywa/Console/Generate/GenerateCommand.php
index d13a0c0..fa5e7cc 100755
--- a/eywa/Console/Generate/GenerateCommand.php
+++ b/eywa/Console/Generate/GenerateCommand.php
@@ -14,14 +14,18 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:console';
- protected function configure():void
+ protected function configure(): void
{
$this
// the short description shown while running "php bin/console list"
->setDescription('Create a new console')
// the full command description shown when running the command with
// the "--help" option
- ->setHelp('php shaolin make:model model table')->addArgument('console', InputArgument::REQUIRED, 'The console name.');
+ ->setHelp('php shaolin make:model model table')
+ ->addArgument('console', InputArgument::REQUIRED, 'The console name')
+ ->addArgument('name', InputArgument::REQUIRED, 'The console command')
+ ->addArgument('description', InputArgument::REQUIRED, 'The comand description')
+ ->addArgument('directory', InputArgument::OPTIONAL, 'The console directory');
}
/**
@@ -36,32 +40,40 @@ namespace Eywa\Console\Generate {
$io = new SymfonyStyle($input, $output);
$x = strval($input->getArgument('console'));
+ $command = strval($input->getArgument('name'));
+ $description = strval($input->getArgument('description'));
if (preg_match("#^[a-z]([a-z_]+)$#", $x) !== 1) {
$io->error('You must use snake case syntax to generate the console');
- return 1;
+ return 1;
}
+ $directory = ucfirst(strval($input->getArgument('directory')));
+
+ if (!is_dir(base('app', 'Console', $directory))) {
+ mkdir(base('app', 'Console', $directory));
+ }
$io->title('Generation of the console');
$console = collect(explode('_', $x))->for('ucfirst')->join('');
- $namespace = 'App\Console';
+ $namespace = def($directory) ? 'App\Console\\' . $directory : 'App\Console';
- $file = base('app', 'Console', "$console.php");
+ $file = def($directory)
+ ? base('app', 'Console', $directory, "$console.php")
+ : base('app', 'Console', "$console.php");
if (file_exists($file)) {
$io->error(sprintf('The %s console already exist', $console));
return 1;
}
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
-
+ if (
+ (new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace $namespace;
-
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -69,23 +81,22 @@ use Symfony\Component\Console\Style\SymfonyStyle;
class $console extends Command
{
- protected static \$defaultName = '';
+ protected static \$defaultName = '$command';
protected function configure(): void
{
-
- \$this->setDescription('');
-
+ \$this->setDescription('$description');
}
+
public function execute(InputInterface \$input, OutputInterface \$output): int
{
- \$io = new SymfonyStyle(\$input,\$output);
+ \$io = new SymfonyStyle(\$input, \$output);
return 0;
}
-
-}")->flush()) {
+}\n")->flush()
+ ) {
$io->success(sprintf('The %s console has been created successfully', $console));
return 0;
diff --git a/eywa/Console/Generate/GenerateContainer.php b/eywa/Console/Generate/GenerateContainer.php
index 79e2344..7c1acd9 100755
--- a/eywa/Console/Generate/GenerateContainer.php
+++ b/eywa/Console/Generate/GenerateContainer.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:container';
- protected function configure():void
+ protected function configure(): void
{
$this
@@ -75,7 +75,8 @@ namespace Eywa\Console\Generate {
return 1;
}
- if ((new File("$file", EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File("$file", EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace $namespace;
@@ -94,7 +95,8 @@ class $class extends Container
return \$this;
}
}
-")->flush()) {
+")->flush()
+ ) {
$io->success(sprintf('The %s container has been generated successfully', $class));
return 0;
diff --git a/eywa/Console/Generate/GenerateController.php b/eywa/Console/Generate/GenerateController.php
index f7da3a7..1eccba4 100755
--- a/eywa/Console/Generate/GenerateController.php
+++ b/eywa/Console/Generate/GenerateController.php
@@ -15,14 +15,14 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:controller';
- protected function configure():void
+ protected function configure(): void
{
$this
- // the short description shown while running "php bin/console list"
->setDescription('Create a new controller')
- // the full command description shown when running the command with
- // the "--help" option
- ->setHelp('php shaolin make:controller controller_name')->addArgument('controller', InputArgument::REQUIRED, 'The controller name.')->addArgument('directory', InputArgument::OPTIONAL, 'The controller directory')->addArgument('layout', InputArgument::OPTIONAL, 'the layout to use');
+ ->setHelp('php shaolin make:controller controller_name')
+ ->addArgument('controller', InputArgument::REQUIRED, 'The controller name.')
+ ->addArgument('directory', InputArgument::OPTIONAL, 'The controller directory')
+ ->addArgument('layout', InputArgument::OPTIONAL, 'the layout to use');
}
/**
@@ -42,17 +42,19 @@ namespace Eywa\Console\Generate {
if (preg_match("#^[a-z]([a-z_]+)$#", $controller) !== 1) {
$io->error('You must use snake case syntax to generate the controller');
- return 1;
+ return 1;
}
- if (def($directory) && ! is_dir(base('app', 'Controllers', $directory))) {
+ if (def($directory) && !is_dir(base('app', 'Controllers', $directory))) {
mkdir(base('app', 'Controllers', $directory));
}
$controller_class = collect(explode('_', $controller))->for('ucfirst')->join('');
- $controller_file = def($directory)? base('app', 'Controllers', $directory, "$controller_class.php"): base('app', 'Controllers', "$controller_class.php");
+ $controller_file = def($directory)
+ ? base('app', 'Controllers', $directory, "$controller_class.php")
+ : base('app', 'Controllers', "$controller_class.php");
if (file_exists($controller_file)) {
$io->error(sprintf('The %s controller already exist', $controller_class));
@@ -63,11 +65,14 @@ namespace Eywa\Console\Generate {
$namespace = def($directory) ? "App\Controllers\\$directory" : 'App\Controllers';
- $layout = def($layout) ? "protected static string \$layout = '$layout';" : "protected static string \$layout = 'layout';";
+ $layout = def($layout)
+ ? "protected static string \$layout = '$layout';"
+ : "protected static string \$layout = 'layout';";
$directory = def($directory) ? "protected static string \$directory = '$directory';" : '';
- if ((new File($controller_file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File($controller_file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace $namespace {
@@ -98,12 +103,13 @@ namespace $namespace {
}
}
-}")->flush()) {
- $io->success("The $controller_class controller has been generated successfully");
+}")->flush()
+ ) {
+ $io->success(sprintf('The %s controller has been generated successfully', $controller_class));
return 0;
}
- $io->error("The $controller_class controller generation has failed");
+ $io->error(sprintf('The %s controller generation has failed', $controller_class));
return 1;
}
}
diff --git a/eywa/Console/Generate/GenerateForm.php b/eywa/Console/Generate/GenerateForm.php
index d671c15..62d75b7 100755
--- a/eywa/Console/Generate/GenerateForm.php
+++ b/eywa/Console/Generate/GenerateForm.php
@@ -15,9 +15,11 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:form';
- protected function configure():void
+ protected function configure(): void
{
- $this->setDescription('Create a new form')->addArgument('form', InputArgument::REQUIRED, 'The form name.')->addArgument('directory', InputArgument::OPTIONAL, 'The form directory');
+ $this->setDescription('Create a new form')
+ ->addArgument('form', InputArgument::REQUIRED, 'The form name.')
+ ->addArgument('directory', InputArgument::OPTIONAL, 'The form directory');
}
/**
@@ -36,17 +38,19 @@ namespace Eywa\Console\Generate {
if (preg_match("#^[a-z]([a-z_]+)$#", $form) !== 1) {
$io->error('You must use snake case syntax to generate the form');
- return 1;
+ return 1;
}
- if (def($directory) && ! is_dir(base('app', 'Forms', $directory))) {
+ if (def($directory) && !is_dir(base('app', 'Forms', $directory))) {
mkdir(base('app', 'Forms', $directory));
}
$form_class = collect(explode('_', $form))->for('ucfirst')->join('');
- $form_file = def($directory)? base('app', 'Forms', $directory, "$form_class.php"): base('app', 'Forms', "$form_class.php");
+ $form_file = def($directory)
+ ? base('app', 'Forms', $directory, "$form_class.php")
+ : base('app', 'Forms', "$form_class.php");
if (file_exists($form_file)) {
$io->error(sprintf('The %s form already exist', $form_class));
@@ -58,7 +62,8 @@ namespace Eywa\Console\Generate {
$namespace = def($directory) ? "App\Forms\\$directory" : 'App\Forms';
- if ((new File($form_file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File($form_file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace $namespace;
@@ -111,7 +116,8 @@ class $form_class extends Form
{
return new Response('');
}
-}")->flush()) {
+}")->flush()
+ ) {
$io->success(sprintf('The %s form has been generated successfully', $form_class));
return 0;
diff --git a/eywa/Console/Generate/GenerateMiddleware.php b/eywa/Console/Generate/GenerateMiddleware.php
index 888f8cc..00000f1 100755
--- a/eywa/Console/Generate/GenerateMiddleware.php
+++ b/eywa/Console/Generate/GenerateMiddleware.php
@@ -14,14 +14,13 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:middleware';
- protected function configure():void
+ protected function configure(): void
{
$this
- // the short description shown while running "php bin/console list"
->setDescription('Create a new middleware')
- // the full command description shown when running the command with
- // the "--help" option
- ->setHelp('php shaolin make:middleware name')->addArgument('middleware', InputArgument::REQUIRED, 'The middleware name.');
+ ->setHelp('php shaolin make:middleware name')
+ ->addArgument('middleware', InputArgument::REQUIRED, 'The middleware name.')
+ ->addArgument('directory', InputArgument::OPTIONAL, 'The middleware directory.');
}
/**
@@ -44,21 +43,33 @@ namespace Eywa\Console\Generate {
$class = collect(explode('_', $middleware))->for('ucfirst')->join('');
- $file = base('app', 'Middleware', "$class.php");
+ $directory = ucfirst(strval($input->getArgument('directory')));
+
+ if (def($directory)) {
+ if (!is_dir(base('app', 'Middleware', $directory))) {
+ mkdir(base('app', 'Middleware', $directory));
+ }
+ }
+ $file = def($directory) ? base('app', 'Middleware', $directory, "$class.php")
+ : base('app', 'Middleware', "$class.php");
+
+ $namespace = def($directory) ? 'App\Middleware\\' . $directory : 'App\Middleware';
if (file_exists($file)) {
$io->error(sprintf('The %s middleware already exist', $class));
return 1;
}
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
-namespace App\Middleware {
+ if (
+ (new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+
+
+namespace $namespace {
use Eywa\Http\Middleware\Middleware;
use Eywa\Http\Request\ServerRequest;
- use Eywa\Http\Response\Response;
class $class extends Middleware
{
@@ -71,7 +82,8 @@ namespace App\Middleware {
// TODO: Implement check() method.
}
}
-}")->flush()) {
+}\n")->flush()
+ ) {
$io->success(sprintf('The %s middleware was generated successfully', $class));
return 0;
diff --git a/eywa/Console/Generate/GenerateMigration.php b/eywa/Console/Generate/GenerateMigration.php
index 16bc422..3d3a32b 100755
--- a/eywa/Console/Generate/GenerateMigration.php
+++ b/eywa/Console/Generate/GenerateMigration.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:migration';
- protected function configure():void
+ protected function configure(): void
{
$this
// the short description shown while running "php bin/console list"
@@ -55,7 +55,8 @@ namespace Eywa\Console\Generate {
$time = date('Y-m-d-H-i-s');
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace Evolution\Migrations {
@@ -91,7 +92,8 @@ namespace Evolution\Migrations {
}
}
-}")->flush()) {
+}")->flush()
+ ) {
$io->success(sprintf('The %s migration was successfully generated', $class));
return 0;
}
diff --git a/eywa/Console/Generate/GenerateModel.php b/eywa/Console/Generate/GenerateModel.php
index d48a488..038497e 100755
--- a/eywa/Console/Generate/GenerateModel.php
+++ b/eywa/Console/Generate/GenerateModel.php
@@ -14,14 +14,17 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:model';
- protected function configure():void
+ protected function configure(): void
{
$this
// the short description shown while running "php bin/console list"
->setDescription('Create a new model')
// the full command description shown when running the command with
// the "--help" option
- ->setHelp('php shaolin make:model model table')->addArgument('model', InputArgument::REQUIRED, 'The model name.')->addArgument('table', InputArgument::REQUIRED, 'The table name.');
+ ->setHelp('php shaolin make:model model table')
+ ->addArgument('model', InputArgument::REQUIRED, 'The model name.')
+ ->addArgument('table', InputArgument::REQUIRED, 'The table name.')
+ ->addArgument('directory', InputArgument::OPTIONAL, 'The directory name.');
}
/**
@@ -42,22 +45,45 @@ namespace Eywa\Console\Generate {
return 1;
}
- $io->title('Generation of the model');
-
+ $dir = ucfirst(strval($input->getArgument('directory')));
+ if (def($dir)) {
+ if (!is_dir(base('app', 'Models', $dir))) {
+ mkdir(base('app', 'Models', $dir));
+ }
+ }
$table = strval($input->getArgument('table'));
$model = collect(explode('_', $x))->for('ucfirst')->join('');
- $namespace = 'App\Models';
+ $namespace = def($dir)
+ ? 'App\Models\\' . $dir
+ : 'App\\Models';
- $file = base('app', 'Models', "$model.php");
+ $file = def($dir) ? base('app', 'Models', $dir, "$model.php") : base('app', 'Models', "$model.php");
if (file_exists($file)) {
- $io->error("The $model model already exist");
+ $io->error(sprintf('The %s model already exist', $model));
return 1;
}
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\nnamespace $namespace\n{ \n\n\tuse Eywa\Database\Model\Model;\n\n\tClass $model extends Model\n\t{\n\n\t\tprotected static string \$table = '$table';\n\n\t\tprotected static string \$by = 'id';\n\n\t\tprotected static int \$limit = 20;\n\n\t}\n\n}\n")->flush()) {
+ $io->title('Generation of the model');
+ if (
+ (new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+
+namespace $namespace
+{
+
+ use Eywa\Database\Model\Model;
+
+ class $model extends Model
+ {
+ protected static string \$table = '$table';
+
+ protected static int \$limit = 20;
+ }
+
+}\n")->flush()
+ ) {
$io->success(sprintf('The %s model has been generated successfully', $model));
return 0;
diff --git a/eywa/Console/Generate/GenerateSeeds.php b/eywa/Console/Generate/GenerateSeeds.php
index cd7960f..89537c3 100755
--- a/eywa/Console/Generate/GenerateSeeds.php
+++ b/eywa/Console/Generate/GenerateSeeds.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:seed';
- protected function configure():void
+ protected function configure(): void
{
$this
// the short description shown while running "php bin/console list"
@@ -56,7 +56,8 @@ namespace Eywa\Console\Generate {
$table = strval($input->getArgument('table'));
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace Evolution\Seeds {
@@ -95,7 +96,8 @@ namespace Evolution\Seeds {
}
}
}
-}")->flush()) {
+}")->flush()
+ ) {
$io->success(sprintf('The %s seeder was successfully generated', $class));
return 0;
}
diff --git a/eywa/Console/Generate/GenerateTest.php b/eywa/Console/Generate/GenerateTest.php
index 6ad972e..265e957 100755
--- a/eywa/Console/Generate/GenerateTest.php
+++ b/eywa/Console/Generate/GenerateTest.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:test';
- protected function configure():void
+ protected function configure(): void
{
$this
@@ -53,7 +53,7 @@ namespace Eywa\Console\Generate {
$io->error(sprintf('The %s tests already exist', $class));
return 1;
}
- $x= ucfirst(strval($input->getArgument('directory')));
+ $x = ucfirst(strval($input->getArgument('directory')));
if (def($x) && !is_dir(base('tests', $x))) {
mkdir(base('tests', $x));
@@ -62,7 +62,8 @@ namespace Eywa\Console\Generate {
$io->title('Generation of the test');
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace $namespace {
@@ -74,7 +75,8 @@ namespace $namespace {
}
}
-")->flush()) {
+")->flush()
+ ) {
$io->success(sprintf('The %s test has been created successfully', $class));
return 0;
}
diff --git a/eywa/Console/Generate/GenerateValidator.php b/eywa/Console/Generate/GenerateValidator.php
index 3a37960..566f97b 100755
--- a/eywa/Console/Generate/GenerateValidator.php
+++ b/eywa/Console/Generate/GenerateValidator.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
{
protected static $defaultName = 'make:validator';
- protected function configure():void
+ protected function configure(): void
{
$this
@@ -75,7 +75,8 @@ namespace Eywa\Console\Generate {
return 1;
}
- if ((new File("$file", EMPTY_AND_WRITE_FILE_MODE))->write("<?php
+ if (
+ (new File("$file", EMPTY_AND_WRITE_FILE_MODE))->write("<?php
namespace $namespace {
@@ -102,7 +103,8 @@ namespace $namespace {
}
}
}
- ")->flush()) {
+ ")->flush()
+ ) {
$io->success(sprintf('The %s validator has been generated successfully', $class));
return 0;
diff --git a/eywa/Console/Generate/GenerateView.php b/eywa/Console/Generate/GenerateView.php
index 599a7ca..1f99670 100755
--- a/eywa/Console/Generate/GenerateView.php
+++ b/eywa/Console/Generate/GenerateView.php
@@ -1,6 +1,6 @@
<?php
-
- namespace Eywa\Console\Generate;
+
+namespace Eywa\Console\Generate {
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -11,15 +11,17 @@
class GenerateView extends Command
{
protected static $defaultName = "make:view";
-
- protected function configure():void
+
+ protected function configure(): void
{
- $this->setDescription('Generate a view')->addArgument('view', InputArgument::REQUIRED, 'the view name')->addArgument('dir', InputArgument::OPTIONAL, 'the view dir');
+ $this->setDescription('Generate a view')
+ ->addArgument('view', InputArgument::REQUIRED, 'the view name')
+ ->addArgument('dir', InputArgument::OPTIONAL, 'the view dir');
}
-
+
/**
- * @param InputInterface $input
- * @param OutputInterface $output
+ * @param InputInterface $input
+ * @param OutputInterface $output
*
* @return int|void|null
*/
@@ -35,10 +37,10 @@
mkdir(base('app', 'Views', $dir));
}
}
-
- $view = collect(explode('.', strval($input->getArgument('view'))))->first();
-
- append($view, '.php');
+
+ $view = collect(explode('.', strval($input->getArgument('view'))))->first();
+
+ append($view, '.html');
$view = def($dir) ? base('app', 'Views', $dir, $view) : base('app', 'Views', $view);
if (file_exists($view)) {
@@ -47,10 +49,16 @@
}
if (touch($view)) {
- $io->success(sprintf('The %s view has been generated successfully', strval($input->getArgument('view'))));
+ $io->success(
+ sprintf(
+ 'The %s view has been generated successfully',
+ strval($input->getArgument('view'))
+ )
+ );
return 0;
}
$io->error(sprintf('The %s view generation has failed', strval($input->getArgument('view'))));
return 1;
}
}
+}
diff --git a/eywa/Console/Get/Documentation.php b/eywa/Console/Get/Documentation.php
index 0443b9d..9157e61 100755
--- a/eywa/Console/Get/Documentation.php
+++ b/eywa/Console/Get/Documentation.php
@@ -1,59 +1,63 @@
<?php
- namespace Eywa\Console\Get
- {
+namespace Eywa\Console\Get
+{
- use Eywa\Console\Shell;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Console\Shell;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class Documentation extends Command
- {
- protected static $defaultName = "get:doc";
+ class Documentation extends Command
+ {
+ protected static $defaultName = "get:doc";
- protected function configure():void
- {
- $this->setDescription('Get the eywa and shaolin documentation')->addArgument('directory', InputArgument::REQUIRED, 'The documentation directory name');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Get the eywa and shaolin documentation')
+ ->addArgument('directory', InputArgument::REQUIRED, 'The documentation directory name');
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return int|null
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- $io->title('Downlaoding or updating the documentation');
- $dir = strval($input->getArgument('directory'));
- if (is_dir($dir)) {
- if (chdir($dir)) {
- $io->success('Checkout inside the documentation directory');
- }
+ $io->title('Downlaoding or updating the documentation');
+ $dir = strval($input->getArgument('directory'));
+ if (is_dir($dir)) {
+ if (chdir($dir)) {
+ $io->success('Checkout inside the documentation directory');
+ }
- if ((new Shell('git pull origin master'))->run()) {
- $io->success('Documentation is up to date');
- return 0;
- } else {
- $io->error('We have not found git');
- return 1;
- }
+ if ((new Shell('git pull origin master'))->run()) {
+ $io->success('Documentation is up to date');
+ return 0;
+ } else {
+ $io->error('We have not found git');
+ return 1;
+ }
+ } else {
+ if (
+ (new Shell(sprintf('git clone https://github.com/fumseckworld/documentation.git %s', $dir)))
+ ->run()
+ ) {
+ $io->success('Documentation has been downloaded successfully');
+ return 0;
} else {
- if ((new Shell("git clone https://github.com/fumseckworld/documentation.git $dir"))->run()) {
- $io->success('Documentation has been downloaded successfully');
- return 0;
- } else {
- $io->error('We have not found git');
- return 1;
- }
+ $io->error('We have not found git');
+ return 1;
}
}
}
}
+}
diff --git a/eywa/Console/Get/Wanted.php b/eywa/Console/Get/Wanted.php
index 6891268..98ac6b5 100755
--- a/eywa/Console/Get/Wanted.php
+++ b/eywa/Console/Get/Wanted.php
@@ -1,50 +1,51 @@
<?php
- namespace Eywa\Console\Get
- {
+namespace Eywa\Console\Get
+{
- use Eywa\Console\Shell;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+ use Eywa\Console\Shell;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class Wanted extends Command
- {
- protected static $defaultName = "get:wanted";
+ class Wanted extends Command
+ {
+ protected static $defaultName = "get:wanted";
- protected function configure(): void
- {
- $this->setDescription('Get the wanted style')->addArgument('directory', InputArgument::REQUIRED, 'The documentation directory name');
- }
+ protected function configure(): void
+ {
+ $this->setDescription('Get the wanted style')
+ ->addArgument('directory', InputArgument::REQUIRED, 'The documentation directory name');
+ }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return int|null
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- $io->title('Downlaoding wanted');
- $dir = strval($input->getArgument('directory'));
- if (is_dir($dir)) {
- $io->error('Wanted already exist');
- return 1;
+ $io->title('Downlaoding wanted');
+ $dir = strval($input->getArgument('directory'));
+ if (is_dir($dir)) {
+ $io->error('Wanted already exist');
+ return 1;
+ } else {
+ if ((new Shell(sprintf('git clone https://github.com/fumseckworld/wanted.git %s', $dir)))->run()) {
+ $io->success('Wanted has been downloaded successfully');
+ return 0;
} else {
- if ((new Shell("git clone https://github.com/fumseckworld/wanted.git $dir"))->run()) {
- $io->success('Wanted has been downloaded successfully');
- return 0;
- } else {
- $io->error('We have not found git');
- return 1;
- }
+ $io->error('We have not found git');
+ return 1;
}
}
}
}
+}
diff --git a/eywa/Console/Lang/CreateCatalogues.php b/eywa/Console/Lang/CreateCatalogues.php
deleted file mode 100755
index 1ae414b..0000000
--- a/eywa/Console/Lang/CreateCatalogues.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-
-
-namespace Eywa\Console\Lang {
-
-;
- use Exception;
- use Eywa\Console\Shell;
- use Eywa\Exception\Kedavra;
- use Gettext\Generator\PoGenerator;
- use Gettext\Loader\PoLoader;
- use Gettext\Scanner\PhpScanner;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
-
- class CreateCatalogues extends Command
- {
- protected static $defaultName = "catalogues:generate";
-
-
- protected function configure():void
- {
- $this->setDescription('Create all catalogues');
- }
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- * @throws Kedavra
- * @throws Exception
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
-
- $io->title('Create localization catalog');
- $x = collect();
-
- foreach (config('i18n', 'locales') as $locale) {
- if ($this->generate($locale)) {
- $io->title(sprintf('Generating the %s cataloge', $locale));
- $io->success(sprintf('The %s catalog has been generated successfully', $locale));
- $x->push(true);
- } else {
- $io->warning(sprintf('The %s catalog already exist', $locale));
- $x->push(false);
- }
- }
- if ($x->ok()) {
- $io->success("All catalogs has been successfully generated");
- return 0;
- }
-
- $io->error('Catalogs already exist');
- return 1;
- }
-
- /**
- * @param string $locale
- * @return bool
- * @throws Exception
- *
- */
- public function generate(string $locale): bool
- {
- if (!is_dir('po')) {
- mkdir('po');
- }
- if (!is_dir("po/$locale")) {
- $view_base = files(base('app', 'Views', '*.php'));
- $view_prof = files(base('app', 'Views', '*', '*.php'));
-
- $x = array_merge($view_base, $view_prof);
-
- $files = collect($x)->join(' ');
-
- $app_name = strval(env('APP_NAME', 'eywa'));
-
- $app_version = strval(env('APP_VERSION', '1.0'));
-
- $translator_email = strval(env('TRANSLATOR_EMAIL', 'translator@free.fr'));
-
-
- return true;
- }
- return false;
- }
- }
-}
diff --git a/eywa/Console/Lang/UpdateCatalogues.php b/eywa/Console/Lang/UpdateCatalogues.php
deleted file mode 100755
index 574d48d..0000000
--- a/eywa/Console/Lang/UpdateCatalogues.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-
-
-namespace Eywa\Console\Lang {
-
-
- use Exception;
- use Eywa\Console\Shell;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
-
- class UpdateCatalogues extends Command
- {
- protected static $defaultName = "catalogues:refresh";
-
- protected function configure():void
- {
- $this->setDescription('Update all catalogues');
- }
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $x = collect();
- $io = new SymfonyStyle($input, $output);
-
- $io->title('Create localization catalog');
- foreach (config('i18n', 'locales') as $catalogue) {
- if ($this->update($catalogue)) {
- $io->error(sprintf('The %s catologue has been updated successfully', $catalogue));
- $x->push(true);
- } else {
- $io->error(sprintf('The %s catologue update has failed', $catalogue));
- $x->push(false);
- }
- }
-
- if ($x->ok()) {
- $io->success('All catalogs has been updated successfully');
- return 0;
- }
- $io->error('Errors has been encontred');
- return 1;
- }
-
- /**
- * @param string $locale
- * @return bool
- *
- *
- * @throws Exception
- */
- public function update(string $locale): bool
- {
- if (is_dir("po/$locale")) {
- $view_base = files(base('app', 'Views', '*.php'));
- $view_prof = files(base('app', 'Views', '*', '*.php'));
-
- $x = array_merge($view_base, $view_prof);
-
- $files = collect($x)->join(' ');
-
- $app_name = strval(env('APP_NAME', 'eywa'));
- $po = base('po', $locale, 'LC_MESSAGES', 'messages.po');
- $pot = base('po', "$app_name.pot");
- $app_version = strval(env('APP_VERSION', '1.0'));
- $translator_email = strval(env('TRANSLATOR_EMAIL', 'translator@free.fr'));
-
- if ((new Shell("xgettext --keyword=@trans --language=PHP --add-comments --msgid-bugs-address=$translator_email --package-version=$app_version --package-name=$app_name --sort-output -o $pot $files"))->run() && (new Shell("msgmerge --update $po $pot"))->run()) {
- return true;
- }
-
- return false;
- }
- return false;
- }
- }
-}
diff --git a/eywa/Console/Mode/DevMode.php b/eywa/Console/Mode/DevMode.php
index 53bcfeb..b0fc256 100755
--- a/eywa/Console/Mode/DevMode.php
+++ b/eywa/Console/Mode/DevMode.php
@@ -13,7 +13,7 @@ namespace Eywa\Console\Mode {
{
protected static $defaultName = 'app:dev';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Put the application in development mode');
}
diff --git a/eywa/Console/Mode/Maintenance.php b/eywa/Console/Mode/Maintenance.php
index ed2fa24..67e99a9 100755
--- a/eywa/Console/Mode/Maintenance.php
+++ b/eywa/Console/Mode/Maintenance.php
@@ -1,41 +1,44 @@
<?php
- namespace Eywa\Console\Mode
- {
- use Eywa\Exception\Kedavra;
- use Eywa\File\File;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
+namespace Eywa\Console\Mode
+{
+ use Eywa\Exception\Kedavra;
+ use Eywa\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+ use Symfony\Component\Console\Style\SymfonyStyle;
- class Maintenance extends Command
- {
- protected static $defaultName = 'app:down';
+ class Maintenance extends Command
+ {
+ protected static $defaultName = 'app:down';
- protected function configure():void
- {
- $this->setDescription('Put the application in maintenance mode');
- }
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int|void
- * @throws Kedavra
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input, $output);
+ protected function configure(): void
+ {
+ $this->setDescription('Put the application in maintenance mode');
+ }
- $io->title('Enabling the maintenance mode');
- if ((new File('config/mode.yaml', EMPTY_AND_WRITE_FILE_MODE))->write("mode: down\nconnexion: prod")->flush()) {
- $io->success('The application is now in maintenance mode');
- return 0;
- }
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int|void
+ * @throws Kedavra
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
- $io->error('Checkout mode has failed');
- return 1;
+ $io->title('Enabling the maintenance mode');
+ if (
+ (new File('config/mode.yaml', EMPTY_AND_WRITE_FILE_MODE))
+ ->write("mode: down\nconnexion: prod")->flush()
+ ) {
+ $io->success('The application is now in maintenance mode');
+ return 0;
}
+
+ $io->error('Checkout mode has failed');
+ return 1;
}
}
+}
diff --git a/eywa/Console/Mode/ProductionMode.php b/eywa/Console/Mode/ProductionMode.php
index fc54ccb..0265c16 100755
--- a/eywa/Console/Mode/ProductionMode.php
+++ b/eywa/Console/Mode/ProductionMode.php
@@ -3,6 +3,7 @@
namespace Eywa\Console\Mode {
+ use Eywa\Exception\Kedavra;
use Eywa\File\File;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@@ -13,18 +14,28 @@ namespace Eywa\Console\Mode {
{
protected static $defaultName = 'app:prod';
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Put the application in production mode');
}
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return int
+ * @throws Kedavra
+ */
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Enabling the production mode');
- if ((new File('config/mode.yaml', EMPTY_AND_WRITE_FILE_MODE))->write("mode: up\nconnexion: prod")->flush()) {
+ if (
+ (new File('config/mode.yaml', EMPTY_AND_WRITE_FILE_MODE))
+ ->write("mode: up\nconnexion: prod")
+ ->flush()
+ ) {
$io->success('The application is now in production mode');
return 0;
}
diff --git a/eywa/Console/Records/Records.php b/eywa/Console/Records/Records.php
index e74b7ee..3c163c4 100644
--- a/eywa/Console/Records/Records.php
+++ b/eywa/Console/Records/Records.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console\Records {
@@ -17,9 +16,11 @@ namespace Eywa\Console\Records {
protected static $defaultName = 'record:show';
- public function configure():void
+ public function configure(): void
{
- $this->setDescription('List the content of a table')->addArgument('table', InputArgument::REQUIRED, 'The table name')->addArgument('env', InputArgument::REQUIRED, 'The env mode');
+ $this->setDescription('List the content of a table')
+ ->addArgument('table', InputArgument::REQUIRED, 'The table name')
+ ->addArgument('env', InputArgument::REQUIRED, 'The env mode');
}
/**
@@ -28,7 +29,7 @@ namespace Eywa\Console\Records {
* @return int
* @throws Kedavra
*/
- public function execute(InputInterface $input, OutputInterface $output):int
+ public function execute(InputInterface $input, OutputInterface $output): int
{
$env = strval($input->getArgument('env'));
$table = strval($input->getArgument('table'));
diff --git a/eywa/Console/Routes/AddRoute.php b/eywa/Console/Routes/AddRoute.php
index c6008d6..329d2c9 100755
--- a/eywa/Console/Routes/AddRoute.php
+++ b/eywa/Console/Routes/AddRoute.php
@@ -3,9 +3,7 @@
namespace Eywa\Console\Routes {
- use Eywa\Collection\Collect;
use Eywa\Database\Query\Sql;
- use Eywa\Database\Table\Table;
use Eywa\Exception\Kedavra;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@@ -17,11 +15,7 @@ namespace Eywa\Console\Routes {
{
protected static $defaultName = "route:add";
- private Collect $routes;
-
- private Collect $entry;
-
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Create a new route');
}
@@ -38,74 +32,110 @@ namespace Eywa\Console\Routes {
{
$io = new SymfonyStyle($input, $output);
- $this->routes = collect();
-
- $this->entry = collect();
+ $entry = collect();
$methods = collect(METHOD_SUPPORTED)->for('strtolower')->all();
do {
$sql = new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes');
do {
- $this->entry->put('name', $io->askQuestion((new Question('What name should be used for represent the new route url ?'))));
- } while (not_def($this->entry->get('name')) || def($sql->where('name', EQUAL, $this->entry->get('name'))->get()));
+ $entry->put('name', $io->askQuestion(
+ (new Question('What name should be used for represent the new route url ?'))
+ ));
+ } while (not_def($entry->get('name')) || def($sql->where('name', EQUAL, $entry->get('name'))->get()));
do {
- $route = $this->entry->get('name');
- $this->entry->put('method', strtoupper($io->askQuestion((new Question(sprintf('What method should be used for the new %s route ?', $route), GET))->setAutocompleterValues($methods))));
- } while (not_in(METHOD_SUPPORTED, $this->entry->get('method')));
+ $route = $entry->get('name');
+ $entry->put('method', strtoupper($io->askQuestion(
+ (new Question(
+ sprintf('What method should be used for the new %s route ?', $route),
+ GET
+ ))->setAutocompleterValues($methods)
+ )));
+ } while (not_in(METHOD_SUPPORTED, $entry->get('method')));
do {
- $route = $this->entry->get('name');
- $this->entry->put('url', $io->askQuestion((new Question(sprintf('What url should be used by the %s route for accessing the controller ?', $route)))));
- if (is_null($this->entry->get('url'))) {
- $this->entry->put('url', '');
+ $route = $entry->get('name');
+ $entry->put('url', $io->askQuestion(
+ (new Question(
+ sprintf(
+ 'What url should be used by the %s route for accessing the controller ?',
+ $route
+ )
+ ))
+ ));
+ if (is_null($entry->get('url'))) {
+ $entry->put('url', '');
}
- } while (not_def($this->entry->get('url') || def($sql->where('url', EQUAL, $this->entry->get('url'))->get())));
+ } while (not_def($entry->get('url') || def($sql->where('url', EQUAL, $entry->get('url'))->get())));
do {
- $this->entry->put('directory', ucfirst($io->askQuestion((new Question('Place the controller in a special directory ?', 'Controllers'))->setAutocompleterValues(controllers_directory()))));
- } while (is_null($this->entry->get('directory')));
+ $entry->put('directory', ucfirst($io->askQuestion(
+ (new Question('Place the controller in a special directory ?', 'Controllers'))
+ ->setAutocompleterValues(controllers_directory())
+ )));
+ } while (is_null($entry->get('directory')));
do {
- $route = $this->entry->get('name');
- $this->entry->put('controller', $io->askQuestion((new Question(sprintf('What controller name should be called by the %s route ?', $route)))->setAutocompleterValues(controllers($this->entry->get('directory')))));
- } while (is_null($this->entry->get('controller')));
-
- if ($this->entry->get('directory') !== 'Controllers') {
- $class = '\App\Controllers\\' . $this->entry->get('directory') . '\\' .$this->entry->get('controller');
+ $route = $entry->get('name');
+ $entry->put('controller', $io->askQuestion(
+ (new Question(sprintf('What controller name should be called by the %s route ?', $route)))
+ ->setAutocompleterValues(controllers($entry->get('directory')))
+ ));
+ } while (is_null($entry->get('controller')));
+
+ if ($entry->get('directory') !== 'Controllers') {
+ $class = '\App\Controllers\\' . $entry->get('directory') . '\\' . $entry->get('controller');
} else {
- $class = '\App\Controllers\\' .$this->entry->get('controller');
+ $class = '\App\Controllers\\' . $entry->get('controller');
}
do {
if (class_exists($class)) {
- $class = new $class;
-
- $controller = $this->entry->get('controller');
- $route = $this->entry->get('name');
-
- $this->entry->put('action', $io->askQuestion((new Question(sprintf('What action in the %s controller should be executed by the %s route ?', $controller, $route)))->setAutocompleterValues(get_class_methods($class))));
+ $class = new $class();
+
+ $controller = $entry->get('controller');
+ $route = $entry->get('name');
+
+ $entry->put('action', $io->askQuestion(
+ (new Question(
+ sprintf(
+ 'What action in the %s controller should be executed by the %s route ?',
+ $controller,
+ $route
+ )
+ ))
+ ->setAutocompleterValues(get_class_methods($class))
+ ));
} else {
- $controller = $this->entry->get('controller');
- $route = $this->entry->get('name');
-
- $this->entry->put('action', $io->askQuestion((new Question(sprintf('What action in the %s controller should be executed by the %s route ?', $controller, $route)))));
+ $controller = $entry->get('controller');
+ $route = $entry->get('name');
+
+ $entry->put('action', $io->askQuestion(
+ (new Question(sprintf(
+ 'What action in the %s controller should be executed by the %s route ?',
+ $controller,
+ $route
+ )))
+ ));
}
- } while (def($sql->where('action', EQUAL, $this->entry->get('action'))->get()) || not_def($this->entry->get('action')));
+ } while (
+ def($sql->where('action', EQUAL, $entry->get('action'))->get())
+ || not_def($entry->get('action'))
+ );
- $this->entry->put('created_at', now()->toDateTimeString())->put('updated_at', now()->toDateTimeString());
+ $entry->put('created_at', now()->toDateTimeString())->put('updated_at', now()->toDateTimeString());
- if ($sql->create($this->entry->all())) {
- $route = $this->entry->get('name');
+ if ($sql->create($entry->all())) {
+ $route = $entry->get('name');
$io->success(sprintf('The %s route has been created successfully', $route));
} else {
$io->error(sprintf('Failed to create the %s route', $route));
return 1;
}
- $this->entry->clear();
+ $entry->clear();
} while ($io->confirm('Do you want continue to create new routes ? ', true));
return 0;
}
diff --git a/eywa/Console/Routes/FindRoute.php b/eywa/Console/Routes/FindRoute.php
index 87eb8ce..9530f4a 100755
--- a/eywa/Console/Routes/FindRoute.php
+++ b/eywa/Console/Routes/FindRoute.php
@@ -19,12 +19,6 @@ namespace Eywa\Console\Routes {
/**
*
- * The search value
- *
- */
- private string $search ='';
- /**
- *
*/
private Sql $sql;
@@ -43,7 +37,7 @@ namespace Eywa\Console\Routes {
$this->sql = (new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'));
}
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Find a route');
}
@@ -57,13 +51,14 @@ namespace Eywa\Console\Routes {
* @return int
* @throws Kedavra
*/
- public function interact(InputInterface $input, OutputInterface $output):int
+ public function interact(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
do {
do {
- $this->search = $io->askQuestion((new Question('Type your search '))->setAutocompleterValues($this->all()));
- } while (not_def($this->search));
+ $search =
+ $io->askQuestion((new Question('Type your search '))->setAutocompleterValues($this->all()));
+ } while (not_def($search));
$table = new Table($output);
$io = new SymfonyStyle($input, $output);
@@ -74,7 +69,7 @@ namespace Eywa\Console\Routes {
->setHeaders(['id', 'method', 'name','url','controller','action','namespace','created','updated'])
->setRows(
- $this->sql->like($this->search)->to(PDO::FETCH_ASSOC)
+ $this->sql->like($search)->to(PDO::FETCH_ASSOC)
)
;
$table->render();
@@ -150,7 +145,7 @@ namespace Eywa\Console\Routes {
* @return array<string>
* @throws Kedavra
*/
- private function action():array
+ private function action(): array
{
$x = collect();
@@ -165,9 +160,14 @@ namespace Eywa\Console\Routes {
* @return array<string>
* @throws Kedavra
*/
- private function all():array
+ private function all(): array
{
- return collect()->merge(collect(METHOD_SUPPORTED)->for('strtolower')->all())->merge($this->name())->merge($this->url())->merge($this->action())->merge($this->controller())->all();
+ return collect()
+ ->merge(collect(METHOD_SUPPORTED)->for('strtolower')->all())
+ ->merge($this->name())->merge($this->url())
+ ->merge($this->action())
+ ->merge($this->controller())
+ ->all();
}
}
}
diff --git a/eywa/Console/Routes/ListRoute.php b/eywa/Console/Routes/ListRoute.php
index 2d1a54a..456d2b1 100755
--- a/eywa/Console/Routes/ListRoute.php
+++ b/eywa/Console/Routes/ListRoute.php
@@ -18,7 +18,7 @@ namespace Eywa\Console\Routes {
protected static $defaultName = "route:list";
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('List all routes');
}
diff --git a/eywa/Console/Routes/RemoveRoute.php b/eywa/Console/Routes/RemoveRoute.php
index c6364c8..9665fda 100755
--- a/eywa/Console/Routes/RemoveRoute.php
+++ b/eywa/Console/Routes/RemoveRoute.php
@@ -34,15 +34,8 @@ namespace Eywa\Console\Routes {
$this->sql = (new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'));
}
- /**
- *
- * The route name
- *
- */
- private string $route = '';
-
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Delete a route');
}
@@ -51,11 +44,15 @@ namespace Eywa\Console\Routes {
* @return array<string>
* @throws Kedavra
*/
- public function name():array
+ public function name(): array
{
- $names= collect();
+ $names = collect();
- foreach ((new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'))->only(['name'])->get() as $value) {
+ foreach (
+ (new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'))
+ ->only(['name'])
+ ->get() as $value
+ ) {
$names->push($value->name);
}
@@ -70,7 +67,7 @@ namespace Eywa\Console\Routes {
* @throws Kedavra
* @throws Exception
*/
- public function execute(InputInterface $input, OutputInterface $output):int
+ public function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
if (def($this->sql->get())) {
@@ -80,10 +77,13 @@ namespace Eywa\Console\Routes {
do {
$names = $this->name();
$default = strval(reset($names));
- $this->route = $io->askQuestion((new Question('Wath is the name of the route to delete', $default))->setAutocompleterValues($this->name()));
- } while (not_def($this->route) || not_def($this->sql->where('name', EQUAL, $this->route)->get()));
+ $route1 = $io->askQuestion(
+ (new Question('Wath is the name of the route to delete', $default))
+ ->setAutocompleterValues($this->name())
+ );
+ } while (not_def($route1) || not_def($this->sql->where('name', EQUAL, $route1)->get()));
- $route = collect($this->sql->where('name', EQUAL, $this->route)->get())->get(0);
+ $route = collect($this->sql->where('name', EQUAL, $route1)->get())->get(0);
if ($this->sql->where('name', EQUAL, $route->name)->delete()) {
$io->success(sprintf('The %s route has been deleted successfully', $route->name));
diff --git a/eywa/Console/Routes/UpdateRoute.php b/eywa/Console/Routes/UpdateRoute.php
index 9198504..cbb74d5 100755
--- a/eywa/Console/Routes/UpdateRoute.php
+++ b/eywa/Console/Routes/UpdateRoute.php
@@ -2,7 +2,6 @@
namespace Eywa\Console\Routes {
- use Eywa\Collection\Collect;
use Eywa\Database\Query\Sql;
use Eywa\Exception\Kedavra;
use Symfony\Component\Console\Command\Command;
@@ -15,22 +14,6 @@ namespace Eywa\Console\Routes {
{
protected static $defaultName = "route:update";
- /**
- *
- * The result asked
- *
- */
- private Collect $entry;
-
- /**
- *
- * The value to find
- *
- */
- private string $search = '';
- /**
- * @var Sql
- */
private Sql $sql;
@@ -47,7 +30,7 @@ namespace Eywa\Console\Routes {
$this->sql = (new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'));
}
- protected function configure():void
+ protected function configure(): void
{
$this->setDescription('Update a route');
}
@@ -56,9 +39,9 @@ namespace Eywa\Console\Routes {
* @return array<string>
* @throws Kedavra
*/
- public function name():array
+ public function name(): array
{
- $names= collect();
+ $names = collect();
foreach ($this->sql->get() as $value) {
$names->push($value->name);
@@ -79,67 +62,102 @@ namespace Eywa\Console\Routes {
public function interact(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
- $this->entry = collect();
+ $entry = collect();
if (def($this->sql->get())) {
do {
$this->sql = (new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'));
do {
- $this->search = $io->askQuestion((new Question('What is the name of the route to update ?', 'root'))->setAutocompleterValues($this->name()));
- } while (not_def($this->sql->where('name', EQUAL, $this->search)->get()));
+ $search = $io->askQuestion(
+ (new Question('What is the name of the route to update ?', 'root'))
+ ->setAutocompleterValues($this->name())
+ );
+ } while (not_def($this->sql->where('name', EQUAL, $search)->get()));
- $route = collect($this->sql->where('name', EQUAL, $this->search)->get())->get(0);
+ $route = collect($this->sql->where('name', EQUAL, $search)->get())->get(0);
do {
- $this->entry->put('name', $io->askQuestion((new Question('Change the route name ? ', $route->name))));
- } while (not_def($this->entry->get('name')) || def($this->sql->where('name', EQUAL, $this->entry->get('name'))->get()) && $this->entry->get('name') !== $route->name);
+ $entry->put('name', $io->askQuestion((new Question('Change the route name ?', $route->name))));
+ } while (
+ not_def($entry->get('name'))
+ || def($this->sql->where('name', EQUAL, $entry->get('name'))->get())
+ && $entry->get('name') !== $route->name
+ );
do {
- $this->entry->put('method', strtoupper($io->askQuestion((new Question('Change the route method ? ', $route->method)))));
- } while (not_def($this->entry->get('method')) || not_in(METHOD_SUPPORTED, $this->entry->get('method')));
+ $entry->put('method', strtoupper(
+ $io->askQuestion(
+ (new Question('Change the route method ?', $route->method))
+ )
+ ));
+ } while (not_def($entry->get('method')) || not_in(METHOD_SUPPORTED, $entry->get('method')));
do {
- $this->entry->put('url', $io->askQuestion((new Question('Change the route url ? ', $route->url))));
- } while (not_def($this->entry->get('url')) || def($this->sql->where('url', EQUAL, $this->entry->get('url'))->get()) && $this->entry->get('url') !== $route->url);
+ $entry->put('url', $io->askQuestion((new Question('Change the route url ?', $route->url))));
+ } while (
+ not_def($entry->get('url'))
+ || def($this->sql->where('url', EQUAL, $entry->get('url'))->get())
+ && $entry->get('url') !== $route->url
+ );
do {
- $this->entry->put('directory', $io->askQuestion((new Question('Change the route namespace ? ', $route->directory))->setAutocompleterValues(controllers_directory())));
- } while (not_def($this->entry->get('directory')));
+ $entry->put('directory', $io->askQuestion(
+ (new Question('Change the route namespace ?', $route->directory))
+ ->setAutocompleterValues(controllers_directory())
+ ));
+ } while (not_def($entry->get('directory')));
do {
- $this->entry->put('controller', $io->askQuestion((new Question(sprintf('Change the route controller ? '), $route->controller))->setAutocompleterValues(controllers($this->entry->get('directory')))));
- } while (is_null($this->entry->get('controller')));
+ $entry->put(
+ 'controller',
+ $io->askQuestion(
+ (new Question(sprintf('Change the route controller ?'), $route->controller))
+ ->setAutocompleterValues(
+ controllers($entry->get('directory'))
+ )
+ )
+ );
+ } while (is_null($entry->get('controller')));
do {
- if ($this->entry->get('directory') !== 'Controllers') {
- $class = '\App\Controllers\\' . $this->entry->get('directory') . '\\' .$this->entry->get('controller');
+ if ($entry->get('directory') !== 'Controllers') {
+ $class = '\App\Controllers\\' . $entry->get('directory') . '\\' . $entry->get('controller');
} else {
- $class = '\App\Controllers\\' .$this->entry->get('controller');
+ $class = '\App\Controllers\\' . $entry->get('controller');
}
if (class_exists($class)) {
- $class = new $class;
+ $class = new $class();
- $this->entry->put('action', $io->askQuestion((new Question('Change the route action ? ', $route->action))->setAutocompleterValues(get_class_methods($class))));
+ $entry->put('action', $io->askQuestion(
+ (new Question('Change the route action ?', $route->action))
+ ->setAutocompleterValues(get_class_methods($class))
+ ));
} else {
- $this->entry->put('action', $io->askQuestion((new Question('Change the route action ? ', $route->action))));
+ $entry->put('action', $io->askQuestion(
+ (new Question('Change the route action ?', $route->action))
+ ));
}
- } while (not_def($this->entry->get('action')) && not_def($this->sql->where('action', EQUAL, $this->entry->get('action'))->get()) && $route->action !== $this->entry->get('action'));
+ } while (
+ not_def($entry->get('action')) &&
+ not_def($this->sql->where('action', EQUAL, $entry->get('action'))->get()) &&
+ $route->action !== $entry->get('action')
+ );
- $this->entry->put('created_at', $route->created_at);
- $this->entry->put('updated_at', now()->toDateTimeString());
+ $entry->put('created_at', $route->created_at);
+ $entry->put('updated_at', now()->toDateTimeString());
- if ($this->sql->update(intval($route->id), $this->entry->all())) {
+ if ($this->sql->update(intval($route->id), $entry->all())) {
$io->success('The route has been updated successfully');
} else {
$io->error('The route has not been updated');
return 1;
}
- $this->entry->clear();
+ $entry->clear();
} while ($io->confirm('Continue to update routes ?', true));
return 0;
}
diff --git a/eywa/Console/Shell.php b/eywa/Console/Shell.php
index e8ebade..cbd580e 100755
--- a/eywa/Console/Shell.php
+++ b/eywa/Console/Shell.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Console;
use Traversable;
diff --git a/eywa/Database/Base/Base.php b/eywa/Database/Base/Base.php
index 44df2df..37b69c6 100755
--- a/eywa/Database/Base/Base.php
+++ b/eywa/Database/Base/Base.php
@@ -1,6 +1,5 @@
<?php
-
declare(strict_types=1);
namespace Eywa\Database\Base {
@@ -34,7 +33,15 @@ namespace Eywa\Database\Base {
if (equal($this->env, 'dev')) {
foreach ((new Table(development(), ''))->show() as $table) {
if (different($table, 'migrations')) {
- is_false((new Table(development(), $table))->truncate(), true, sprintf('The truncate task for the %s table has failed', $table));
+ is_false(
+ (new Table(development(), $table))
+ ->truncate(),
+ true,
+ sprintf(
+ 'The truncate task for the %s table has failed',
+ $table
+ )
+ );
}
}
return true;
@@ -43,7 +50,15 @@ namespace Eywa\Database\Base {
if (equal($this->env, 'prod')) {
foreach ((new Table(production(), ''))->show() as $table) {
if (different($table, 'migrations')) {
- is_false((new Table(production(), $table))->truncate(), true, sprintf('The truncate task for the %s table has failed', $table));
+ is_false(
+ (new Table(production(), $table))
+ ->truncate(),
+ true,
+ sprintf(
+ 'The truncate task for the %s table has failed',
+ $table
+ )
+ );
}
}
return true;
@@ -52,13 +67,29 @@ namespace Eywa\Database\Base {
if (equal($this->env, 'any')) {
foreach ((new Table(production(), ''))->show() as $table) {
if (different($table, 'migrations')) {
- is_false((new Table(production(), $table))->truncate(), true, sprintf('The truncate task for the %s table has failed', $table));
+ is_false(
+ (new Table(production(), $table))
+ ->truncate(),
+ true,
+ sprintf(
+ 'The truncate task for the %s table has failed',
+ $table
+ )
+ );
}
}
foreach ((new Table(development(), ''))->show() as $table) {
if (different($table, 'migrations')) {
- is_false((new Table(development(), $table))->truncate(), true, sprintf('The truncate task for the %s table has failed', $table));
+ is_false(
+ (new Table(development(), $table))
+ ->truncate(),
+ true,
+ sprintf(
+ 'The truncate task for the %s table has failed',
+ $table
+ )
+ );
}
}
return true;
diff --git a/eywa/Database/Connexion/Connect.php b/eywa/Database/Connexion/Connect.php
index 6dc28af..38d83ad 100755
--- a/eywa/Database/Connexion/Connect.php
+++ b/eywa/Database/Connexion/Connect.php
@@ -80,8 +80,13 @@ namespace Eywa\Database\Connexion {
* @inheritDoc
*
*/
- public function __construct(string $driver, string $base, string $username ='', string $password ='', string $host = LOCALHOST)
- {
+ public function __construct(
+ string $driver,
+ string $base,
+ string $username = '',
+ string $password = '',
+ string $host = LOCALHOST
+ ) {
$this->driver = $driver;
$this->base = $base;
$this->username = $username;
@@ -135,7 +140,7 @@ namespace Eywa\Database\Connexion {
$result = $this->pdo()->prepare($query);
foreach ($this->args as $k => $arg) {
- $result->bindParam($k +1, $arg);
+ $result->bindParam($k + 1, $arg);
}
$result->execute();
@@ -171,7 +176,7 @@ namespace Eywa\Database\Connexion {
* @return bool
* @throws Kedavra
*/
- public function create_database(string ...$bases): bool
+ public function createDatabase(string ...$bases): bool
{
$x = collect();
foreach ($bases as $base) {
@@ -186,7 +191,7 @@ namespace Eywa\Database\Connexion {
* @return bool
* @throws Kedavra
*/
- public function remove_database(string ...$bases): bool
+ public function removeDatabase(string ...$bases): bool
{
$x = collect();
if (in_array($this->driver(), [MYSQL,POSTGRESQL])) {
@@ -210,11 +215,13 @@ namespace Eywa\Database\Connexion {
* @throws Kedavra
*
*/
- public function remove_user(string $user): bool
+ public function removeUser(string $user): bool
{
$x = collect();
if (in_array($this->driver(), [MYSQL,POSTGRESQL])) {
- $this->mysql() ? $x->push($this->set("DROP USER IF EXISTS '$user'@'{$this->host}'")->execute()) : $x->push($this->set("DROP USER IF EXISTS $user")->execute());
+ $this->mysql()
+ ? $x->push($this->set("DROP USER IF EXISTS '$user'@'{$this->host}'")->execute())
+ : $x->push($this->set("DROP USER IF EXISTS $user")->execute());
}
return $x->ok();
}
@@ -226,13 +233,17 @@ namespace Eywa\Database\Connexion {
* @return bool
* @throws Kedavra
*/
- public function create_user(string $user, string $password, string $base): bool
+ public function createUser(string $user, string $password, string $base): bool
{
switch ($this->driver()) {
case MYSQL:
- return $this->set("CREATE USER IF NOT EXISTS '$user'@'localhost' IDENTIFIED BY '$password';")->set("GRANT ALL PRIVILEGES ON $base.* TO '$user'@'localhost';")->execute();
+ return $this->set("CREATE USER IF NOT EXISTS '$user'@'localhost' IDENTIFIED BY '$password';")
+ ->set("GRANT ALL PRIVILEGES ON $base.* TO '$user'@'localhost';")
+ ->execute();
case POSTGRESQL:
- return $this->set("CREATE USER $user WITH PASSWORD '$password' LOGIN;")->set("GRANT ALL PRIVILEGES ON DATABASE $base TO $user")->execute();
+ return $this->set("CREATE USER $user WITH PASSWORD '$password' LOGIN;")
+ ->set("GRANT ALL PRIVILEGES ON DATABASE $base TO $user")
+ ->execute();
default:
return false;
}
@@ -254,20 +265,6 @@ namespace Eywa\Database\Connexion {
}
/**
- *
- * Get the connexion infos
- *
- * @return string
- *
- */
- public function info(): string
- {
- return collect(get_object_vars($this))->del(['connexion','queries','args','options'])->each(function ($k, $v) {
- return "\$$k=$v;";
- })->join('');
- }
-
- /**
* @inheritDoc
*/
public function back(string $message): bool
@@ -381,7 +378,7 @@ namespace Eywa\Database\Connexion {
* @return bool
*
*/
- public function sqlite():bool
+ public function sqlite(): bool
{
return $this->driver() === SQLITE;
}
@@ -432,7 +429,13 @@ namespace Eywa\Database\Connexion {
*/
public function development(): Connect
{
- return new static(strval(env('DEVELOP_DB_DRIVER', 'mysql')),strval(env('DEVELOP_DB_NAME', 'ikran')),strval(env('DEVELOP_DB_USERNAME', 'ikran')),strval(env('DEVELOP_DB_PASSWORD', 'ikran')),strval(env('DEVELOP_DB_HOST', 'localhost')));
+ return new static(
+ strval(env('DEVELOP_DB_DRIVER', 'mysql')),
+ strval(env('DEVELOP_DB_NAME', 'ikran')),
+ strval(env('DEVELOP_DB_USERNAME', 'ikran')),
+ strval(env('DEVELOP_DB_PASSWORD', 'ikran')),
+ strval(env('DEVELOP_DB_HOST', 'localhost'))
+ );
}
/**
@@ -443,9 +446,45 @@ namespace Eywa\Database\Connexion {
{
if (is_null($this->connexion)) {
if (equal($this->driver, MYSQL)) {
- $this->connexion = def($this->base) ? new PDO(sprintf('mysql:host=%s;port=3306;dbname=%s;charset=UTF8', $this->host, $this->base), $this->username, $this->password) : new PDO(sprintf('mysql:host=%s;port=3306;charset=UTF8', $this->host), $this->username, $this->password);
+ $this->connexion = def($this->base)
+ ?
+ new PDO(
+ sprintf(
+ 'mysql:host=%s;port=3306;dbname=%s;charset=UTF8',
+ $this->host,
+ $this->base
+ ),
+ $this->username,
+ $this->password
+ )
+ :
+ new PDO(
+ sprintf(
+ 'mysql:host=%s;port=3306;charset=UTF8',
+ $this->host
+ ),
+ $this->username,
+ $this->password
+ );
} elseif (equal($this->driver, POSTGRESQL)) {
- $this->connexion = def($this->base) ? new PDO(sprintf('pgsql:host=%s;port=5432;dbname=%s;options=\'--client_encoding=UTF8\'', $this->host, $this->base), $this->username, $this->password) : new PDO(sprintf('pgsql:host=%s;port=5432;options=\'--client_encoding=UTF8\'', $this->host), $this->username, $this->password);
+ $this->connexion = def($this->base)
+ ? new PDO(
+ sprintf(
+ 'pgsql:host=%s;port=5432;dbname=%s;options=\'--client_encoding=UTF8\'',
+ $this->host,
+ $this->base
+ ),
+ $this->username,
+ $this->password
+ )
+ : new PDO(
+ sprintf(
+ 'pgsql:host=%s;port=5432;options=\'--client_encoding=UTF8\'',
+ $this->host
+ ),
+ $this->username,
+ $this->password
+ );
} else {
$this->connexion = new PDO(sprintf('sqlite:%s', $this->base), '', '');
}
diff --git a/eywa/Database/Connexion/Connexion.php b/eywa/Database/Connexion/Connexion.php
index 4db9f81..1fcd1c7 100755
--- a/eywa/Database/Connexion/Connexion.php
+++ b/eywa/Database/Connexion/Connexion.php
@@ -24,7 +24,13 @@ namespace Eywa\Database\Connexion {
*
* @throws Kedavra
*/
- public function __construct(string $driver, string $base, string $username ='', string $password ='', string $host = LOCALHOST);
+ public function __construct(
+ string $driver,
+ string $base,
+ string $username = '',
+ string $password = '',
+ string $host = LOCALHOST
+ );
/**
*
@@ -96,7 +102,7 @@ namespace Eywa\Database\Connexion {
* @throws Kedavra
*
*/
- public function fetch(string $class = 'stdClass', array $args = []) : array ;
+ public function fetch(string $class = 'stdClass', array $args = []): array;
/**
@@ -112,7 +118,7 @@ namespace Eywa\Database\Connexion {
* @throws Kedavra
*
*/
- public function get(int $style): array ;
+ public function get(int $style): array;
/**
*
@@ -227,6 +233,6 @@ namespace Eywa\Database\Connexion {
* @return Collect
*
*/
- public function sql(): Collect ;
+ public function sql(): Collect;
}
}
diff --git a/eywa/Database/Import/Import.php b/eywa/Database/Import/Import.php
index af0ef16..31522d0 100755
--- a/eywa/Database/Import/Import.php
+++ b/eywa/Database/Import/Import.php
@@ -2,7 +2,6 @@
declare(strict_types=1);
-
namespace Eywa\Database\Import {
@@ -39,7 +38,7 @@ namespace Eywa\Database\Import {
* @return bool
*
*/
- public function import() : bool
+ public function import(): bool
{
$password = $this->connect->password();
$username = $this->connect->username();
diff --git a/eywa/Database/Migration/CreateMigrationTable.php b/eywa/Database/Migration/CreateMigrationTable.php
index 847bfae..ab436b1 100755
--- a/eywa/Database/Migration/CreateMigrationTable.php
+++ b/eywa/Database/Migration/CreateMigrationTable.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Database\Migration {
@@ -19,7 +18,11 @@ namespace Eywa\Database\Migration {
*/
public function up(): bool
{
- return $this->add('id', 'primary')->add('version', 'string', 255)->add('migration', 'string', 255)->add('time', 'datetime')->create();
+ return $this->add('id', 'primary')
+ ->add('version', 'string', 255)
+ ->add('migration', 'string', 255)
+ ->add('time', 'datetime')
+ ->create();
}
/**
diff --git a/eywa/Database/Migration/Evolution.php b/eywa/Database/Migration/Evolution.php
index f0b3662..e14e753 100644
--- a/eywa/Database/Migration/Evolution.php
+++ b/eywa/Database/Migration/Evolution.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
namespace Eywa\Database\Migration {
@@ -11,7 +12,7 @@ namespace Eywa\Database\Migration {
class Evolution
{
- private string $from = '';
+ private string $from;
private Collect $columns;
@@ -19,7 +20,7 @@ namespace Eywa\Database\Migration {
private Table $table;
- private string $env = '';
+ private string $env;
/**
*
@@ -71,16 +72,16 @@ namespace Eywa\Database\Migration {
switch ($type) {
case 'string':
append($sql, "$column {$this->text()} ");
- break;
+ break;
case 'longtext':
append($sql, "$column {$this->longtext()} ");
- break;
+ break;
case 'datetime':
append($sql, "$column {$this->datetime()} ");
- break;
+ break;
default:
append($sql, "$column $type ");
- break;
+ break;
}
if ($size !== 0) {
@@ -221,7 +222,7 @@ namespace Eywa\Database\Migration {
*/
public function refresh(string $column, string $new_column_name): bool
{
- return $this->table->rename_column($column, $new_column_name);
+ return $this->table->renameColumn($column, $new_column_name);
}
/**
@@ -235,17 +236,32 @@ namespace Eywa\Database\Migration {
* @throws Kedavra
*
*/
- public function remove_foreign(array $columns): bool
+ public function removeForeign(array $columns): bool
{
$x = collect();
foreach ($columns as $column) {
switch ($this->connexion()->driver()) {
case MYSQL:
- $x->push($this->connexion()->set(sprintf('ALTER TABLE %s DROP FOREIGN KEY %s', $this->from, $column))->execute());
- break;
+ $x->push(
+ $this->connexion()->set(
+ sprintf(
+ 'ALTER TABLE %s DROP FOREIGN KEY %s',
+ $this->from,
+ $column
+ )
+ )
+ ->execute()
+ );
+ break;
case POSTGRESQL:
- $x->push($this->connexion()->set(sprintf('ALTER TABLE %s DROP CONSTRAINT %s', $this->from, $column))->execute());
- break;
+ $x->push($this->connexion()->set(
+ sprintf(
+ 'ALTER TABLE %s DROP CONSTRAINT %s',
+ $this->from,
+ $column
+ )
+ )->execute());
+ break;
default:
return false;
}
@@ -267,7 +283,7 @@ namespace Eywa\Database\Migration {
* @throws Kedavra
*
*/
- public function add(string $column, string $type, int $size = 0, array $constraints= []): Evolution
+ public function add(string $column, string $type, int $size = 0, array $constraints = []): Evolution
{
if (equal($type, 'primary')) {
return $this->primary($column);
@@ -292,8 +308,13 @@ namespace Eywa\Database\Migration {
* @return Evolution
*
*/
- public function foreign(string $column, string $reference, string $reference_column, string $on = '', string $do =''): Evolution
- {
+ public function foreign(
+ string $column,
+ string $reference,
+ string $reference_column,
+ string $on = '',
+ string $do = ''
+ ): Evolution {
$constraint = " FOREIGN KEY ($column) REFERENCES $reference($reference_column)";
if (def($on, $do)) {
@@ -320,17 +341,17 @@ namespace Eywa\Database\Migration {
$type = 'INT';
$constraints = ['PRIMARY KEY NOT NULL AUTO_INCREMENT'];
$this->columns->push(compact('column', 'type', 'size', 'constraints'));
- break;
+ break;
case POSTGRESQL:
$type = 'SERIAL';
$constraints = ['PRIMARY KEY'];
$this->columns->push(compact('column', 'type', 'size', 'constraints'));
- break;
+ break;
case SQLITE:
$type = 'INTEGER';
$constraints = ['PRIMARY KEY AUTOINCREMENT'];
$this->columns->push(compact('column', 'type', 'size', 'constraints'));
- break;
+ break;
}
return $this;
@@ -391,7 +412,7 @@ namespace Eywa\Database\Migration {
* @throws Kedavra
*
*/
- private function text():string
+ private function text(): string
{
switch ($this->connexion()->driver()) {
case MYSQL:
@@ -402,7 +423,6 @@ namespace Eywa\Database\Migration {
return 'text';
default:
return '';
-
}
}
}
diff --git a/eywa/Database/Migration/Migrate.php b/eywa/Database/Migration/Migrate.php
index 5f350c3..efc721e 100644
--- a/eywa/Database/Migration/Migrate.php
+++ b/eywa/Database/Migration/Migrate.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Database\Migration {
use Eywa\Database\Query\Sql;
@@ -62,7 +61,14 @@ namespace Eywa\Database\Migration {
if ($result->ok()) {
$io->success($up_success_message);
- self::sql('dev')->create(['version'=> $created_at,'migration'=> $migration,'time'=> now()->toDateTimeString()]);
+ self::sql('dev')
+ ->create(
+ [
+ 'version' => $created_at,
+ 'migration' => $migration,
+ 'time' => now()->toDateTimeString()
+ ]
+ );
} else {
self::sql('dev')->where('version', EQUAL, $date)->delete();
$io->error($up_error_message);
@@ -82,7 +88,13 @@ namespace Eywa\Database\Migration {
if ($result->ok()) {
$io->success($up_success_message);
- self::sql('prod')->create(['version'=> $created_at,'migration'=> $migration,'time'=> now()->toDateTimeString()]);
+ self::sql('prod')->create(
+ [
+ 'version' => $created_at,
+ 'migration' => $migration,
+ 'time' => now()->toDateTimeString()
+ ]
+ );
} else {
self::sql('prod')->where('version', EQUAL, $date)->delete();
$io->error($up_error_message);
@@ -116,7 +128,13 @@ namespace Eywa\Database\Migration {
if ($result->ok()) {
$io->success($up_success_message);
- self::sql('dev')->create(['version'=> $created_at,'migration'=> $migration,'time'=> now()->toDateTimeString()]);
+ self::sql('dev')->create(
+ [
+ 'version' => $created_at,
+ 'migration' => $migration,
+ 'time' => now()->toDateTimeString()
+ ]
+ );
} else {
self::sql('dev')->where('version', EQUAL, $date)->delete();
$io->error($up_error_message);
@@ -132,7 +150,13 @@ namespace Eywa\Database\Migration {
if ($result->ok()) {
$io->success($up_success_message);
- self::sql('prod')->create(['version'=> $created_at,'migration'=> $migration,'time'=> now()->toDateTimeString()]);
+ self::sql('prod')->create(
+ [
+ 'version' => $created_at,
+ 'migration' => $migration,
+ 'time' => now()->toDateTimeString()
+ ]
+ );
} else {
self::sql('prod')->where('version', EQUAL, $date)->delete();
$io->error($up_error_message);
@@ -155,7 +179,7 @@ namespace Eywa\Database\Migration {
* @throws Kedavra
*
*/
- public function rollback(SymfonyStyle $io):int
+ public function rollback(SymfonyStyle $io): int
{
if ($this->check('down')) {
$io->warning('Nothing to rollback');
@@ -172,13 +196,39 @@ namespace Eywa\Database\Migration {
$table = $x->getStaticPropertyValue('table');
- $down_success_message = str_replace('%s', $table, $x->getStaticPropertyValue('down_success_message'));
-
- $down_error_message = str_replace('%s', $table, $x->getStaticPropertyValue('down_error_message'));
-
- $down_title = str_replace('%s', $table, $x->getStaticPropertyValue('down_title'));
-
- $exist = self::sql('dev')->where('version', EQUAL, $date)->exist() && self::sql('prod')->where('version', EQUAL, $date)->exist();
+ $down_success_message =
+ str_replace(
+ '%s',
+ $table,
+ $x->getStaticPropertyValue('down_success_message')
+ );
+
+ $down_error_message = str_replace(
+ '%s',
+ $table,
+ $x->getStaticPropertyValue('down_error_message')
+ );
+
+ $down_title = str_replace(
+ '%s',
+ $table,
+ $x->getStaticPropertyValue('down_title')
+ );
+
+ $exist = self::sql('dev')
+ ->where(
+ 'version',
+ EQUAL,
+ $date
+ )
+ ->exist() &&
+ self::sql('prod')
+ ->where(
+ 'version',
+ EQUAL,
+ $date
+ )
+ ->exist();
if ($exist) {
@@ -268,7 +318,7 @@ namespace Eywa\Database\Migration {
$item = collect(explode('.', $item))->first();
- $class = '\Evolution\Migrations\\' .$item;
+ $class = '\Evolution\Migrations\\' . $item;
$x[$class] = (new ReflectionClass($class))->getStaticPropertyValue('created_at');
}
@@ -285,12 +335,25 @@ namespace Eywa\Database\Migration {
* @throws Kedavra
* @throws ReflectionException
*/
- private function check(string $mode ='up'): bool
+ private function check(string $mode = 'up'): bool
{
if (equal($mode, 'up')) {
$return = collect();
foreach (self::list('up') as $class => $date) {
- $return->push(self::sql('dev')->where('version', EQUAL, $date)->exist() && self::sql('prod')->where('version', EQUAL, $date)->exist());
+ $return->push(self::sql('dev')
+ ->where(
+ 'version',
+ EQUAL,
+ $date
+ )
+ ->exist() &&
+ self::sql('prod')
+ ->where(
+ 'version',
+ EQUAL,
+ $date
+ )
+ ->exist());
}
return $return->ok();
}
diff --git a/eywa/Database/Migration/Migration.php b/eywa/Database/Migration/Migration.php
index 1f66642..dad8255 100755
--- a/eywa/Database/Migration/Migration.php
+++ b/eywa/Database/Migration/Migration.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Database\Migration {
use Eywa\Exception\Kedavra;
@@ -229,9 +228,9 @@ namespace Eywa\Database\Migration {
* @throws Kedavra
*
*/
- public function remove_foreign(array $columns): bool
+ public function removeForeign(array $columns): bool
{
- return $this->db->remove_foreign($columns);
+ return $this->db->removeForeign($columns);
}
/**
@@ -267,8 +266,13 @@ namespace Eywa\Database\Migration {
* @return Evolution
*
*/
- public function foreign(string $column, string $reference, string $reference_column, string $on = '', string $do = ''): Evolution
- {
+ public function foreign(
+ string $column,
+ string $reference,
+ string $reference_column,
+ string $on = '',
+ string $do = ''
+ ): Evolution {
return $this->db->foreign($column, $reference, $reference_column, $on, $do);
}
}
diff --git a/eywa/Database/Model/Interact.php b/eywa/Database/Model/Interact.php
index c10c40c..1d9a39d 100644
--- a/eywa/Database/Model/Interact.php
+++ b/eywa/Database/Model/Interact.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Database\Model {
diff --git a/eywa/Database/Model/Model.php b/eywa/Database/Model/Model.php
index d72a025..5bdd90f 100755
--- a/eywa/Database/Model/Model.php
+++ b/eywa/Database/Model/Model.php
@@ -15,6 +15,17 @@ namespace Eywa\Database\Model {
protected static int $limit = 20;
+ /**
+ *
+ * Get and instance of the model
+ *
+ * @return Model
+ *
+ */
+ public function instance(): Model
+ {
+ return $this;
+ }
/**
* @inheritDoc
diff --git a/eywa/Database/Query/Records.php b/eywa/Database/Query/Records.php
index 22a0dde..7a98e2e 100644
--- a/eywa/Database/Query/Records.php
+++ b/eywa/Database/Query/Records.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Database\Query {
@@ -35,7 +34,7 @@ namespace Eywa\Database\Query {
*
*
*/
- public function take(int $limit, int $offset =0): self;
+ public function take(int $limit, int $offset = 0): self;
/**
*
@@ -65,7 +64,14 @@ namespace Eywa\Database\Query {
* @throws Kedavra
*
*/
- public function join(string $type, string $condition, string $first_table, string $second_table, string $first_param, string $second_param): self;
+ public function join(
+ string $type,
+ string $condition,
+ string $first_table,
+ string $second_table,
+ string $first_param,
+ string $second_param
+ ): self;
/**
*
@@ -82,7 +88,13 @@ namespace Eywa\Database\Query {
* @throws Kedavra
*
*/
- public function union(string $type, string $first_table, string $second_table, string $first_column, string $second_column): self;
+ public function union(
+ string $type,
+ string $first_table,
+ string $second_table,
+ string $first_column,
+ string $second_column
+ ): self;
/**
*
@@ -199,7 +211,7 @@ namespace Eywa\Database\Query {
* @return string
*
*/
- public function sql():string;
+ public function sql(): string;
/**
*
@@ -210,7 +222,7 @@ namespace Eywa\Database\Query {
* @throws Kedavra
*
*/
- public function primary():string;
+ public function primary(): string;
/**
*
@@ -219,7 +231,7 @@ namespace Eywa\Database\Query {
* @return string
*
*/
- public function pagination():string;
+ public function pagination(): string;
/**
*
@@ -262,7 +274,7 @@ namespace Eywa\Database\Query {
* @throws Kedavra
*
*/
- public function columns():array;
+ public function columns(): array;
/**
*
* Execute the query
@@ -323,7 +335,7 @@ namespace Eywa\Database\Query {
* @throws Kedavra
*
*/
- public function sum():int;
+ public function sum(): int;
/**
*
@@ -332,6 +344,6 @@ namespace Eywa\Database\Query {
* @throws Kedavra
*
*/
- public function connexion():Connect;
+ public function connexion(): Connect;
}
}
diff --git a/eywa/Database/Query/Sql.php b/eywa/Database/Query/Sql.php
index 59e563c..e36d3e4 100755
--- a/eywa/Database/Query/Sql.php
+++ b/eywa/Database/Query/Sql.php
@@ -12,14 +12,14 @@ namespace Eywa\Database\Query {
class Sql implements Records
{
- const VALID_OPERATORS = [ EQUAL,DIFFERENT,SUPERIOR,INFERIOR,INFERIOR_OR_EQUAL,SUPERIOR_OR_EQUAL ];
+ protected const VALID_OPERATORS = [ EQUAL,DIFFERENT,SUPERIOR,INFERIOR,INFERIOR_OR_EQUAL,SUPERIOR_OR_EQUAL ];
/**
*
* The name of the table
*
*/
- private string $table ='';
+ private string $table;
/**
*
@@ -75,7 +75,7 @@ namespace Eywa\Database\Query {
* The or clause
*
*/
- private string $or ='';
+ private string $or = '';
/**
*
@@ -88,14 +88,14 @@ namespace Eywa\Database\Query {
* The pagination
*
*/
- private string $pagination ='';
+ private string $pagination = '';
/**
*
* The html code
*
*/
- private string $records ='';
- private string $from = '';
+ private string $records = '';
+ private string $from;
/**
@@ -113,7 +113,17 @@ namespace Eywa\Database\Query {
*/
public function take(int $limit, int $offset = 0): Sql
{
- $this->limit = $this->connexion()->mysql() ? sprintf('LIMIT %d,%d', $offset, $limit) : sprintf('LIMIT %d OFFSET %d', $limit, $offset);
+ $this->limit = $this->connexion()->mysql()
+ ? sprintf(
+ 'LIMIT %d,%d',
+ $offset,
+ $limit
+ )
+ : sprintf(
+ 'LIMIT %d OFFSET %d',
+ $limit,
+ $offset
+ );
return $this;
}
@@ -131,11 +141,43 @@ namespace Eywa\Database\Query {
/**
* @inheritDoc
*/
- public function join(string $type, string $condition, string $first_table, string $second_table, string $first_param, string $second_param): Sql
- {
- not_in([LEFT_JOIN,RIGHT_JOIN,CROSS_JOIN,NATURAL_JOIN,INNER_JOIN,FULL_JOIN], $type, true, 'The type is invalid');
-
- append($this->join, sprintf('SELECT %s FROM %s %s %s ON %s.%s %s %s.%s ', $this->columns, $first_table, $type, $second_table, $first_table, $first_param, $condition, $second_table, $second_param));
+ public function join(
+ string $type,
+ string $condition,
+ string $first_table,
+ string $second_table,
+ string $first_param,
+ string $second_param
+ ): Sql {
+ not_in(
+ [
+ LEFT_JOIN,
+ RIGHT_JOIN,
+ CROSS_JOIN,
+ NATURAL_JOIN,
+ INNER_JOIN,
+ FULL_JOIN
+ ],
+ $type,
+ true,
+ 'The type is invalid'
+ );
+
+ append(
+ $this->join,
+ sprintf(
+ 'SELECT %s FROM %s %s %s ON %s.%s %s %s.%s ',
+ $this->columns,
+ $first_table,
+ $type,
+ $second_table,
+ $first_table,
+ $first_param,
+ $condition,
+ $second_table,
+ $second_param
+ )
+ );
return $this;
}
@@ -143,14 +185,32 @@ namespace Eywa\Database\Query {
/**
* @inheritDoc
*/
- public function union(string $type, string $first_table, string $second_table, string $first_column, string $second_column): Sql
- {
+ public function union(
+ string $type,
+ string $first_table,
+ string $second_table,
+ string $first_column,
+ string $second_column
+ ): Sql {
not_in([UNION,UNION_ALL], $type, true, 'The type is not valid');
if (not_def($first_column, $second_column)) {
- append($this->union, sprintf('SELECT * FROM %s %s SELECT * FROM %s ', $first_table, $type, $second_table));
+ append(
+ $this->union,
+ sprintf('SELECT * FROM %s %s SELECT * FROM %s ', $first_table, $type, $second_table)
+ );
} else {
- append($this->union, sprintf('SELECT %s FROM %s %s SELECT %s FROM %s ', $first_column, $first_table, $type, $second_column, $second_table));
+ append(
+ $this->union,
+ sprintf(
+ 'SELECT %s FROM %s %s SELECT %s FROM %s',
+ $first_column,
+ $first_table,
+ $type,
+ $second_column,
+ $second_table
+ )
+ );
}
return $this;
@@ -164,9 +224,25 @@ namespace Eywa\Database\Query {
not_in(self::VALID_OPERATORS, $condition, true, 'The used condition operator is not valid');
if (is_string($expected)) {
- append($this->or, sprintf('OR %s %s %s ', $column, html_entity_decode($condition), $this->connexion()->secure($expected)));
+ append(
+ $this->or,
+ sprintf(
+ 'OR %s %s %s ',
+ $column,
+ html_entity_decode($condition),
+ $this->connexion()->secure($expected)
+ )
+ );
} else {
- append($this->or, sprintf('OR %s %s %d ', $column, html_entity_decode($condition), $expected));
+ append(
+ $this->or,
+ sprintf(
+ 'OR %s %s %d ',
+ $column,
+ html_entity_decode($condition),
+ $expected
+ )
+ );
}
return $this;
@@ -180,9 +256,25 @@ namespace Eywa\Database\Query {
not_in(self::VALID_OPERATORS, $condition, true, 'The used condition operator is not valid');
if (is_string($expected)) {
- append($this->and, sprintf('AND %s %s %s ', $column, html_entity_decode($condition), $this->connexion()->secure($expected)));
+ append(
+ $this->and,
+ sprintf(
+ 'AND %s %s %s ',
+ $column,
+ html_entity_decode($condition),
+ $this->connexion()->secure($expected)
+ )
+ );
} else {
- append($this->and, sprintf('AND %s %s %d ', $column, html_entity_decode($condition), $expected));
+ append(
+ $this->and,
+ sprintf(
+ 'AND %s %s %d ',
+ $column,
+ html_entity_decode($condition),
+ $expected
+ )
+ );
}
return $this;
@@ -215,7 +307,21 @@ namespace Eywa\Database\Query {
{
not_in(self::VALID_OPERATORS, $condition, true, 'The used condition operator is not valid');
- $this->where = is_numeric($expected) ? sprintf('WHERE %s %s %d', $column, html_entity_decode($condition), $expected) : sprintf('WHERE %s %s %s', $column, html_entity_decode($condition), $this->connexion()->secure($expected));
+ $this->where = is_numeric($expected)
+ ?
+ sprintf(
+ 'WHERE %s %s %d',
+ $column,
+ html_entity_decode($condition),
+ $expected
+ )
+ :
+ sprintf(
+ 'WHERE %s %s %s',
+ $column,
+ html_entity_decode($condition),
+ $this->connexion()->secure($expected)
+ );
return $this;
}
@@ -284,7 +390,16 @@ namespace Eywa\Database\Query {
$bool = collect();
foreach ($this->get() as $record) {
- $bool->push($this->connexion()->set(sprintf('DELETE FROM %s WHERE %s = %d', $this->table, $id, $record->$id))->execute());
+ $bool->push(
+ $this->connexion()->set(
+ sprintf(
+ 'DELETE FROM %s WHERE %s = %d',
+ $this->table,
+ $id,
+ $record->$id
+ )
+ )->execute()
+ );
}
return $bool->ok();
@@ -301,9 +416,9 @@ namespace Eywa\Database\Query {
$table = $this->table;
- foreach ($values as $k => $value) {
+ foreach ($values as $k => $value) {
if (different($k, $primary)) {
- $columns->push("$k =" .$this->connexion()->secure($value));
+ $columns->push("$k =" . $this->connexion()->secure($value));
}
}
@@ -376,19 +491,41 @@ namespace Eywa\Database\Query {
{
switch ($this->connexion()->driver()) {
case MYSQL:
- return strval(collect($this->connexion()->set("show columns from {$this->table} where `Key` = 'PRI';")->get(COLUMNS))->first());
+ return strval(collect($this->connexion()
+ ->set("show columns from {$this->table} where `Key` = 'PRI';")->get(COLUMNS))->first());
case POSTGRESQL:
- return strval(collect($this->connexion()->set("select column_name FROM information_schema.key_column_usage WHERE table_name = '{$this->table}' and constraint_name ='{$this->table}_pkey';")->get(PDO::FETCH_COLUMN))->first());
+ return strval(
+ collect($this->connexion()
+ ->set(
+ sprintf(
+ 'select column_name
+ FROM information_schema.key_column_usage
+ WHERE table_name = \'%s\'
+ and constraint_name =\'%s_pkey\'',
+ $this->table,
+ $this->table
+ )
+ )->get(PDO::FETCH_COLUMN))->first()
+ );
case SQLITE:
foreach ($this->connexion()->set("PRAGMA table_info({$this->table})")->get(OBJECTS) as $value) {
if ($value->pk) {
return strval($value->name);
}
}
- break;
+ break;
case SQL_SERVER:
- return strval(collect($this->connexion()->set("SELECT COLUMN_NAME , CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = '{$this->table}';")->get(COLUMNS))->first());
-
+ return strval(
+ collect($this->connexion()
+ ->set(
+ sprintf(
+ 'SELECT COLUMN_NAME, CONSTRAINT_NAME
+ FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
+ WHERE TABLE_NAME = \'%s\';',
+ $this->table
+ )
+ )->get(COLUMNS))->first()
+ );
}
throw new Kedavra('We have not found a primary key');
}
@@ -402,14 +539,32 @@ namespace Eywa\Database\Query {
switch ($this->connexion()->driver()) {
case MYSQL:
- return $this->connexion()->set("SHOW FULL COLUMNS FROM {$this->table}")->get(COLUMNS);
+ return $this->connexion()
+ ->set(
+ sprintf(
+ 'SHOW FULL COLUMNS FROM %s',
+ $this->table
+ )
+ )->get(COLUMNS);
case POSTGRESQL:
- return $this->connexion()->set("SELECT column_name FROM information_schema.columns WHERE table_name ='{$this->table}'")->get(COLUMNS);
+ return $this->connexion()
+ ->set(
+ sprintf(
+ 'SELECT column_name
+ FROM information_schema.columns
+ WHERE table_name =\'%s\'',
+ $this->table
+ )
+ )->get(COLUMNS);
case SQLITE:
$x = function ($x) {
return $x->name ;
};
- return collect($this->connexion()->set("PRAGMA table_info({$this->table})")->get(OBJECTS))->for($x)->all();
+ return collect($this->connexion()
+ ->set(sprintf(
+ 'PRAGMA table_info(%s)',
+ $this->table
+ ))->get(OBJECTS))->for($x)->all();
default:
return $fields->all();
}
@@ -422,7 +577,8 @@ namespace Eywa\Database\Query {
{
$this->pagination = (new Pagination($current_page, $limit, $this->sum()))->paginate();
- $this->records = collect($this->take($limit, (($current_page) - 1) * $limit)->by($this->primary())->get())->for($callback)->join('');
+ $this->records = collect($this->take($limit, (($current_page) - 1) * $limit)->by($this->primary())->get())
+ ->for($callback)->join('');
return $this;
}
@@ -455,7 +611,7 @@ namespace Eywa\Database\Query {
/**
* @inheritDoc
*/
- public function sum():int
+ public function sum(): int
{
return count($this->get());
}
diff --git a/eywa/Database/Seed/Seeder.php b/eywa/Database/Seed/Seeder.php
index ca29063..fc3d518 100755
--- a/eywa/Database/Seed/Seeder.php
+++ b/eywa/Database/Seed/Seeder.php
@@ -1,4 +1,5 @@
<?php
+
declare(strict_types=1);
namespace Eywa\Database\Seed {
@@ -121,7 +122,7 @@ namespace Eywa\Database\Seed {
* @throws Exception
*
*/
- public function seed() : bool
+ public function seed(): bool
{
static::$connexion = development();
@@ -142,7 +143,7 @@ namespace Eywa\Database\Seed {
$columns = static::$table->columns();
- for ($i=0;$i<static::$generate;$i++) {
+ for ($i = 0; $i < static::$generate; $i++) {
static::each(static::$faker, static::$table, $this);
$tmp = collect();
@@ -151,7 +152,7 @@ namespace Eywa\Database\Seed {
$tmp->set(static::$set->get($column));
}
- append($values, '('. trim($tmp->join(), ', ') . '),');
+ append($values, '(' . trim($tmp->join(), ', ') . '),');
static::$set->clear();
diff --git a/eywa/Database/Seed/Seeding.php b/eywa/Database/Seed/Seeding.php
index 279ecf4..dc01f47 100755
--- a/eywa/Database/Seed/Seeding.php
+++ b/eywa/Database/Seed/Seeding.php
@@ -29,7 +29,7 @@ namespace Eywa\Database\Seed {
$item = collect(explode('.', $item))->first();
- $class = '\Evolution\Seeds\\' .$item;
+ $class = '\Evolution\Seeds\\' . $item;
$x[$item] = $class;
}
diff --git a/eywa/Database/Table/Records.php b/eywa/Database/Table/Records.php
index e30a655..fcd048c 100644
--- a/eywa/Database/Table/Records.php
+++ b/eywa/Database/Table/Records.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Database\Table {
@@ -106,7 +105,7 @@ namespace Eywa\Database\Table {
* @throws Kedavra
*
*/
- public function rename_column(string $column, string $new_name): bool;
+ public function renameColumn(string $column, string $new_name): bool;
/**
*
diff --git a/eywa/Database/Table/Table.php b/eywa/Database/Table/Table.php
index e460a7c..92eac1b 100755
--- a/eywa/Database/Table/Table.php
+++ b/eywa/Database/Table/Table.php
@@ -1,4 +1,5 @@
<?php
+
declare(strict_types=1);
namespace Eywa\Database\Table {
@@ -19,10 +20,10 @@ namespace Eywa\Database\Table {
/**
* @var string
*/
- private string $table ='';
+ private string $table = '';
private Collect $columns ;
private string $saved_table = '';
- private string $primary ='id';
+ private string $primary = 'id';
/**
* @inheritDoc
@@ -39,16 +40,27 @@ namespace Eywa\Database\Table {
* @return array
* @throws Kedavra
*/
- public function content(int $pdo_mode = PDO::FETCH_OBJ):array
+ public function content(int $pdo_mode = PDO::FETCH_OBJ): array
{
- return $this->connect->set(sprintf('SELECT * FROM %s', $this->table))->get($pdo_mode);
+ return $this->connect->set(
+ sprintf(
+ 'SELECT * FROM %s',
+ $this->table
+ )
+ )
+ ->get($pdo_mode);
}
/**
* @inheritDoc
*/
public function drop(): bool
{
- return $this->connect->set(sprintf('DROP TABLE %s', $this->table))->execute();
+ return $this->connect->set(
+ sprintf(
+ 'DROP TABLE %s',
+ $this->table
+ )
+ )->execute();
}
/**
@@ -65,15 +77,30 @@ namespace Eywa\Database\Table {
public function truncate(): bool
{
switch ($this->connect->driver()) {
- case MYSQL:
- return $this->connect->set(sprintf('TRUNCATE TABLE %s', $this->table))->execute();
- case POSTGRESQL:
- return $this->connect->set(sprintf('TRUNCATE TABLE %s RESTART IDENTITY', $this->table))->execute();
- case SQLITE:
- return $this->connect->set(sprintf('DELETE FROM %s', $this->table))->set('VACUUM')->execute();
- default:
- return false;
- }
+ case MYSQL:
+ return $this->connect->set(
+ sprintf(
+ 'TRUNCATE TABLE %s',
+ $this->table
+ )
+ )->execute();
+ case POSTGRESQL:
+ return $this->connect->set(
+ sprintf(
+ 'TRUNCATE TABLE %s RESTART IDENTITY',
+ $this->table
+ )
+ )->execute();
+ case SQLITE:
+ return $this->connect->set(
+ sprintf(
+ 'DELETE FROM %s',
+ $this->table
+ )
+ )->set('VACUUM')->execute();
+ default:
+ return false;
+ }
}
/**
@@ -87,7 +114,15 @@ namespace Eywa\Database\Table {
switch ($this->connect->driver()) {
case MYSQL:
case POSTGRESQL:
- return $this->connect->set(sprintf('ALTER TABLE %s %s', $this->table, collect($columns)->for($mysql)->join()))->execute();
+ return $this->connect->set(
+ sprintf(
+ 'ALTER TABLE %s %s',
+ $this->table,
+ collect($columns)
+ ->for($mysql)
+ ->join()
+ )
+ )->execute();
default:
return false;
}
@@ -100,9 +135,21 @@ namespace Eywa\Database\Table {
{
switch ($this->connect->driver()) {
case MYSQL:
- return $this->connect->set(sprintf('RENAME TABLE %s TO %s', $this->table, $new_name))->execute();
+ return $this->connect->set(
+ sprintf(
+ 'RENAME TABLE %s TO %s',
+ $this->table,
+ $new_name
+ )
+ )->execute();
case POSTGRESQL:
- return $this->connect->set(sprintf('ALTER TABLE %s RENAME TO %s', $this->table, $new_name))->execute();
+ return $this->connect->set(
+ sprintf(
+ 'ALTER TABLE %s RENAME TO %s',
+ $this->table,
+ $new_name
+ )
+ )->execute();
default:
return false;
}
@@ -114,7 +161,7 @@ namespace Eywa\Database\Table {
public function has(array $columns): bool
{
foreach ($columns as $column) {
- if ($this->columns()->not_exist($column)) {
+ if ($this->columns()->notExist($column)) {
return false;
}
}
@@ -125,12 +172,19 @@ namespace Eywa\Database\Table {
/**
* @inheritDoc
*/
- public function rename_column(string $column, string $new_name): bool
+ public function renameColumn(string $column, string $new_name): bool
{
switch ($this->connect->driver()) {
case MYSQL:
case POSTGRESQL:
- return $this->connect->set(sprintf('ALTER TABLE %s RENAME COLUMN %s TO %s', $this->table, $column, $new_name))->execute();
+ return $this->connect->set(
+ sprintf(
+ 'ALTER TABLE %s RENAME COLUMN %s TO %s',
+ $this->table,
+ $column,
+ $new_name
+ )
+ )->execute();
default:
return false;
}
@@ -146,25 +200,48 @@ namespace Eywa\Database\Table {
}
switch ($this->connect->driver()) {
- case MYSQL:
- $this->primary = collect($this->connect->set(sprintf('show columns from %s where `Key` = \'PRI\' ', $this->table))->get(COLUMNS))->first();
+ case MYSQL:
+ $this->primary =
+ collect($this->connect->set(
+ sprintf(
+ 'show columns from %s where `Key` = \'PRI\' ',
+ $this->table
+ )
+ )
+ ->get(COLUMNS))->first();
break;
- case POSTGRESQL:
- $this->primary = collect($this->connect->set(sprintf('select column_name FROM information_schema.key_column_usage WHERE table_name = \'%s\' ', $this->table))->get(COLUMNS))->first();
+ case POSTGRESQL:
+ $this->primary =
+ collect($this->connect->set(
+ sprintf(
+ 'select column_name FROM information_schema.key_column_usage WHERE table_name = \'%s\'',
+ $this->table
+ )
+ )->get(COLUMNS))->first();
break;
- case SQLITE:
- foreach ($this->connect->set(sprintf('PRAGMA table_info(%s)', $this->table))->get(OBJECTS) as $column) {
- if ($column->pk) {
- $this->primary = $column->name;
- }
+ case SQLITE:
+ foreach (
+ $this->connect->set(
+ sprintf(
+ 'PRAGMA table_info(%s)',
+ $this->table
+ )
+ )->get(OBJECTS) as $column
+ ) {
+ if ($column->pk) {
+ $this->primary = $column->name;
}
+ }
break;
- case SQL_SERVER:
- $this->primary = collect($this->connect->set(sprintf('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME =\'%s\' AND CONSTRAINT_NAME LIKE \'PK\'', $this->table))->get(COLUMNS))->first();
+ case SQL_SERVER:
+ $this->primary = collect($this->connect->set(
+ sprintf('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME =\'%s\'
+ AND CONSTRAINT_NAME LIKE \'PK\'', $this->table)
+ )->get(COLUMNS))->first();
break;
- default:
- return '';
- }
+ default:
+ return '';
+ }
return $this->primary;
}
@@ -176,9 +253,21 @@ namespace Eywa\Database\Table {
$file = sprintf('%s.sql', $this->connect->base());
switch ($this->connect->driver()) {
case MYSQL:
- return (new Shell(sprintf('mysqldump -u %s -p%s %s > %s', $this->connect->username(), $this->connect->password(), $this->connect->base(), $file)))->run();
+ return (new Shell(sprintf(
+ 'mysqldump -u %s -p%s %s > %s',
+ $this->connect->username(),
+ $this->connect->password(),
+ $this->connect->base(),
+ $file
+ )))->run();
case POSTGRESQL:
- return (new Shell(sprintf('pg_dump -h %s -U %s %s > %s', $this->connect->hostname(), $this->connect->username(), $this->connect->base(), $file)))->run();
+ return (new Shell(sprintf(
+ 'pg_dump -h %s -U %s %s > %s',
+ $this->connect->hostname(),
+ $this->connect->username(),
+ $this->connect->base(),
+ $file
+ )))->run();
case SQLITE:
return (new Shell(sprintf('sqlite3 %s > %s', $this->connect->base(), $file)))->run();
default:
@@ -204,11 +293,34 @@ namespace Eywa\Database\Table {
switch ($this->connect->driver()) {
case MYSQL:
- return (new Shell(sprintf('mysqldump -h %s -u %s -p%s %s < %s', $host, $username, $password, $base, $file)))->run();
+ return (new Shell(
+ sprintf(
+ 'mysqldump -h %s -u %s -p%s %s < %s',
+ $host,
+ $username,
+ $password,
+ $base,
+ $file
+ )
+ ))->run();
case POSTGRESQL:
- return (new Shell(sprintf('psql -h %s -U %s %s < %s', $host, $username, $base, $file)))->run();
+ return (new Shell(
+ sprintf(
+ 'psql -h %s -U %s %s < %s',
+ $host,
+ $username,
+ $base,
+ $file
+ )
+ ))->run();
case SQLITE:
- return (new Shell(sprintf('sqlite3 %s < %s', $base, $file)))->run();
+ return (new Shell(
+ sprintf(
+ 'sqlite3 %s < %s',
+ $base,
+ $file
+ )
+ ))->run();
default:
return false;
}
@@ -224,11 +336,17 @@ namespace Eywa\Database\Table {
case MYSQL:
return collect($this->connect->set('SHOW TABLES')->get(COLUMNS));
case POSTGRESQL:
- return collect($this->connect->set('SELECT table_name FROM information_schema.tables WHERE table_type = \'BASE TABLE\' AND table_schema NOT IN (\'pg_catalog\', \'information_schema\');')->get(COLUMNS));
+ return collect($this->connect->set(
+ 'SELECT table_name FROM information_schema.tables
+ WHERE table_type = \'BASE TABLE\' AND table_schema
+ NOT IN (\'pg_catalog\', \'information_schema\');'
+ )->get(COLUMNS));
case SQLITE:
return collect($this->connect->set('SELECT tbl_name FROM sqlite_master')->get(COLUMNS));
case SQL_SERVER:
- return collect($this->connect->set('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE=\'BASE TABLE\'')->get(COLUMNS));
+ return collect($this->connect
+ ->set('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
+ WHERE TABLE_TYPE=\'BASE TABLE\'')->get(COLUMNS));
default:
return collect();
}
@@ -247,15 +365,26 @@ namespace Eywa\Database\Table {
$x = collect();
switch ($this->connect->driver()) {
case MYSQL:
- $this->columns = collect($this->connect->set("SHOW FULL COLUMNS FROM {$this->table}")->get(COLUMNS));
+ $this->columns = collect($this->connect->set(
+ sprintf(
+ 'SHOW FULL COLUMNS FROM %s',
+ $this->table
+ )
+ )->get(COLUMNS));
$this->saved_table = $this->table;
break;
case POSTGRESQL:
- $this->columns = collect($this->connect->set("SELECT column_name FROM information_schema.columns WHERE table_name ='{$this->table}'")->get(COLUMNS));
+ $this->columns = collect($this->connect->set(
+ "SELECT column_name FROM information_schema.columns WHERE table_name ='{$this->table}'"
+ )->get(COLUMNS));
$this->saved_table = $this->table;
break;
case SQLITE:
- foreach ($this->connect->set("PRAGMA table_info({$this->table})")->get(OBJECTS) as $c) {
+ foreach (
+ $this->connect->set(
+ "PRAGMA table_info({$this->table})"
+ )->get(OBJECTS) as $c
+ ) {
$x->push($c->name);
}
$this->saved_table = $this->table;
@@ -263,11 +392,12 @@ namespace Eywa\Database\Table {
break;
case SQL_SERVER:
$this->saved_table = $this->table;
- $this->columns = collect($this->connect->set("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{$this->table}'")->get(COLUMNS));
+ $this->columns = collect($this->connect->set(
+ "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{$this->table}'"
+ )->get(COLUMNS));
break;
default:
return collect();
-
}
return $this->columns;
}
diff --git a/eywa/Database/User/User.php b/eywa/Database/User/User.php
index 9986579..c9bfc05 100755
--- a/eywa/Database/User/User.php
+++ b/eywa/Database/User/User.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Database\User {
diff --git a/eywa/Debug/Dumper.php b/eywa/Debug/Dumper.php
index d71a8ca..9dee0a8 100755
--- a/eywa/Debug/Dumper.php
+++ b/eywa/Debug/Dumper.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Debug {
@@ -19,8 +20,8 @@ namespace Eywa\Debug {
*/
public function dump($value)
{
- $dumper = 'cli' === PHP_SAPI ? new CliDumper : new HtmlDumper;
- $dumper->dump((new VarCloner)->cloneVar($value));
+ $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
+ $dumper->dump((new VarCloner())->cloneVar($value));
}
}
}
diff --git a/eywa/Debug/HtmlDumper.php b/eywa/Debug/HtmlDumper.php
index 64f2939..1100aff 100755
--- a/eywa/Debug/HtmlDumper.php
+++ b/eywa/Debug/HtmlDumper.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Debug {
@@ -10,6 +11,33 @@ namespace Eywa\Debug {
* @var array<mixed>
*/
protected static $themes = [
- 'dark' => [ 'default' => 'background:none; color:#222; line-height:1.2em; font:12px Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all', 'ellipsis' => 'color:#CC7832', 'ns' => 'user-select:none;', 'num' => 'color:#a71d5d', 'const' => 'color:#795da3', 'str' => 'color:#df5000', 'cchr' => 'color:#222', 'note' => 'color:#a71d5d', 'ref' => 'color:#a0a0a0', 'public' => 'color:#795da3', 'protected' => 'color:#795da3', 'private' => 'color:#795da3', 'meta' => 'color:#795da3', 'key' => 'color:#df5000', 'index' => 'color:#a71d5d', ], ];
+ 'dark' =>
+ [
+ 'default' => 'background:none;
+ color:#222;
+ line-height:1.2em;
+ font:12px Monaco, Consolas, monospace;
+ word-wrap: break-word;
+ white-space: pre-wrap;
+ position:absolute;
+ botom: 0;
+ z-index:99999;
+ word-break: break-all',
+ 'ellipsis' => 'color:#CC7832',
+ 'ns' => 'user-select:none;',
+ 'num' => 'color:#a71d5d',
+ 'const' => 'color:#795da3',
+ 'str' => 'color:#df5000',
+ 'cchr' => 'color:#222',
+ 'note' => 'color:#a71d5d',
+ 'ref' => 'color:#a0a0a0',
+ 'public' => 'color:#795da3',
+ 'protected' => 'color:#795da3',
+ 'private' => 'color:#795da3',
+ 'meta' => 'color:#795da3',
+ 'key' => 'color:#df5000',
+ 'index' => 'color:#a71d5d'
+ ]
+ ];
}
}
diff --git a/eywa/Detection/Detect.php b/eywa/Detection/Detect.php
index 481dbb4..36baa4e 100755
--- a/eywa/Detection/Detect.php
+++ b/eywa/Detection/Detect.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Detection {
use Mobile_Detect;
@@ -140,7 +141,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function chrome_os(): bool
+ public function chromeOs(): bool
{
return $this->os() === Os::CHROME_OS;
}
@@ -312,7 +313,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function opera_mini(): bool
+ public function operaMini(): bool
{
return $this->browser() === Browser::OPERA_MINI;
}
@@ -325,7 +326,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function web_tv(): bool
+ public function webTv(): bool
{
return $this->browser() === Browser::WEBTV;
}
@@ -351,7 +352,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function pocket_ie(): bool
+ public function pocketIe(): bool
{
return $this->browser() === Browser::POCKET_IE;
}
@@ -522,7 +523,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function samsung_browser(): bool
+ public function samsungBrowser(): bool
{
return $this->browser() === Browser::SAMSUNG_BROWSER;
}
@@ -548,7 +549,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function google_bot(): bool
+ public function googlebot(): bool
{
return $this->browser() === Browser::GOOGLEBOT;
}
@@ -619,7 +620,7 @@ namespace Eywa\Detection {
* @return bool
*
*/
- public function windows_phone(): bool
+ public function windowsPhone(): bool
{
return $this->device() === Device::WINDOWS_PHONE;
}
diff --git a/eywa/Exception/Kedavra.php b/eywa/Exception/Kedavra.php
index 7637ca5..efbda35 100755
--- a/eywa/Exception/Kedavra.php
+++ b/eywa/Exception/Kedavra.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Exception {
diff --git a/eywa/File/Assets.php b/eywa/File/Assets.php
index 0ec5437..58c5d77 100644
--- a/eywa/File/Assets.php
+++ b/eywa/File/Assets.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\File {
@@ -49,7 +48,7 @@ namespace Eywa\File {
* @throws Kedavra
*
*/
- public function make():string
+ public function make(): string
{
switch ($this->type) {
case 'css':
@@ -73,7 +72,8 @@ namespace Eywa\File {
*/
private function js(): string
{
- return https() ? 'https://'. Request::make()->server()->get('SERVER_NAME') . '/js/' . $this->filename : 'http://'. Request::make()->server()->get('SERVER_NAME') . '/js/' . $this->filename;
+ return https() ? 'https://' . Request::make()->server()->get('SERVER_NAME') . '/js/' . $this->filename
+ : 'http://' . Request::make()->server()->get('SERVER_NAME') . '/js/' . $this->filename;
}
/**
@@ -87,7 +87,10 @@ namespace Eywa\File {
*/
private function css(): string
{
- return https() ? 'https://'. Request::make()->server()->get('SERVER_NAME') . '/css/' . $this->filename : 'http://'. Request::make()->server()->get('SERVER_NAME') . '/css/' . $this->filename;
+ return https()
+ ?
+ 'https://' . Request::make()->server()->get('SERVER_NAME') . '/css/' . $this->filename
+ : 'http://' . Request::make()->server()->get('SERVER_NAME') . '/css/' . $this->filename;
}
}
}
diff --git a/eywa/File/File.php b/eywa/File/File.php
index b054c48..0f7800a 100755
--- a/eywa/File/File.php
+++ b/eywa/File/File.php
@@ -1,5 +1,7 @@
<?php
+
declare(strict_types=1);
+
namespace Eywa\File {
use Eywa\Collection\Collect;
@@ -140,9 +142,9 @@ namespace Eywa\File {
* @return bool
*
*/
- public function to_json(array $data): bool
+ public function json(array $data): bool
{
- return file_put_contents($this->absolute_path(), json_encode($data, JSON_FORCE_OBJECT)) !== false;
+ return file_put_contents($this->realpath(), json_encode($data, JSON_FORCE_OBJECT)) !== false;
}
/**
@@ -154,7 +156,7 @@ namespace Eywa\File {
* @return bool
*
*/
- public static function remove_if_exist(string $filename): bool
+ public static function del(string $filename): bool
{
return self::exist([$filename]) ? self::delete($filename) : false;
}
@@ -209,9 +211,9 @@ namespace Eywa\File {
* @return int
*
*/
- public function count_lines(): int
+ public function sum(): int
{
- return $this->to(PHP_INT_MAX)->current_line() + 1;
+ return $this->to(PHP_INT_MAX)->position() + 1;
}
/**
@@ -247,9 +249,9 @@ namespace Eywa\File {
*/
public function char(): string
{
- $x= $this->instance()->fgetc();
+ $x = $this->instance()->fgetc();
- return $x !== false ? $x :'';
+ return $x !== false ? $x : '';
}
/**
@@ -343,7 +345,7 @@ namespace Eywa\File {
* @return int
*
*/
- public function current_line(): int
+ public function position(): int
{
return $this->instance()->key();
}
@@ -377,7 +379,7 @@ namespace Eywa\File {
* @throws Kedavra
*
*/
- public function write_line(string $line_content): File
+ public function add(string $line_content): File
{
return $this->write("$line_content\n");
}
@@ -418,7 +420,7 @@ namespace Eywa\File {
* @return File
*
*/
- public function set_max(int $max): File
+ public function maximum(int $max): File
{
$this->instance()->setMaxLineLen($max);
@@ -463,7 +465,7 @@ namespace Eywa\File {
* @return bool
*
*/
- public function is_dir(): bool
+ public function dir(): bool
{
return $this->instance()->isDir();
}
@@ -475,7 +477,7 @@ namespace Eywa\File {
* @return bool
*
*/
- public function is_file(): bool
+ public function file(): bool
{
return $this->instance()->isFile();
}
@@ -561,7 +563,7 @@ namespace Eywa\File {
* @return string
*
*/
- public function base_name(string $suffix = ''): string
+ public function basename(string $suffix = ''): string
{
return $this->instance()->getBasename($suffix);
}
@@ -597,7 +599,7 @@ namespace Eywa\File {
* @return string
*
*/
- public function absolute_path():string
+ public function realpath(): string
{
$x = $this->instance()->getRealPath();
@@ -621,7 +623,7 @@ namespace Eywa\File {
* @return bool
*
*/
- public function is_link(): bool
+ public function link(): bool
{
return $this->instance()->isLink();
}
@@ -661,7 +663,9 @@ namespace Eywa\File {
*/
public function copy(string $dest): bool
{
- return is_dir($dest) ? copy($this->absolute_path(), "$dest" . DIRECTORY_SEPARATOR . $this->name()) : copy($this->absolute_path(), $dest);
+ return is_dir($dest)
+ ? copy($this->realpath(), "$dest" . DIRECTORY_SEPARATOR . $this->name())
+ : copy($this->realpath(), $dest);
}
/**
@@ -673,7 +677,7 @@ namespace Eywa\File {
*/
public function remove(): bool
{
- return unlink($this->absolute_path());
+ return unlink($this->realpath());
}
/**
@@ -687,7 +691,9 @@ namespace Eywa\File {
*/
public function move(string $dest)
{
- return is_dir($dest) ? copy($this->absolute_path(), "$dest" . DIRECTORY_SEPARATOR . $this->name()) && $this->remove() : copy($this->absolute_path(), $dest) && $this->remove();
+ return is_dir($dest)
+ ? copy($this->realpath(), "$dest" . DIRECTORY_SEPARATOR . $this->name())
+ && $this->remove() : copy($this->realpath(), $dest) && $this->remove();
}
/**
@@ -739,7 +745,7 @@ namespace Eywa\File {
* @return array<mixed>
*
*/
- public function keys(string $delimiter = ':'):array
+ public function keys(string $delimiter = ':'): array
{
$data = collect();
@@ -776,32 +782,5 @@ namespace Eywa\File {
return $data->values()->all();
}
-
- /**
- * @param array<mixed> $keys
- * @param array<mixed> $values
- * @param string $delimiter
- *
- * @return bool
- *
- * @throws Kedavra
- *
- */
- public function change_values(array $keys, array $values, string $delimiter = ':'): bool
- {
- if (sum($keys) !== sum($values)) {
- throw new Kedavra('The keys and values size are different');
- }
- $keys = collect($keys);
- $values = collect($values);
- foreach ($keys->all() as $k => $v) {
- $key = $keys->get($k);
- $value = $values->get($k);
- $line = is_numeric($value) || is_bool($value) ? "$key$delimiter $value" : "$key$delimiter '$value'";
- $this->write_line($line);
- }
-
- return $this->flush();
- }
}
}
diff --git a/eywa/Html/Form/Form.php b/eywa/Html/Form/Form.php
index a441f28..0045596 100755
--- a/eywa/Html/Form/Form.php
+++ b/eywa/Html/Form/Form.php
@@ -105,15 +105,15 @@ namespace Eywa\Html\Form {
$method = static::$method;
$options = static::$options;
- $this->form = '<form action="'.$url.'" method="POST" '. collect($options)->each(function ($k, $v) {
- return $k.'='.'"'.$v.'"';
- })->join('').'>';
+ $this->form = '<form action="' . $url . '" method="POST" ' . collect($options)->each(function ($k, $v) {
+ return $k . '=' . '"' . $v . '"';
+ })->join('') . '>';
$this->inputs = collect();
- $this->add('_method', 'hidden', '', '', ['value'=> $method]);
- $this->add(CSRF_TOKEN, 'hidden', '', '', ['value'=> csrf_field()]);
+ $this->add('_method', 'hidden', '', '', ['value' => $method]);
+ $this->add(CSRF_TOKEN, 'hidden', '', '', ['value' => csrf_field()]);
return $this;
}
@@ -132,9 +132,14 @@ namespace Eywa\Html\Form {
* @throws Kedavra
*
*/
- protected function add(string $name, string $type, string $label_text, string $help_text ='', array $options = []): Form
- {
- if ($this->has_input($name)) {
+ protected function add(
+ string $name,
+ string $type,
+ string $label_text,
+ string $help_text = '',
+ array $options = []
+ ): Form {
+ if ($this->check($name)) {
return $this;
} else {
$this->inputs->put($name, $name);
@@ -161,27 +166,30 @@ namespace Eywa\Html\Form {
case 'url':
case 'week':
case 'datetime':
-
-
- $this->append('<div class="'.$this->class('separator', 'form-group').'">');
+ $this->append('<div class="' . $this->class('separator', 'form-group') . '">');
$x = collect($options)->each(function ($k, $v) {
- return $k.'='.'"'.$v.'"';
+ return $k . '=' . '"' . $v . '"';
})->join(' ');
$help_id = def($help_text) ? "help-$name" : '';
- $help_input = def($help_text) ? '<small id="'.$help_id.'" class="'.$this->class('help', 'form-help').'">'.$help_text.'</small>' : '';
+ $help_input =
+ def($help_text) ?
+ '<small id="' . $help_id . '"
+ class="' . $this->class('help', 'form-help') . '">' . $help_text . '</small>' : '';
- $help_atribute = def($help_text) ? ' aria-describedby="'.$help_id.'" ': '';
+ $help_atribute = def($help_text) ? ' aria-describedby="' . $help_id . '" ' : '';
if (equal($type, 'hidden')) {
- $input = '<input type="'.$type.'" name="'.$name.'" id="'.$name.'" '.$x.'>';
+ $input = '<input type="' . $type . '" name="' . $name . '" id="' . $name . '" ' . $x . '>';
} else {
- $input = '<div class="'.$this->class('separator', 'form-group').'">
- '.$help_input.'
- <label for="'.$name.'">'.$label_text.'</label>
- <input type="'.$type.'" name="'.$name.'" class="'.$this->class('input', 'form-control').'" id="'.$name.'" '.$help_atribute.' '.$x.'>
+ $input = '<div class="' . $this->class('separator', 'form-group') . '">
+ ' . $help_input . '
+ <label for="' . $name . '">' . $label_text . '</label>
+ <input type="' . $type . '" name="' . $name . '"
+ class="' . $this->class('input', 'form-control') . '"
+ id="' . $name . '" ' . $help_atribute . ' ' . $x . '>
</div>';
}
@@ -189,25 +197,30 @@ namespace Eywa\Html\Form {
$this->end();
break;
case 'textarea':
-
- $this->append('<div class="'.$this->class('separator', 'form-group').'">');
+ $this->append('<div class="' . $this->class('separator', 'form-group') . '">');
$x = collect($options)->each(function ($k, $v) {
- return $k.'='.'"'.$v.'"';
+ return $k . '=' . '"' . $v . '"';
})->join('');
$value = array_key_exists('value', $options) ? $options['value'] : '';
$help_id = def($help_text) ? "help-$name" : '';
- $help_input = def($help_text) ? '<div class="'.$this->class('help-separator', 'help-separator').'"><small id="'.$help_id.' " class="'.$this->class('help-text', 'help-text').'">'.$help_text.'</small></div>' : '';
+ $help_input = def($help_text) ?
+ '<div class="' . $this->class('help-separator', 'help-separator') . '">
+ <small id="' . $help_id . '"
+ class="' . $this->class('help-text', 'help-text') . '">' . $help_text . '</small>
+ </div>' : '';
$help_atribute = '';
- $input = '<div class="'.$this->class('separator', 'form-group').'">
- '.$help_input.'
- <label for="'.$name.'">'.$label_text.'</label>
- <textarea name="'.$name.'" class="'.$this->class('input', 'form-control').'" id="'.$name.'" '.$help_atribute.' '.$x.' >'.$value.'</textarea>
+ $input = '<div class="' . $this->class('separator', 'form-group') . '">
+ ' . $help_input . '
+ <label for="' . $name . '">' . $label_text . '</label>
+ <textarea name="' . $name . '"
+ class="' . $this->class('input', 'form-control') . '"
+ id="' . $name . '" ' . $help_atribute . ' ' . $x . ' >' . $value . '</textarea>
</div>';
@@ -216,28 +229,31 @@ namespace Eywa\Html\Form {
$this->end();
break;
case 'file':
- $this->append('<div class="'.$this->class('separator', 'form-group').'">');
+ $this->append('<div class="' . $this->class('separator', 'form-group') . '">');
$help_id = def($help_text) ? "help-$name" : '';
- $help_input = def($help_text) ? '<small id="'.$help_id.' " class="text-muted">'.$help_text.'</small>' : '';
+ $help_input = def($help_text) ?
+ '<small id="' . $help_id . ' " class="text-muted">' . $help_text . '</small>' : '';
- $help_atribute = def($help_text) ? ' aria-describedby="'.$help_id.'" ': '';
+ $help_atribute = def($help_text) ? ' aria-describedby="' . $help_id . '" ' : '';
$x = collect($options)->each(function ($k, $v) {
- return $k.'='.'"'.$v.'"';
+ return $k . '=' . '"' . $v . '"';
})->join('');
- $input = '<div class="'.$this->class('separator', 'form-group').'">
- '.$help_input.'
- <label for="'.$name.'">'.$label_text.'</label>
- <input name="files[]" class="'.$this->class('input', 'form-control').'" id="'.$name.'" '.$help_atribute.' '.$x.' multiple>
+ $input = '<div class="' . $this->class('separator', 'form-group') . '">
+ ' . $help_input . '
+ <label for="' . $name . '">' . $label_text . '</label>
+ <input name="files[]" class="' . $this->class('input', 'form-control') . '"
+ id="' . $name . '" ' . $help_atribute . ' ' . $x . ' multiple>
</div>';
$this->append($input);
$this->end();
break;
case 'hidden':
- $x = '<input type="hidden" name="'.$name.'" class="'.$this->class('hide', 'hide').'" value="'.$options['value'] .'">';
+ $x = '<input type="hidden" name="' . $name . '"
+ class="' . $this->class('hide', 'hide') . '" value="' . $options['value'] . '">';
$this->append($x);
break;
}
@@ -255,10 +271,12 @@ namespace Eywa\Html\Form {
* @throws Kedavra
*
*/
- protected function get(string $submit_text ='submit'): string
+ protected function get(string $submit_text = 'submit'): string
{
- $input = '<div class="'.$this->class('separator', 'form-group').'">
- <button type="submit" class="'.$this->class('submit', 'btn btn-submit').'">'.$submit_text.'</button>
+ $input = '<div class="' . $this->class('separator', 'form-group') . '">
+ <button type="submit" class="' . $this->class('submit', 'btn btn-submit') . '">'
+ . $submit_text . '
+ </button>
</div>';
$this->append($input);
@@ -291,7 +309,7 @@ namespace Eywa\Html\Form {
*/
protected function row(): Form
{
- return $this->append('<div class="'.$this->class('row', 'row').'">');
+ return $this->append('<div class="' . $this->class('row', 'row') . '">');
}
/**
@@ -303,7 +321,7 @@ namespace Eywa\Html\Form {
* @return bool
*
*/
- private function has_input(string $name): bool
+ private function check(string $name): bool
{
return $this->inputs->has($name);
}
@@ -335,7 +353,7 @@ namespace Eywa\Html\Form {
* @throws Kedavra
*
*/
- private function class(string $x, string $value =''):string
+ private function class(string $x, string $value = ''): string
{
$x = collect(config('form', 'class'))->get($x);
return def($x) ? $x : $value;
diff --git a/eywa/Html/Navigation/Navigation.php b/eywa/Html/Navigation/Navigation.php
index 7aa6ad4..c89a876 100644
--- a/eywa/Html/Navigation/Navigation.php
+++ b/eywa/Html/Navigation/Navigation.php
@@ -37,6 +37,16 @@ namespace Eywa\Html\Navigation {
is_false(is_string($this->nav_a_class), true, 'The navigation a class must be a string');
}
+ /**
+ *
+ *
+ * Display the navigation bar
+ *
+ * @return string
+ *
+ * @throws Kedavra
+ *
+ */
public function display(): string
{
$html = sprintf('<nav class="%s" ><ul>', $this->navigation_class);
@@ -44,7 +54,16 @@ namespace Eywa\Html\Navigation {
foreach ($this->links as $k => $v) {
$link = cli() ? strval($k) : url($k) ;
- append($html, sprintf('<li class="%s"><a href="%s" class="%s">%s</a></li>', $this->navigation_li_class, $link, $this->nav_a_class, $v));
+ append(
+ $html,
+ sprintf(
+ '<li class="%s"><a href="%s" class="%s">%s</a></li>',
+ $this->navigation_li_class,
+ $link,
+ $this->nav_a_class,
+ $v
+ )
+ );
}
append($html, '</ul></nav>');
return $html;
diff --git a/eywa/Html/Pagination/Pagination.php b/eywa/Html/Pagination/Pagination.php
index d85a03c..541bdc7 100755
--- a/eywa/Html/Pagination/Pagination.php
+++ b/eywa/Html/Pagination/Pagination.php
@@ -78,7 +78,7 @@ namespace Eywa\Html\Pagination {
* @return string
*
*/
- public function paginate() : string
+ public function paginate(): string
{
if (superior_or_equal($this->limit, $this->total)) {
return '';
@@ -87,7 +87,23 @@ namespace Eywa\Html\Pagination {
$html = '<ul class="' . config('pagination', 'ul_class') . '">';
for ($i = 1; $i != $this->pages; $i++) {
- $i === $this->current_page ? append($html, '<li class="' . config('pagination', 'li_class') . ' active"><a href="' . $this->url . $i . '" class="' . config('pagination', 'link_class') . '">' . $i . '</a></li>') : append($html, '<li class="' . config('pagination', 'li_class') . '"><a href="' . $this->url . $i . '" class="' . config('pagination', 'link_class') . '">' . $i . '</a></li>');
+ ($i === $this->current_page) ?
+ append(
+ $html,
+ '<li class="' . config('pagination', 'li_class') . ' active">
+ <a href="' . $this->url . $i . '"
+ class="' . config('pagination', 'link_class') . '">' . $i . '</a>
+ </li>'
+ )
+ :
+ append(
+ $html,
+ '<li class="' . config('pagination', 'li_class') . '">
+ <a href="' . $this->url . $i . '"
+ class="' . config('pagination', 'link_class') . '">' . $i . '
+ </a>
+ </li>'
+ );
}
append($html, '</ul>');
diff --git a/eywa/Http/Controller/Controller.php b/eywa/Http/Controller/Controller.php
index aa9e7b6..3f937d3 100755
--- a/eywa/Http/Controller/Controller.php
+++ b/eywa/Http/Controller/Controller.php
@@ -23,7 +23,7 @@ namespace Eywa\Http\Controller {
* @param Request $request
*
*/
- abstract public function before_action(Request $request): void;
+ abstract public function before(Request $request): void;
/**
*
@@ -32,6 +32,6 @@ namespace Eywa\Http\Controller {
* @param Request $request
*
*/
- abstract public function after_action(Request $request):void;
+ abstract public function after(Request $request): void;
}
}
diff --git a/eywa/Http/Controller/Crud.php b/eywa/Http/Controller/Crud.php
index ec1e6f9..89c9c7d 100644
--- a/eywa/Http/Controller/Crud.php
+++ b/eywa/Http/Controller/Crud.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Http\Controller {
use Eywa\Application\App;
@@ -18,7 +17,7 @@ namespace Eywa\Http\Controller {
* @param Request $request
*
*/
- abstract public function before_action(Request $request): void;
+ abstract public function before(Request $request): void;
/**
*
@@ -27,7 +26,7 @@ namespace Eywa\Http\Controller {
* @param Request $request
*
*/
- abstract public function after_action(Request $request):void;
+ abstract public function after(Request $request): void;
/**
*
diff --git a/eywa/Http/Curl/Curl.php b/eywa/Http/Curl/Curl.php
index e546b8e..52eb2f1 100755
--- a/eywa/Http/Curl/Curl.php
+++ b/eywa/Http/Curl/Curl.php
@@ -1,4 +1,5 @@
<?php
+
declare(strict_types=1);
namespace Eywa\Http\Curl {
diff --git a/eywa/Http/Middleware/Middleware.php b/eywa/Http/Middleware/Middleware.php
index d208785..b2e28b4 100755
--- a/eywa/Http/Middleware/Middleware.php
+++ b/eywa/Http/Middleware/Middleware.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Http\Middleware {
use Eywa\Exception\Kedavra;
diff --git a/eywa/Http/Parameter/Uploaded/UploadedFile.php b/eywa/Http/Parameter/Uploaded/UploadedFile.php
index e179ec9..37a4f14 100755
--- a/eywa/Http/Parameter/Uploaded/UploadedFile.php
+++ b/eywa/Http/Parameter/Uploaded/UploadedFile.php
@@ -1,12 +1,10 @@
<?php
-
namespace Eywa\Http\Parameter\Uploaded {
use Exception;
use Eywa\Collection\Collect;
- use Eywa\Exception\Kedavra;
use SplFileInfo;
use wapmorgan\FileTypeDetector\Detector;
@@ -69,7 +67,6 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* @param array<mixed> $files
*
- * @throws Kedavra
*
*/
public function __construct(array $files = [])
@@ -80,7 +77,7 @@ namespace Eywa\Http\Parameter\Uploaded {
$this->errors = collect();
$this->size = collect();
if (def($files)) {
- $i= 0;
+ $i = 0;
$this->sum = collect($files['files']['name'])->sum();
do {
@@ -99,9 +96,24 @@ namespace Eywa\Http\Parameter\Uploaded {
if (
- $type && ! in_array($x->getExtension(), ['exe','php','c','rb','bat','js','perl','bash','sh','py','ts',''])
+ $type
+ &&
+ ! in_array(
+ $x->getExtension(),
+ ['exe','php','c','rb','bat','js','perl','bash','sh','py','ts','']
+ )
&& ! $x->isExecutable()
- && ! in_array($type, ['application/javascript','application/typescript','application/java-archive','application/x-msdownload','text/plain'])) {
+ && ! in_array(
+ $type,
+ [
+ 'application/javascript',
+ 'application/typescript',
+ 'application/java-archive',
+ 'application/x-msdownload',
+ 'text/plain'
+ ]
+ )
+ ) {
$this->filename->put($i, $current);
$this->types->put($this->filename->get($i), $file['type'][$i]);
@@ -111,7 +123,7 @@ namespace Eywa\Http\Parameter\Uploaded {
$this->size->put($this->filename->get($i), $file['size'][$i]);
}
$i++;
- } while ($i <$this->sum);
+ } while ($i < $this->sum);
}
}
@@ -123,7 +135,7 @@ namespace Eywa\Http\Parameter\Uploaded {
$path = base('web');
foreach (explode(DIRECTORY_SEPARATOR, $path) as $dir) {
- append($path, DIRECTORY_SEPARATOR. $dir);
+ append($path, DIRECTORY_SEPARATOR . $dir);
if (!is_dir($path)) {
mkdir($path);
@@ -137,11 +149,11 @@ namespace Eywa\Http\Parameter\Uploaded {
$countfiles = $this->filename->sum();
// Looping all files
- for ($i=0;$i<$countfiles;$i++) {
+ for ($i = 0; $i < $countfiles; $i++) {
$filename = $this->filename->get($i);
// Upload file
- $result->push(move_uploaded_file($this->temporary->get($i), $path.DIRECTORY_SEPARATOR.$filename));
+ $result->push(move_uploaded_file($this->temporary->get($i), $path . DIRECTORY_SEPARATOR . $filename));
}
return $result->ok();
}
diff --git a/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php b/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php
index c76b5d4..032de8f 100755
--- a/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php
+++ b/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Http\Parameter\Uploaded {
@@ -50,7 +49,7 @@ namespace Eywa\Http\Parameter\Uploaded {
* @return array<string>
*
*/
- public function files():array;
+ public function files(): array;
/**
*
@@ -59,7 +58,7 @@ namespace Eywa\Http\Parameter\Uploaded {
* @return array<string>
*
*/
- public function types():array;
+ public function types(): array;
/**
*
@@ -68,7 +67,7 @@ namespace Eywa\Http\Parameter\Uploaded {
* @return array<int>
*
*/
- public function size():array;
+ public function size(): array;
/**
*
@@ -76,7 +75,7 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* @return array<int>
*/
- public function errors():array;
+ public function errors(): array;
/**
*
@@ -85,7 +84,7 @@ namespace Eywa\Http\Parameter\Uploaded {
* @return array<string>
*
*/
- public function temporary():array;
+ public function temporary(): array;
/**
*
diff --git a/eywa/Http/Request/Request.php b/eywa/Http/Request/Request.php
index 236a399..f64e7a5 100755
--- a/eywa/Http/Request/Request.php
+++ b/eywa/Http/Request/Request.php
@@ -68,8 +68,14 @@ namespace Eywa\Http\Request {
* @throws Kedavra
*
*/
- public function __construct(array $request = [], array $query = [], array $cookies = [], array $files = [], array $server = [], array $router_args = [])
- {
+ public function __construct(
+ array $request = [],
+ array $query = [],
+ array $cookies = [],
+ array $files = [],
+ array $server = [],
+ array $router_args = []
+ ) {
$this->initialize($query, $request, $cookies, $files, $server, $router_args);
}
@@ -198,8 +204,14 @@ namespace Eywa\Http\Request {
*
* @throws Kedavra
*/
- private function initialize(array $query, array $request, array $cookies, array $files, array $server, array $router_args):void
- {
+ private function initialize(
+ array $query,
+ array $request,
+ array $cookies,
+ array $files,
+ array $server,
+ array $router_args
+ ): void {
$this->query = new Bag($query);
$this->request = new Bag($request);
$this->cookie = new Bag($cookies);
@@ -218,25 +230,50 @@ namespace Eywa\Http\Request {
}
$ip = $_SERVER['REMOTE_ADDR'];
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
+ if (
+ isset($_SERVER['HTTP_X_FORWARDED_FOR'])
+ && preg_match_all(
+ '#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s',
+ $_SERVER['HTTP_X_FORWARDED_FOR'],
+ $matches
+ )
+ ) {
foreach ($matches[0] as $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
- } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
+ } elseif (
+ isset($_SERVER['HTTP_CLIENT_IP'])
+ && preg_match(
+ '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',
+ $_SERVER['HTTP_CLIENT_IP']
+ )
+ ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CF_CONNECTING_IP'])) {
+ } elseif (
+ isset($_SERVER['HTTP_CF_CONNECTING_IP'])
+ && preg_match(
+ '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',
+ $_SERVER['HTTP_CF_CONNECTING_IP']
+ )
+ ) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
- } elseif (isset($_SERVER['HTTP_X_REAL_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_X_REAL_IP'])) {
+ } elseif (
+ isset($_SERVER['HTTP_X_REAL_IP']) &&
+ preg_match(
+ '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/',
+ $_SERVER['HTTP_X_REAL_IP']
+ )
+ ) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
}
return $ip;
}
- public function local():bool
+ public function local(): bool
{
return $this->ip() === LOCALHOST_IP;
}
diff --git a/eywa/Http/Request/ServerRequest.php b/eywa/Http/Request/ServerRequest.php
index 1127586..6a72ea5 100755
--- a/eywa/Http/Request/ServerRequest.php
+++ b/eywa/Http/Request/ServerRequest.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Http\Request {
@@ -50,7 +51,11 @@ namespace Eywa\Http\Request {
if (not_cli()) {
$this->request = Request::make();
- $this->method = different($method, GET) ? strval($this->request->request()->get('_method', POST)) : $method;
+ $this->method = different($method, GET) ?
+ strval(
+ $this->request->request()->get('_method', POST)
+ )
+ : $method;
} else {
$this->request = new Request();
@@ -104,7 +109,7 @@ namespace Eywa\Http\Request {
* @return Bag
*
*/
- public function request():Bag
+ public function request(): Bag
{
return $this->request->request();
}
diff --git a/eywa/Http/Response/JsonResponse.php b/eywa/Http/Response/JsonResponse.php
index d03be34..d46f9c8 100755
--- a/eywa/Http/Response/JsonResponse.php
+++ b/eywa/Http/Response/JsonResponse.php
@@ -46,7 +46,7 @@ namespace Eywa\Http\Response {
* @return Response
*
*/
- public function send():Response
+ public function send(): Response
{
return $this->reponse->send();
}
diff --git a/eywa/Http/Response/RedirectResponse.php b/eywa/Http/Response/RedirectResponse.php
index da46d3b..60eb9e7 100755
--- a/eywa/Http/Response/RedirectResponse.php
+++ b/eywa/Http/Response/RedirectResponse.php
@@ -1,6 +1,5 @@
<?php
-
declare(strict_types=1);
namespace Eywa\Http\Response {
@@ -62,7 +61,7 @@ namespace Eywa\Http\Response {
* @return Response
*
*/
- public function send():Response
+ public function send(): Response
{
return $this->response->send();
}
diff --git a/eywa/Http/Response/Response.php b/eywa/Http/Response/Response.php
index a15e888..2b2f2de 100755
--- a/eywa/Http/Response/Response.php
+++ b/eywa/Http/Response/Response.php
@@ -63,7 +63,7 @@ namespace Eywa\Http\Response {
*/
public function __construct(string $content, string $url = '', int $status = 200, array $headers = [])
{
- $this->set_content($content)->set_status($status)->set_headers($headers)->set_url($url);
+ $this->setContent($content)->setStatus($status)->setHeaders($headers)->setUrl($url);
}
/**
@@ -96,7 +96,7 @@ namespace Eywa\Http\Response {
* @throws Kedavra
*
*/
- public function set_status(int $status): Response
+ public function setStatus(int $status): Response
{
not_in(STATUS_CODES, $status, true, 'The status code is not valid');
@@ -115,7 +115,7 @@ namespace Eywa\Http\Response {
* @return Response
*
*/
- public function set_headers(array $headers): Response
+ public function setHeaders(array $headers): Response
{
$this->headers = $headers;
@@ -145,7 +145,7 @@ namespace Eywa\Http\Response {
* @return Response
*
*/
- public function set_content(string $content): Response
+ public function setContent(string $content): Response
{
$this->content = $content;
@@ -161,7 +161,7 @@ namespace Eywa\Http\Response {
*/
public function send(): Response
{
- return $this->send_headers()->send_content();
+ return $this->sendHeaders()->sendContent();
}
/**
@@ -169,7 +169,7 @@ namespace Eywa\Http\Response {
*
* @return $this
*/
- public function send_content()
+ public function sendContent()
{
if (not_cli()) {
echo $this->content();
@@ -185,7 +185,7 @@ namespace Eywa\Http\Response {
* @return Response
*
*/
- public function send_headers(): Response
+ public function sendHeaders(): Response
{
// headers have already been sent by the developer
if (headers_sent()) {
@@ -271,7 +271,7 @@ namespace Eywa\Http\Response {
* @return Response
*
*/
- private function set_url(string $url): Response
+ private function setUrl(string $url): Response
{
$this->url = def($url) ? $url : '';
return $this;
diff --git a/eywa/Http/Routing/RouteResult.php b/eywa/Http/Routing/RouteResult.php
index 030a3c1..66e5312 100755
--- a/eywa/Http/Routing/RouteResult.php
+++ b/eywa/Http/Routing/RouteResult.php
@@ -18,7 +18,7 @@ namespace Eywa\Http\Routing {
* The controller namespace
*
*/
- private string $namespace = '';
+ private string $namespace ;
/**
@@ -26,14 +26,14 @@ namespace Eywa\Http\Routing {
* The route controller
*
*/
- private string $controller = '';
+ private string $controller ;
/**
*
* The route action&
*
*/
- private string $action = '';
+ private string $action;
/**
@@ -43,14 +43,14 @@ namespace Eywa\Http\Routing {
* @var array<mixed>
*
*/
- private array $args = [];
+ private array $args;
/**
*
* The http method used
*
*/
- private string $method = '';
+ private string $method;
/**
*
@@ -89,7 +89,7 @@ namespace Eywa\Http\Routing {
*/
public function class()
{
- return $this->namespace() .'\\' . $this->controller();
+ return $this->namespace() . '\\' . $this->controller();
}
/**
@@ -99,21 +99,41 @@ namespace Eywa\Http\Routing {
*/
public function call(): Response
{
- is_false(class_exists($this->class()), true, "The class {$this->controller()} not exist inside the Controllers directory");
-
- is_false(method_exists($this->class(), $this->action()), true, "The action {$this->action()} not exist inside the {$this->controller()} controller");
+ is_false(
+ class_exists(
+ $this->class()
+ ),
+ true,
+ sprintf(
+ 'The class %s not exist inside the Controllers directory',
+ $this->controller()
+ )
+ );
+
+ is_false(
+ method_exists(
+ $this->class(),
+ $this->action()
+ ),
+ true,
+ sprintf(
+ 'The action %s not exist inside the %s controller',
+ $this->action(),
+ $this->controller()
+ )
+ );
$x = new ReflectionClass($this->class());
$request = cli() ? new Request([], [], [], [], [], $this->args()) : Request::make($this->args());
- $x->getMethod('before_action')->invoke($x->newInstance(), $request);
+ $x->getMethod('before')->invoke($x->newInstance(), $request);
$result = $x->getMethod($this->action())->invoke($x->newInstance(), $request);
- $x->getMethod('after_action')->invoke($x->newInstance(), $request);
+ $x->getMethod('after')->invoke($x->newInstance(), $request);
return $result;
}
diff --git a/eywa/Http/Routing/Router.php b/eywa/Http/Routing/Router.php
index 39102c7..7e48f1d 100755
--- a/eywa/Http/Routing/Router.php
+++ b/eywa/Http/Routing/Router.php
@@ -28,7 +28,7 @@ namespace Eywa\Http\Routing {
* The request method
*
*/
- private string $method = GET;
+ private string $method;
/**
@@ -64,7 +64,7 @@ namespace Eywa\Http\Routing {
$this->method = $request->method();
- $this->call_middleware($request);
+ $this->callMiddleware($request);
}
/**
@@ -78,13 +78,21 @@ namespace Eywa\Http\Routing {
*/
public function run(): Response
{
- foreach ((new Sql(connect(SQLITE, base('routes', 'web.sqlite3')), 'routes'))->where('method', EQUAL, $this->method)->get() as $route) {
+ foreach (
+ (new Sql(
+ connect(
+ SQLITE,
+ base('routes', 'web.sqlite3')
+ ),
+ 'routes'
+ ))->where('method', EQUAL, $this->method)->get() as $route
+ ) {
if ($this->match($route->url, $route)) {
$this->route = $route;
return $this->result()->call();
}
}
- return $this->not_found();
+ return $this->notFound();
}
@@ -93,7 +101,13 @@ namespace Eywa\Http\Routing {
*/
public function result(): RouteResult
{
- return new RouteResult($this->route->controller, $this->route->directory, $this->route->action, $this->parameters, $this->method);
+ return new RouteResult(
+ $this->route->controller,
+ $this->route->directory,
+ $this->route->action,
+ $this->parameters,
+ $this->method
+ );
}
/**
@@ -149,7 +163,7 @@ namespace Eywa\Http\Routing {
* @throws Kedavra
*
*/
- private function not_found(): Response
+ private function notFound(): Response
{
return (new RedirectResponse(route('404')))->send();
}
@@ -166,28 +180,49 @@ namespace Eywa\Http\Routing {
* @throws ReflectionException
*
*/
- private function call_middleware(ServerRequest $request): void
+ private function callMiddleware(ServerRequest $request): void
{
$middleware_dir = 'Middleware';
- $namespace = 'App' . '\\' . $middleware_dir . '\\';
$dir = base('app', $middleware_dir);
- is_false(is_dir($dir), true, "The $dir directory was not found");
-
- $middle = files(base('app', $middleware_dir, '*.php'));
+ is_false(is_dir($dir), true, sprintf('The %s directory has not been found', $dir));
+
+ $middle = array_merge(
+ files(
+ base(
+ 'app',
+ $middleware_dir,
+ '*.php'
+ )
+ ),
+ files(
+ base(
+ 'app',
+ $middleware_dir,
+ '*',
+ '*.php'
+ )
+ )
+ );
call_user_func_array([ new CsrfMiddleware(), 'check' ], [ $request ]);
foreach ($middle as $middleware) {
- $middle = collect(explode(DIRECTORY_SEPARATOR, $middleware))->last();
-
- $middleware = collect(explode('.', $middle))->first();
-
- $class = "$namespace$middleware";
-
- $x = new ReflectionClass($class);
+ $middle = '\\' . strval(collect(explode('.', strval(collect(
+ explode(
+ DIRECTORY_SEPARATOR,
+ strval(
+ strstr(
+ $middleware,
+ 'app'
+ )
+ )
+ )
+ )->for('ucfirst')->join('\\'))))->first());
+
+ $x = new ReflectionClass($middle);
$x->getMethod('check')->invoke($x->newInstance(), $request);
diff --git a/eywa/Http/Server/Http.php b/eywa/Http/Server/Http.php
index f8fed48..26cf5d2 100644
--- a/eywa/Http/Server/Http.php
+++ b/eywa/Http/Server/Http.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Http\Server {
@@ -51,7 +50,7 @@ namespace Eywa\Http\Server {
/**
* @return int
*/
- public function run():int
+ public function run(): int
{
$this->io->title('Starting the development server');
$this->io->success(sprintf('The server is running and listen at %s', $this->url));
diff --git a/eywa/Http/View/View.php b/eywa/Http/View/View.php
index 4bc3a35..87f80ce 100755
--- a/eywa/Http/View/View.php
+++ b/eywa/Http/View/View.php
@@ -78,9 +78,15 @@ namespace Eywa\Http\View {
* @throws Exception
*
*/
- public function __construct(string $view, string $title, string $description, array $args = [], string $layout = 'layout.php', string $directory='')
- {
- $x = collect(explode('.', $view))->first() .'.php';
+ public function __construct(
+ string $view,
+ string $title,
+ string $description,
+ array $args = [],
+ string $layout = 'layout.php',
+ string $directory = ''
+ ) {
+ $x = collect(explode('.', $view))->first() . '.html';
$this->view = def($directory) ? base('app', 'Views', $directory, $x) : base('app', 'Views', $x);
@@ -89,7 +95,15 @@ namespace Eywa\Http\View {
if (!is_dir(base('cache', $directory))) {
mkdir(base('cache', $directory));
}
- is_true(not_def($view, $title, $description), true, "You must have defined the view name, the view title and the view desccription");
+ is_true(
+ not_def(
+ $view,
+ $title,
+ $description
+ ),
+ true,
+ "You must have defined the view name, the view title and the view desccription"
+ );
if (!file_exists($this->view)) {
touch($this->view);
@@ -131,7 +145,14 @@ namespace Eywa\Http\View {
return ltrim(strval(ob_get_clean()));
}
- is_false(file_exists($this->layout), true, sprintf('The %s file has not been found inside the Views directory', $this->layout));
+ is_false(
+ file_exists($this->layout),
+ true,
+ sprintf(
+ 'The %s file has not been found inside the Views directory',
+ $this->layout
+ )
+ );
ob_start();
@@ -154,60 +175,332 @@ namespace Eywa\Http\View {
$html = ltrim(strval(ob_get_clean()));
$this
- ->replace('#{{ ([\$a-zA-Z-0-9\_]+) }}#', '<?= htmlentities($${1},ENT_QUOTES,"UTF-8");?>', $html, $html)
- ->replace('#@print\((\$[a-zA-Z-0-9\_]+)\)#', '<?= html_entity_decode(${1},ENT_QUOTES,"UTF-8");?>', $html, $html)
- ->replace('#{{ (\$[\$a-zA-Z-0-9\_]+)->([a-zA-Z0-9\_]+) }}#', '<?= htmlentities(${1}->${2},ENT_QUOTES,"UTF-8");?>', $html, $html)
- ->replace('#@admin#', '<?php if((new \Eywa\Security\Authentication\Auth(new \Eywa\Session\Session()))->is(\'admin\')) : ?>', $html, $html)
- ->replace('#@url\(\'([a-zA-Z0-9\-\/]+)\'\)#', '<?php if(equal(\Eywa\Http\Request\ServerRequest::generate()->url(),\'${1}\')) : ?>', $html, $html)
- ->replace('#@trans\(([a-zA-Z0-9\-\/]+)\)#', '<?= _("${1}"); ?>', $html, $html)
- ->replace('#@redac#', '<?php if((new \Eywa\Security\Authentication\Auth(new \Eywa\Session\Session()))->is(\'redac\')) :?>', $html, $html)
- ->replace('#@print\(([a-zA-Z0-9 ]+)\)#', '<?= html_entity_decode($${1},ENT_QUOTES,"UTF-8");?>', $html, $html)
- ->replace('#@d\((\$[a-zA-Z0-9 ]+)\)#', '<?= (new \Eywa\Debug\Dumper())->dump($${1});?>', $html, $html)
- ->replace('#@if\((\$[a-zA-Z0-9\-> == ]+)\)#', '<?php if(${1}) :?>', $html, $html)
- ->replace('#@elseif\(([\$a-zA-Z0-9]+)\)#', '<?php elseif ($${1}) :?>', $html, $html)
- ->replace('#@continue\((\$[a-zA-Z0-9\-> ==]+)\)#', '<?php if(${1}) { continue; }?>', $html, $html)
- ->replace('#@continue#', '<?php continue; ?>', $html, $html)
- ->replace('#@exit\((\$[a-zA-Z0-9\-> ==]+)\)#', '<?php if(${1}) { break; }?>', $html, $html)
- ->replace('#@exit#', '<?php break; ?>', $html, $html)
- ->replace('#@else#', '<?php else :?>', $html, $html)
- ->replace('#@endif#', '<?php endif;?>', $html, $html)
- ->replace('#@navigation#', '<?= (new \Eywa\Html\Navigation\Navigation())->display();?>', $html, $html)
- ->replace('#@foreach\((\$[a-zA-Z0-9]+) as (\$[a-z0-9]+)\)#', '<?php foreach(${1} ?? [] as ${2}) : ?>', $html, $html)
- ->replace('#@link\(([a-zA-Z-0-9]+):([a-zA-Z0-9]+):([a-zA-Z0-9]+)\)#', '<a href="<?= route(\'${1}\')?>" class="${3}">${2}</a>', $html, $html)
- ->replace('#@endforeach#', '<?php endforeach; ?>', $html, $html)
- ->replace('#@switch\(([\$a-zA-Z0-9]+)\)#', '<?php switch($${1}): ', $html, $html)
- ->replace('#@case\(([\$a-zA-Z]+)\)#', 'case "${1}" : ?>', $html, $html)
- ->replace('#@flash#', '<?= flash(); ?>', $html, $html)
- ->replace('#@ago\(([0-9\-]+)\)#', '<?= ago("${1}"); ?>', $html, $html)
- ->replace('#@alert\(([a-zA-Z0-9\_\- ]+),([\$a-zA-Z0-9\_ ]+)\)#', '<div class="alert ${1}">${2}</div>', $html, $html)
- ->replace('#@case\(([0-9]+)\)#', 'case ${1} : ?>', $html, $html)
- ->replace('#@break#', '<?php break; ?>', $html, $html)
- ->replace('#@default#', '<?php default : ?>', $html, $html)
- ->replace('#@logged#', '<?php if(logged()) :?>', $html, $html)
- ->replace('#@history#', '<?= history() ; ?>', $html, $html)
- ->replace('#@mobile#', '<?php if(app()->detect()->mobile()) :?>', $html, $html)
- ->replace('#@tablet#', '<?php if(app()->detect()->tablet()) :?>', $html, $html)
- ->replace('#@desktop#', '<?php if(app()->detect()->desktop()) :?>', $html, $html)
- ->replace('#@windows#', '<?php if(app()->detect()->windows()) :?>', $html, $html)
- ->replace('#@apple#', '<?php if( ! app()->detect()->windows() && ! app()->detect()->linux()) :?>', $html, $html)
- ->replace('#@linux#', '<?php if(app()->detect()->linux()) :?>', $html, $html)
- ->replace('#@guest#', '<?php if(guest()) :?>', $html, $html)
- ->replace('#@endlogged#', '<?php endif;?>', $html, $html)
- ->replace('#@endlinux#', '<?php endif;?>', $html, $html)
- ->replace('#@endwindows#', '<?php endif;?>', $html, $html)
- ->replace('#@end#', '<?php endif;?>', $html, $html)
- ->replace('#@endadmin#', '<?php endif;?>', $html, $html)
- ->replace('#@endurl#', '<?php endif;?>', $html, $html)
- ->replace('#@endredac#', '<?php endif;?>', $html, $html)
- ->replace('#@endguest#', '<?php endif;?>', $html, $html)
- ->replace('#@unless\(([\$a-zA-Z0-9]+)\)#', '<?php if(is_false($${1})) :?>', $html, $html)
- ->replace('#@endunless#', '<?php endif;?>', $html, $html)
- ->replace('#@endmobile#', '<?php endif;?>', $html, $html)
- ->replace('#@endtablet#', '<?php endif;?>', $html, $html)
- ->replace('#@enddesktop#', '<?php endif;?>', $html, $html)
- ->replace('#@css\(([a-zA-Z0-9]+)\)#', '<?= (new \Eywa\\File\Assets("css","${1}.css"))->make();?>', $html, $html)
- ->replace('#@js\(([a-zA-Z0-9]+)\)#', '<?= (new \Eywa\\File\Assets("js","${1}.js"))->make();?>', $html, $html)
- ->replace('#@endswitch#', '<?php endswitch ; ?>', $html, $html);
+ ->replace(
+ '#{{ ([\$a-zA-Z-0-9\_]+) }}#',
+ '<?= htmlentities($${1},ENT_QUOTES,"UTF-8");?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@print\((\$[a-zA-Z-0-9\_]+)\)#',
+ '<?= html_entity_decode(${1},ENT_QUOTES,"UTF-8");?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#{{ (\$[\$a-zA-Z-0-9\_]+)->([a-zA-Z0-9\_]+) }}#',
+ '<?= htmlentities(${1}->${2},ENT_QUOTES,"UTF-8");?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@admin#',
+ '<?php
+ if((new \Eywa\Security\Authentication\Auth(new \Eywa\Session\Session()))->is(\'admin\')) : ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@url\(\'([a-zA-Z0-9\-\/]+)\'\)#',
+ '<?php if(equal(\Eywa\Http\Request\ServerRequest::generate()->url(),\'${1}\')) : ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@trans\(([a-zA-Z0-9\-\/]+)\)#',
+ '<?= _("${1}"); ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@redac#',
+ '<?php
+ if((new \Eywa\Security\Authentication\Auth(new \Eywa\Session\Session()))->is(\'redac\')) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@print\(([a-zA-Z0-9 ]+)\)#',
+ '<?= html_entity_decode($${1},ENT_QUOTES,"UTF-8");?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@d\((\$[a-zA-Z0-9 ]+)\)#',
+ '<?= (new \Eywa\Debug\Dumper())->dump($${1});?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@if\((\$[a-zA-Z0-9\-> == ]+)\)#',
+ '<?php if(${1}) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@elseif\(([\$a-zA-Z0-9]+)\)#',
+ '<?php elseif ($${1}) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@continue\((\$[a-zA-Z0-9\-> ==]+)\)#',
+ '<?php if(${1}) { continue; }?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@continue#',
+ '<?php continue; ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@exit\((\$[a-zA-Z0-9\-> ==]+)\)#',
+ '<?php if(${1}) { break; }?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@exit#',
+ '<?php break; ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@else#',
+ '<?php else :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endif#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@navigation#',
+ '<?= (new \Eywa\Html\Navigation\Navigation())->display();?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@foreach\((\$[a-zA-Z0-9]+) as (\$[a-z0-9]+)\)#',
+ '<?php foreach(${1} ?? [] as ${2}) : ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@link\(([a-zA-Z-0-9]+):([a-zA-Z0-9]+):([a-zA-Z0-9]+)\)#',
+ '<a href="<?= route(\'${1}\')?>" class="${3}">${2}</a>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endforeach#',
+ '<?php endforeach; ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@switch\(([\$a-zA-Z0-9]+)\)#',
+ '<?php switch($${1}): ',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@case\(([\$a-zA-Z]+)\)#',
+ 'case "${1}" : ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@flash#',
+ '<?= flash(); ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@ago\(([0-9\-]+)\)#',
+ '<?= ago("${1}"); ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@alert\(([a-zA-Z0-9\_\- ]+),([\$a-zA-Z0-9\_ ]+)\)#',
+ '<div class="alert ${1}">${2}</div>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@case\(([0-9]+)\)#',
+ 'case ${1} : ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@break#',
+ '<?php break; ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@default#',
+ '<?php default : ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@logged#',
+ '<?php if(logged()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@history#',
+ '<?= history() ; ?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@mobile#',
+ '<?php if(app()->detect()->mobile()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@tablet#',
+ '<?php if(app()->detect()->tablet()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@desktop#',
+ '<?php if(app()->detect()->desktop()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@windows#',
+ '<?php if(app()->detect()->windows()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@apple#',
+ '<?php if( ! app()->detect()->windows() && ! app()->detect()->linux()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@linux#',
+ '<?php if(app()->detect()->linux()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@guest#',
+ '<?php if(guest()) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endlogged#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endlinux#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endwindows#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@end#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endadmin#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endurl#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endredac#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endguest#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@unless\(([\$a-zA-Z0-9]+)\)#',
+ '<?php if(is_false($${1})) :?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endunless#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endmobile#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endtablet#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@enddesktop#',
+ '<?php endif;?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@css\(([a-zA-Z0-9]+)\)#',
+ '<?= (new \Eywa\\File\Assets("css","${1}.css"))->make();?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@js\(([a-zA-Z0-9]+)\)#',
+ '<?= (new \Eywa\\File\Assets("js","${1}.js"))->make();?>',
+ $html,
+ $html
+ )
+ ->replace(
+ '#@endswitch#',
+ '<?php endswitch ; ?>',
+ $html,
+ $html
+ );
$html = collect(explode("\n", collect(explode(' ', $html))->join('')))->join('');
diff --git a/eywa/Ioc/Container.php b/eywa/Ioc/Container.php
index d4acff2..e0bfeaf 100755
--- a/eywa/Ioc/Container.php
+++ b/eywa/Ioc/Container.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Ioc {
/**
diff --git a/eywa/Ioc/Ioc.php b/eywa/Ioc/Ioc.php
index 0a625ab..f4d02c5 100755
--- a/eywa/Ioc/Ioc.php
+++ b/eywa/Ioc/Ioc.php
@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Eywa\Ioc {
- use Eywa\Collection\Collect;
use Eywa\Database\Connexion\Connect;
use Eywa\Exception\Kedavra;
use ReflectionClass;
@@ -21,7 +20,7 @@ namespace Eywa\Ioc {
* All instances
*
*/
- private static array $instances =[];
+ private static array $instances = [];
/**
*
@@ -51,20 +50,6 @@ namespace Eywa\Ioc {
/**
*
- * @return Collect
- *
- * @throws Kedavra
- * @throws ReflectionException
- *
- */
- public static function list():Collect
- {
- self::make();
- return collect()->put('variables', self::$variables)->put('instances', self::$instances);
- }
-
- /**
- *
* @param string $key
* @param array $args
*
@@ -122,6 +107,9 @@ namespace Eywa\Ioc {
*/
public function set(string $key, $value): Ioc
{
+ if (array_key_exists($key, self::$variables)) {
+ return $this;
+ }
self::$variables[$key] = $value;
return $this;
@@ -143,7 +131,18 @@ namespace Eywa\Ioc {
$filename = function (array $data) {
return $data['filename'];
};
- $container = '\\'.collect(explode(DIRECTORY_SEPARATOR, strval(strstr($container, '/ioc'))))->shift()->for('ucfirst')->for('pathinfo')->for($filename)->join('\\');
+ $container = '\\' .
+ collect(
+ explode(
+ DIRECTORY_SEPARATOR,
+ strval(
+ strstr(
+ $container,
+ '/ioc'
+ )
+ )
+ )
+ )->shift()->for('ucfirst')->for('pathinfo')->for($filename)->join('\\');
$x = new ReflectionClass($container);
@@ -152,10 +151,27 @@ namespace Eywa\Ioc {
$x = new ReflectionClass($extern_container);
- self::$instances = array_merge(self::$instances, $x->getMethod('instances')->invoke($x->newInstance()));
- self::$variables = array_merge(self::$variables, $x->getMethod('variables')->invoke($x->newInstance()));
-
- self::$instances[Connect::class] = equal(config('mode', 'connexion'), 'prod') ? production() : development();
+ self::$instances = array_merge(
+ self::$instances,
+ $x->getMethod('instances')
+ ->invoke(
+ $x->newInstance()
+ )
+ );
+ self::$variables = array_merge(
+ self::$variables,
+ $x->getMethod('variables')
+ ->invoke(
+ $x->newInstance()
+ )
+ );
+
+ self::$instances[Connect::class] =
+ equal(config('mode', 'connexion'), 'prod')
+ ?
+ production()
+ :
+ development();
self::$variables['faker'] = faker(strval(config('i18n', 'locale')));
}
@@ -198,97 +214,116 @@ namespace Eywa\Ioc {
* @return object
*
* @throws ReflectionException
+ * @throws Kedavra
*
*/
- private static function parse(string $key, array $args =[]): object
+ private static function parse(string $key, array $args = []): object
{
- $reflection = new ReflectionClass($key);
- $constructor = $reflection->getConstructor();
- $youldlike_parameters = !is_null($constructor) ? $constructor->getParameters() : [] ;
-
- /**
- *
- * Capture all class
- *
- * @param ReflectionParameter $parameter
- *
- * @return string
- *
- */
- $capture = function (ReflectionParameter $parameter) {
- $x = $parameter->getClass();
- return is_null($x)? $parameter->getName() : $x->getName();
- };
-
-
- /**
- *
- * Get the instance for a key
- *
- * @param string $key
- *
- * @return object
- *
- */
- $parse = function (string $key) use ($capture,$args) {
+
+ if (class_exists($key)) {
$reflection = new ReflectionClass($key);
$constructor = $reflection->getConstructor();
$youldlike_parameters = !is_null($constructor) ? $constructor->getParameters() : [] ;
- $all = collect();
- foreach ($youldlike_parameters as $parameter) {
- $current = call_user_func_array($capture, [$parameter]);
-
- if (class_exists($current)) {
- if (self::has($current)) {
- $all->push(self::get($current));
- }
- } else {
- if (array_key_exists($current, $args)) {
- $all->push($args[$current]);
+ /**
+ *
+ * Capture all class
+ *
+ * @param ReflectionParameter $parameter
+ *
+ * @return string
+ *
+ */
+ $capture = function (ReflectionParameter $parameter) {
+ $x = $parameter->getClass();
+ return is_null($x) ? $parameter->getName() : $x->getName();
+ };
+
+
+ /**
+ *
+ * Get the instance for a key
+ *
+ * @param string $key
+ *
+ * @return object
+ *
+ */
+ $parse = function (string $key) use ($capture, $args) {
+ $reflection = new ReflectionClass($key);
+ $constructor = $reflection->getConstructor();
+ $youldlike_parameters = !is_null($constructor) ? $constructor->getParameters() : [] ;
+ $all = collect();
+ foreach ($youldlike_parameters as $parameter) {
+ $current = call_user_func_array($capture, [$parameter]);
+
+
+ if (class_exists($current)) {
+ if (self::has($current)) {
+ $all->push(self::get($current));
+ }
} else {
- throw new Kedavra(sprintf('The %s parameter has not been found in the container', $current));
+ if (array_key_exists($current, $args)) {
+ $all->push($args[$current]);
+ } else {
+ throw new Kedavra(
+ sprintf(
+ 'The %s parameter has not been found in the container',
+ $current
+ )
+ );
+ }
}
}
- }
- return $reflection->newInstanceArgs($all->all());
- };
-
- /**
- *
- * Add a new instance
- *
- * @param string $key
- *
- * @return mixed
- *
- */
- $add = function (string $key) use ($parse) {
- if (self::has($key)) {
- return self::get($key);
- }
+ return $reflection->newInstanceArgs($all->all());
+ };
+
+ /**
+ *
+ * Add a new instance
+ *
+ * @param string $key
+ *
+ * @return mixed
+ *
+ */
+ $add = function (string $key) use ($parse) {
+ if (self::has($key)) {
+ return self::get($key);
+ }
- return call_user_func_array($parse, [$key]);
- };
-
- /**
- *
- * Save instance and return it
- *
- * @param array $classes
- *
- * @return object
- *
- */
- $instance = function (array $classes) use ($key) {
- $reflection = new ReflectionClass($key);
+ return call_user_func_array($parse, [$key]);
+ };
+
+ /**
+ *
+ * Save instance and return it
+ *
+ * @param array $classes
+ *
+ * @return object
+ *
+ */
+ $instance = function (array $classes) use ($key) {
+ $reflection = new ReflectionClass($key);
- self::$instances[$key] = $reflection->newInstanceArgs($classes);
+ self::$instances[$key] = $reflection->newInstanceArgs($classes);
+
+ return self::get($key);
+ };
+ return call_user_func_array(
+ $instance,
+ [collect($youldlike_parameters)
+ ->for($capture)->for($add)->all()]
+ );
+ }
+
+ if (self::has($key)) {
return self::get($key);
- };
+ }
- return call_user_func_array($instance, [collect($youldlike_parameters)->for($capture)->for($add)->all()]);
+ throw new Kedavra(sprintf('The %s parameter has not been found in the container', $key));
}
}
}
diff --git a/eywa/Message/Email/Write.php b/eywa/Message/Email/Write.php
index e250fdf..6874806 100755
--- a/eywa/Message/Email/Write.php
+++ b/eywa/Message/Email/Write.php
@@ -46,7 +46,10 @@ namespace Eywa\Message\Email {
$file = 'mail';
- $this->transport = (new Swift_SmtpTransport(config($file, 'smtp'), config($file, 'port')))->setUsername(config($file, 'username'))->setPassword(config($file, 'password'));
+ $this->transport = (new Swift_SmtpTransport(
+ config($file, 'smtp'),
+ config($file, 'port')
+ ))->setUsername(config($file, 'username'))->setPassword(config($file, 'password'));
$this->message = new Swift_Message();
@@ -60,7 +63,9 @@ namespace Eywa\Message\Email {
$this->mailer = new Swift_Mailer($this->transport);
- config($file, 'html') ? $this->message->setBody(message($message), 'text/html', 'utf-8') : $this->message->setBody($message, 'text/plain', 'utf-8');
+ config($file, 'html')
+ ? $this->message->setBody(message($message), 'text/html', 'utf-8')
+ : $this->message->setBody($message, 'text/plain', 'utf-8');
$this->private_key = (new File(base() . DIRECTORY_SEPARATOR . 'dkim.private.key'))->read();
}
@@ -73,10 +78,15 @@ namespace Eywa\Message\Email {
*
*
*/
- public function sign() : Write
+ public function sign(): Write
{
$file = 'mail';
- $signer = new Swift_Signers_DKIMSigner($this->private_key, config($file, 'domain'), config($file, 'selector'), config($file, 'passphrase'));
+ $signer = new Swift_Signers_DKIMSigner(
+ $this->private_key,
+ config($file, 'domain'),
+ config($file, 'selector'),
+ config($file, 'passphrase')
+ );
$this->message->attachSigner($signer);
return $this;
@@ -91,10 +101,12 @@ namespace Eywa\Message\Email {
*
* @return Write
*/
- public function attach(string $path, string $filename, string $type, string $disposition = '') : Write
+ public function attach(string $path, string $filename, string $type, string $disposition = ''): Write
{
if (def($disposition)) {
- $this->message->attach(Swift_Attachment::fromPath($path, $type)->setFilename($filename)->setDisposition($disposition));
+ $this->message->attach(Swift_Attachment::fromPath($path, $type)
+ ->setFilename($filename)
+ ->setDisposition($disposition));
} else {
$this->message->attach(Swift_Attachment::fromPath($path, $type)->setFilename($filename));
}
@@ -109,10 +121,15 @@ namespace Eywa\Message\Email {
* @throws Kedavra
* @return bool
*/
- public static function valid(string ...$emails) : bool
+ public static function valid(string ...$emails): bool
{
foreach ($emails as $email) {
- is_false((new EmailValidator())->isValid($email, new RFCValidation()), true, "The email $email is not valid");
+ is_false(
+ (new EmailValidator())
+ ->isValid($email, new RFCValidation()),
+ true,
+ sprintf('%s is not a valid email', $email)
+ );
}
return true;
@@ -128,7 +145,7 @@ namespace Eywa\Message\Email {
* @return Write
*
*/
- public function cc(string $email, string $name = null) : Write
+ public function cc(string $email, string $name = null): Write
{
self::valid($email);
$this->message->setCc($email, $name);
@@ -146,7 +163,7 @@ namespace Eywa\Message\Email {
* @return Write
*
*/
- public function bcc(string $email, string $name = null) : Write
+ public function bcc(string $email, string $name = null): Write
{
self::valid($email);
@@ -165,7 +182,7 @@ namespace Eywa\Message\Email {
* @return Write
*
*/
- public function add_bcc(string $email, string $name = null) : Write
+ public function addBcc(string $email, string $name = null): Write
{
self::valid($email);
@@ -184,7 +201,7 @@ namespace Eywa\Message\Email {
* @return Write
*
*/
- public function add_cc(string $email, string $name = null) : Write
+ public function addCc(string $email, string $name = null): Write
{
self::valid($email);
@@ -203,7 +220,7 @@ namespace Eywa\Message\Email {
* @return Write
*
*/
- public function add_to(string $email, string $name = null) : Write
+ public function addTo(string $email, string $name = null): Write
{
self::valid($email);
@@ -215,7 +232,7 @@ namespace Eywa\Message\Email {
/**
* @return bool
*/
- public function send() : bool
+ public function send(): bool
{
return $this->mailer->send($this->message) !== 0;
}
diff --git a/eywa/Message/Flash/Flash.php b/eywa/Message/Flash/Flash.php
index 12692ad..7b7132c 100755
--- a/eywa/Message/Flash/Flash.php
+++ b/eywa/Message/Flash/Flash.php
@@ -36,7 +36,9 @@ namespace Eywa\Message\Flash {
$this->destroy([$key]);
if (def($message)) {
- return $success ? '<div class="'.$success_class.'" role="alert">'.$message.'</div>':'<div class="'.$failure_class.'" role="alert">'.$message.'</div>';
+ return $success
+ ? '<div class="' . $success_class . '" role="alert">' . $message . '</div>'
+ : '<div class="' . $failure_class . '" role="alert">' . $message . '</div>';
}
}
return $result;
diff --git a/eywa/Security/Authentication/Auth.php b/eywa/Security/Authentication/Auth.php
index f45283b..fb0cb8e 100755
--- a/eywa/Security/Authentication/Auth.php
+++ b/eywa/Security/Authentication/Auth.php
@@ -1,165 +1,175 @@
<?php
+
declare(strict_types=1);
- namespace Eywa\Security\Authentication
+namespace Eywa\Security\Authentication
+{
+
+ use Eywa\Collection\Collect;
+ use Eywa\Database\Model\Model;
+ use Eywa\Exception\Kedavra;
+ use Eywa\Http\Response\RedirectResponse;
+ use Eywa\Http\Response\Response;
+ use Eywa\Message\Flash\Flash;
+ use Eywa\Session\SessionInterface;
+ use ReflectionClass;
+ use stdClass;
+
+ /**
+ *
+ * Class Auth
+ *
+ * @package Eywa\Security\Authentication
+ *
+ */
+ class Auth implements AuthInterface
{
-
- use App\Models\User;
- use Eywa\Collection\Collect;
- use Eywa\Exception\Kedavra;
- use Eywa\Http\Response\RedirectResponse;
- use Eywa\Http\Response\Response;
- use Eywa\Message\Flash\Flash;
- use Eywa\Session\SessionInterface;
- use stdClass;
+ /**
+ * @var Model
+ */
+ private static Model $model;
/**
*
- * Class Auth
- *
- * @package Eywa\Security\Authentication
+ * The session
*
*/
- class Auth implements AuthInterface
+ private SessionInterface $session;
+
+ /**
+ * @inheritDoc
+ */
+ public function __construct(SessionInterface $session, string $model)
{
+ $this->session = $session;
+ is_false(class_exists($model), true, 'The model not exist');
- /**
- *
- * The session
- *
- */
- private SessionInterface $session;
-
- /**
- * @inheritDoc
- */
- public function __construct(SessionInterface $session)
- {
- $this->session = $session;
- }
+ $model = new ReflectionClass($model);
+ static::$model = $model->getMethod('instance')->invoke($model->newInstance());
+ }
- /**
- * @inheritDoc
- */
- public function connected(): bool
- {
- return $this->session->has('user');
- }
+ /**
+ * @inheritDoc
+ */
+ public function connected(): bool
+ {
+ return $this->session->has('user');
+ }
- /**
- * @inheritDoc
- */
- public function is(string $role): bool
- {
- if ($this->connected()) {
- switch ($role) {
- case 'admin':
- return $this->current()->id == '1';
- case 'redac':
- return in_array($this->current()->id, ['1','2'], true);
- default:
- return false;
- }
+ /**
+ * @inheritDoc
+ */
+ public function is(string $role): bool
+ {
+ if ($this->connected()) {
+ switch ($role) {
+ case 'admin':
+ return $this->current()->id == '1';
+ case 'redac':
+ return in_array($this->current()->id, ['1','2'], true);
+ default:
+ return false;
}
- return false;
}
+ return false;
+ }
- /**
- * @inheritDoc
- */
- public function clean(): bool
- {
- return $this->session->destroy(['user']);
- }
+ /**
+ * @inheritDoc
+ */
+ public function clean(): bool
+ {
+ return $this->session->destroy(['user']);
+ }
- /**
- * @inheritDoc
- */
- public function current(): stdClass
- {
- return $this->session->has('user') ? unserialize($this->session->get('user')) : new stdClass();
- }
+ /**
+ * @inheritDoc
+ */
+ public function current(): stdClass
+ {
+ return $this->session->has('user') ? unserialize($this->session->get('user')) : new stdClass();
+ }
- /**
- * @inheritDoc
- */
- public function login(string $username, string $password): Response
- {
- try {
- $user = User::by('username', $username);
- } catch (Kedavra $kedavra) {
- return $this->redirect('/login', alert([$this->messages()->get('user_not_found')]));
- }
+ /**
+ * @inheritDoc
+ */
+ public function login(string $username, string $password): Response
+ {
+ try {
+ $user = static::$model::by('username', $username);
+ } catch (Kedavra $kedavra) {
+ return $this->redirect('/login', alert([$this->messages()->get('user_not_found')]));
+ }
- if (def($user)) {
- if (check($password, $user->password)) {
- $this->session->set('user', serialize($user));
- return $this->redirect('/home', alert([ $this->messages()->get('welcome')], true), true);
- } else {
- $this->clean();
+ if (def($user)) {
+ if (check($password, $user->password)) {
+ $this->session->set('user', serialize($user));
+ return $this->redirect('/home', alert([ $this->messages()->get('welcome')], true), true);
+ } else {
+ $this->clean();
- return $this->redirect('/login', alert([$this->messages()->get('password_no_match')]));
- }
+ return $this->redirect('/login', alert([$this->messages()->get('password_no_match')]));
}
-
- return $this->redirect('/login', alert([$this->messages()->get('user_not_found')]));
}
- /**
- * @inheritDoc
- */
- public function logout(): Response
- {
- $this->clean();
+ return $this->redirect('/login', alert([$this->messages()->get('user_not_found')]));
+ }
- return $this->redirect('/', $this->messages()->get('bye'), true);
- }
+ /**
+ * @inheritDoc
+ */
+ public function logout(): Response
+ {
+ $this->clean();
- /**
- * @inheritDoc
- */
- public function delete_account(): Response
- {
- if ($this->connected()) {
- if (User::destroy(intval($this->current()->id))) {
- return $this->redirect('/', $this->messages()->get('account_removed_successfully'), true);
- }
- return $this->redirect('/', $this->messages()->get('account_removed_fail'));
- }
+ return $this->redirect('/', $this->messages()->get('bye'), true);
+ }
- return $this->redirect('/', $this->messages()->get('not_connected'));
+ /**
+ * @inheritDoc
+ */
+ public function deleteAccount(): Response
+ {
+ if ($this->connected()) {
+ if (static::$model::destroy(intval($this->current()->id))) {
+ return $this->redirect('/', $this->messages()->get('account_removed_successfully'), true);
+ }
+ return $this->redirect('/', $this->messages()->get('account_removed_fail'));
}
- /**
- *
- * Get all messages
- *
- * @return Collect
- *
- * @throws Kedavra
- *
- */
- private function messages(): Collect
- {
- return collect(config('auth', 'messages'));
- }
+ return $this->redirect('/', $this->messages()->get('not_connected'));
+ }
- /**
- *
- * Get all messages
- *
- * @param string $url
- * @param string $message
- * @param bool $success
- * @return Response
- *
- * @throws Kedavra
- */
- private function redirect(string $url, string $message, bool $success = false): Response
- {
- $success ? (new Flash())->set(SUCCESS, $message) : (new Flash())->set(FAILURE, $message);
-
- return (new RedirectResponse($url))->send();
- }
+ /**
+ *
+ * Get all messages
+ *
+ * @return Collect
+ *
+ * @throws Kedavra
+ *
+ */
+ private function messages(): Collect
+ {
+ return collect(config('auth', 'messages'));
+ }
+
+ /**
+ *
+ * Get all messages
+ *
+ * @param string $url
+ * @param string $message
+ * @param bool $success
+ * @return Response
+ *
+ * @throws Kedavra
+ */
+ private function redirect(string $url, string $message, bool $success = false): Response
+ {
+ $success ? (new Flash())->set(SUCCESS, $message) : (new Flash())->set(FAILURE, $message);
+
+ return (new RedirectResponse($url))->send();
}
}
+}
diff --git a/eywa/Security/Authentication/AuthInterface.php b/eywa/Security/Authentication/AuthInterface.php
index f4794b1..29680ab 100644
--- a/eywa/Security/Authentication/AuthInterface.php
+++ b/eywa/Security/Authentication/AuthInterface.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Security\Authentication {
@@ -8,6 +9,7 @@ namespace Eywa\Security\Authentication {
use Eywa\Exception\Kedavra;
use Eywa\Http\Response\Response;
use Eywa\Session\SessionInterface;
+ use ReflectionException;
use stdClass;
interface AuthInterface
@@ -18,9 +20,13 @@ namespace Eywa\Security\Authentication {
* AuthInterface constructor.
*
* @param SessionInterface $session
+ * @param string $model
+ *
+ * @throws Kedavra
+ * @throws ReflectionException
*
*/
- public function __construct(SessionInterface $session);
+ public function __construct(SessionInterface $session, string $model);
/**
*
@@ -99,6 +105,6 @@ namespace Eywa\Security\Authentication {
*
*
*/
- public function delete_account(): Response;
+ public function deleteAccount(): Response;
}
}
diff --git a/eywa/Security/Crypt/Crypter.php b/eywa/Security/Crypt/Crypter.php
index 2aa46d7..2fea9ed 100755
--- a/eywa/Security/Crypt/Crypter.php
+++ b/eywa/Security/Crypt/Crypter.php
@@ -1,4 +1,5 @@
<?php
+
declare(strict_types=1);
namespace Eywa\Security\Crypt {
@@ -13,14 +14,14 @@ namespace Eywa\Security\Crypt {
* The encryption key.
*
*/
- private string $key ='';
+ private string $key;
/**
*
* The algorithm used for encryption.
*
*/
- private string $cipher = '';
+ private string $cipher ;
/**
* Create a new encrypter instance.
@@ -34,7 +35,7 @@ namespace Eywa\Security\Crypt {
$this->cipher = strtolower(strval(env('CIPHER', 'AES-128-CBC')));
- is_true(collect(openssl_get_cipher_methods())->not_exist($this->cipher), true, "The cipher is not valid");
+ is_true(collect(openssl_get_cipher_methods())->notExist($this->cipher), true, "The cipher is not valid");
}
@@ -49,7 +50,19 @@ namespace Eywa\Security\Crypt {
*/
public static function generateKey(): string
{
- return base64_encode(random_bytes(intval(openssl_cipher_iv_length(strtolower(strval(env('CIPHER', 'AES-128-CBC')))))));
+ return base64_encode(
+ random_bytes(
+ intval(
+ openssl_cipher_iv_length(
+ strtolower(
+ strval(
+ env('CIPHER', 'AES-128-CBC')
+ )
+ )
+ )
+ )
+ )
+ );
}
/**
@@ -163,7 +176,7 @@ namespace Eywa\Security\Crypt {
*
* @throws Exception
*/
- protected function getJsonPayload($payload):array
+ protected function getJsonPayload($payload): array
{
$payload = json_decode(base64_decode($payload), true);
@@ -186,7 +199,8 @@ namespace Eywa\Security\Crypt {
*/
protected function validPayload($payload)
{
- return is_array($payload) && isset($payload['iv'], $payload['value'], $payload['mac']) && strlen(strval(base64_decode($payload['iv'], true))) === openssl_cipher_iv_length($this->cipher);
+ return is_array($payload) && isset($payload['iv'], $payload['value'], $payload['mac'])
+ && strlen(strval(base64_decode($payload['iv'], true))) === openssl_cipher_iv_length($this->cipher);
}
/**
diff --git a/eywa/Security/Csrf/Csrf.php b/eywa/Security/Csrf/Csrf.php
index 395f735..191c56c 100755
--- a/eywa/Security/Csrf/Csrf.php
+++ b/eywa/Security/Csrf/Csrf.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Security\Csrf {
@@ -40,9 +39,19 @@ namespace Eywa\Security\Csrf {
{
is_false($this->session->has(CSRF_TOKEN), true, 'Csrf token was not found');
- is_true(different((new Crypter())->decrypt($this->session->get('server')), Request::make()->server()->get('SERVER_NAME', 'eywa')), true, 'Server is invalid');
+ is_true(
+ different(
+ (new Crypter())
+ ->decrypt(
+ $this->session->get('server')
+ ),
+ Request::make()->server()->get('SERVER_NAME', 'eywa')
+ ),
+ true,
+ 'Server is invalid'
+ );
- $this->remove_token();
+ $this->removeToken();
return true;
}
@@ -54,7 +63,7 @@ namespace Eywa\Security\Csrf {
* @return bool
*
*/
- public function remove_token(): bool
+ public function removeToken(): bool
{
return $this->session->destroy([CSRF_TOKEN]);
}
@@ -71,7 +80,15 @@ namespace Eywa\Security\Csrf {
return $this->session->get(CSRF_TOKEN);
}
- $server = $this->session->has('server') ? $this->session->get('server') : $this->session->set('server', (new Crypter())->encrypt(Request::make()->server()->get('SERVER_NAME', 'eywa')))->get('server');
+ $server = $this->session->has('server')
+ ? $this->session->get('server')
+ : $this->session->set(
+ 'server',
+ (new Crypter())->encrypt(
+ Request::make()->server()
+ ->get('SERVER_NAME', 'eywa')
+ )
+ )->get('server');
$x = bin2hex(random_bytes(16));
$csrf = $this->session->set('csrf', $x)->get('csrf');
diff --git a/eywa/Security/Hashing/Hash.php b/eywa/Security/Hashing/Hash.php
index 45609b3..277b34e 100755
--- a/eywa/Security/Hashing/Hash.php
+++ b/eywa/Security/Hashing/Hash.php
@@ -1,5 +1,7 @@
<?php
+
declare(strict_types=1);
+
namespace Eywa\Security\Hashing
{
@@ -76,7 +78,7 @@ namespace Eywa\Security\Hashing
* @return bool
*
*/
- public function valid(string $value) : bool
+ public function valid(string $value): bool
{
return hash_equals($this->valid, $value);
}
@@ -88,7 +90,7 @@ namespace Eywa\Security\Hashing
* @return string
*
*/
- public function generate() : string
+ public function generate(): string
{
return $this->valid;
}
diff --git a/eywa/Security/Middleware/CsrfMiddleware.php b/eywa/Security/Middleware/CsrfMiddleware.php
index 9efe42e..b6826da 100755
--- a/eywa/Security/Middleware/CsrfMiddleware.php
+++ b/eywa/Security/Middleware/CsrfMiddleware.php
@@ -1,6 +1,5 @@
<?php
-
namespace Eywa\Security\Middleware {
diff --git a/eywa/Session/ArraySession.php b/eywa/Session/ArraySession.php
index f306860..c32bdbf 100755
--- a/eywa/Session/ArraySession.php
+++ b/eywa/Session/ArraySession.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Session {
diff --git a/eywa/Session/Session.php b/eywa/Session/Session.php
index 44524e6..303d932 100755
--- a/eywa/Session/Session.php
+++ b/eywa/Session/Session.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Session {
diff --git a/eywa/Testing/Unit.php b/eywa/Testing/Unit.php
index c4ab22a..5619564 100755
--- a/eywa/Testing/Unit.php
+++ b/eywa/Testing/Unit.php
@@ -1,9 +1,11 @@
<?php
declare(strict_types=1);
+
namespace Eywa\Testing {
use Eywa\Collection\Collect;
+ use Eywa\Database\Model\Model;
use Eywa\Exception\Kedavra;
use Eywa\File\File;
use Eywa\Http\Request\ServerRequest;
@@ -31,7 +33,7 @@ namespace Eywa\Testing {
* @throws ReflectionException
*
*/
- public function visit(string $url, string $method = GET): Response
+ public function visit(string $url, string $method = GET): Response
{
return (new Router(new ServerRequest($url, $method)))->run();
}
@@ -52,12 +54,17 @@ namespace Eywa\Testing {
/**
*
+ *
+ * @param string $model
+ *
* @return Auth
*
+ * @throws Kedavra
+ *
*/
- public function auth(): Auth
+ public function auth(string $model): Auth
{
- return new Auth(new ArraySession());
+ return new Auth(new ArraySession(), $model);
}
/**
diff --git a/eywa/Time/Timing.php b/eywa/Time/Timing.php
index a4db871..3af0faa 100755
--- a/eywa/Time/Timing.php
+++ b/eywa/Time/Timing.php
@@ -1,6 +1,5 @@
<?php
-
declare(strict_types=1);
namespace Eywa\Time {
@@ -42,7 +41,7 @@ namespace Eywa\Time {
* @return int
*
*/
- public function check():int
+ public function check(): int
{
$this->end_time = now();
diff --git a/eywa/Validate/Validator.php b/eywa/Validate/Validator.php
index f40aac6..141e99b 100755
--- a/eywa/Validate/Validator.php
+++ b/eywa/Validate/Validator.php
@@ -59,6 +59,9 @@ namespace Eywa\Validate {
VALIDATOR_ARGUMENT_NOT_BETWEEN => '',
VALIDATOR_ARGUMENT_SUPERIOR_OF_MAX_VALUE => '',
VALIDATOR_ARGUMENT_SUPERIOR_MIN_OF_VALUE => '',
+ VALIDATOR_ARGUMENT_SLUG => '',
+ VALIDATOR_ARGUMENT_SNAKE => '',
+ VALIDATOR_ARGUMENT_CAMEL_CASE => '',
];
/**
* @var Request
@@ -104,7 +107,15 @@ namespace Eywa\Validate {
*/
public function call(): Response
{
- return static::$errors->empty() ? call_user_func_array([$this,'success'], [$this->request]) : call_user_func_array([$this,'error'], [static::$errors->all()]);
+ return static::$errors->empty()
+ ? call_user_func_array(
+ [$this, 'success'],
+ [$this->request]
+ )
+ : call_user_func_array(
+ [$this, 'error'],
+ [static::$errors->all()]
+ );
}
/**
@@ -120,7 +131,7 @@ namespace Eywa\Validate {
* @throws Kedavra
*
*/
- public function redirect(string $url, string $message, bool $success = true):Response
+ public function redirect(string $url, string $message, bool $success = true): Response
{
$success ? (new Flash())->set(SUCCESS, $message) : (new Flash())->set(FAILURE, $message);
@@ -160,19 +171,55 @@ namespace Eywa\Validate {
switch ($rule) {
case 'email':
if (!(new EmailValidator())->isValid($request->request()->get($k), new RFCValidation())) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_EMAIL_NOT_VALID], $k, strval($request->request()->get($k))));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_EMAIL_NOT_VALID],
+ $k,
+ strval($request->request()->get($k))
+ )
+ );
+ }
+ break;
+ case 'slug':
+ if (!is_slug($request->request()->get($k))) {
+ static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_SLUG], strval($k)));
+ }
+ break;
+
+ case 'snake':
+ if (!is_snake($request->request()->get($k))) {
+ static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_SNAKE], strval($k)));
+ }
+ break;
+ case 'camel':
+ if (!is_camel($request->request()->get($k))) {
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_CAMEL_CASE],
+ strval($k)
+ )
+ );
}
break;
case 'required':
if (not_def($request->request()->get($k))) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_NOT_DEFINED], strval($k)));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_NOT_DEFINED],
+ strval($k)
+ )
+ );
}
break;
case 'numeric':
-
$digit = $request->request()->get($k);
if (not_int($digit)) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_NOT_NUMERIC], strval($k)));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_NOT_NUMERIC],
+ strval($k)
+ )
+ );
}
break;
@@ -181,7 +228,13 @@ namespace Eywa\Validate {
$table = $x[1];
if (sql($table)->where($k, EQUAL, $request->request()->get($k))->exist()) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_NOT_UNIQUE], strval($k), strval($table)));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_NOT_UNIQUE],
+ strval($k),
+ strval($table)
+ )
+ );
}
break;
@@ -191,19 +244,31 @@ namespace Eywa\Validate {
$max = intval($x[1]);
$value = $request->request()->get($k);
if ($value < $min && $value > $max || not_def($value)) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_NOT_BETWEEN], strval($k), $min, $max));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_NOT_BETWEEN],
+ strval($k),
+ $min,
+ $max
+ )
+ );
}
break;
case preg_match('#max:([0-9]+)#', $rule) === 1:
-
$max = intval(collect(explode(':', $rule))->last());
$value = strval($request->request()->get($k));
$length = mb_strlen($value);
if ($length > $max) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_SUPERIOR_OF_MAX_VALUE], strval($k), $max));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_SUPERIOR_OF_MAX_VALUE],
+ strval($k),
+ $max
+ )
+ );
}
break;
@@ -214,7 +279,13 @@ namespace Eywa\Validate {
$length = mb_strlen($value);
if ($length < $min) {
- static::$errors->push(sprintf(static::$messages[VALIDATOR_ARGUMENT_SUPERIOR_MIN_OF_VALUE], strval($k), $min));
+ static::$errors->push(
+ sprintf(
+ static::$messages[VALIDATOR_ARGUMENT_SUPERIOR_MIN_OF_VALUE],
+ strval($k),
+ $min
+ )
+ );
}
break;
}
diff --git a/grumphp.yml b/grumphp.yml
index b49c753..90dd2ec 100755
--- a/grumphp.yml
+++ b/grumphp.yml
@@ -5,7 +5,7 @@ parameters:
ignore_unstaged_changes: false
stop_on_failure: true
tasks:
- phpcsfixer: ~
+ phpcs: ~
phpversion:
project: '7.4.2'
file_size:
diff --git a/helpers/admin.php b/helpers/admin.php
index 5cee77e..91132c6 100755
--- a/helpers/admin.php
+++ b/helpers/admin.php
@@ -2,7 +2,6 @@
declare(strict_types=1);
-
use Eywa\Application\App;
use Eywa\Configuration\Config;
use Eywa\Database\Connexion\Connect;
@@ -12,7 +11,6 @@ use Eywa\Exception\Kedavra;
use Eywa\File\File;
use Eywa\Http\Request\Request;
use Eywa\Ioc\Ioc;
-use Eywa\Security\Authentication\Auth;
use Eywa\Security\Hashing\Hash;
use Eywa\Session\Session;
use Faker\Factory;
@@ -21,7 +19,11 @@ use Whoops\Run;
if (!function_exists('controllers_directory')) {
/**
+ *
+ * List all controllers directories
+ *
* @return array
+ *
*/
function controllers_directory(): array
{
@@ -29,6 +31,21 @@ if (!function_exists('controllers_directory')) {
return is_bool($x) ? [] : collect($x)->del(['.','..'])->all();
}
}
+
+if (!function_exists('views')) {
+
+ /**
+ *
+ * List all views
+ *
+ * @return array
+ *
+ */
+ function views(): array
+ {
+ return array_merge(files(base('app', 'Views', '*.php')), files(base('app', 'Views', '*', '*.php')));
+ }
+}
if (!function_exists('only')) {
/**
*
@@ -39,7 +56,7 @@ if (!function_exists('only')) {
* @throws Kedavra
*
*/
- function https():bool
+ function https(): bool
{
return cli() ? false : Request::make()->secure();
}
@@ -96,7 +113,7 @@ if (!function_exists('files')) {
* @return array
*
*/
- function files(string $pattern):array
+ function files(string $pattern): array
{
$files = glob($pattern);
@@ -193,7 +210,13 @@ if (!function_exists('production')) {
*/
function production(): Connect
{
- return new Connect(strval(env('DB_DRIVER', 'mysql')), strval(env('DB_NAME', 'eywa')), strval(env('DB_USERNAME', 'eywa')), strval(env('DB_PASSWORD', 'eywa')), strval(env('DB_HOST', 'localhost')));
+ return new Connect(
+ strval(env('DB_DRIVER', 'mysql')),
+ strval(env('DB_NAME', 'eywa')),
+ strval(env('DB_USERNAME', 'eywa')),
+ strval(env('DB_PASSWORD', 'eywa')),
+ strval(env('DB_HOST', 'localhost'))
+ );
}
}
@@ -205,7 +228,13 @@ if (!function_exists('development')) {
*/
function development(): Connect
{
- return new Connect(strval(env('DEVELOP_DB_DRIVER', 'mysql')), strval(env('DEVELOP_DB_NAME', 'ikran')), strval(env('DEVELOP_DB_USERNAME', 'ikran')), strval(env('DEVELOP_DB_PASSWORD', 'ikran')), strval(env('DEVELOP_DB_HOST', 'localhost')));
+ return new Connect(
+ strval(env('DEVELOP_DB_DRIVER', 'mysql')),
+ strval(env('DEVELOP_DB_NAME', 'ikran')),
+ strval(env('DEVELOP_DB_USERNAME', 'ikran')),
+ strval(env('DEVELOP_DB_PASSWORD', 'ikran')),
+ strval(env('DEVELOP_DB_HOST', 'localhost'))
+ );
}
}
if (!function_exists('sql')) {
@@ -237,7 +266,7 @@ if (!function_exists('int')) {
* @return bool
*
*/
- function int($digit):bool
+ function int($digit): bool
{
if (is_int($digit)) {
return true;
@@ -259,7 +288,7 @@ if (!function_exists('not_int')) {
* @return bool
*
*/
- function not_int($digit):bool
+ function not_int($digit): bool
{
return ! int($digit);
}
@@ -350,7 +379,8 @@ if (!function_exists('history')) {
*/
function history(): string
{
- return '<button onclick="window.history.back()" class="' . config('history', 'class') . '">' . config('history', 'text') . '</button>';
+ return '<button onclick="window.history.back()"
+ class="' . config('history', 'class') . '">' . config('history', 'text') . '</button>';
}
}
@@ -470,6 +500,176 @@ if (!function_exists('is_false')) {
return $x;
}
}
+
+
+if (!function_exists('snake_to_camel')) {
+
+
+ /**
+ *
+ * Get a camelcase string format with snakecase format
+ *
+ * @param string $snake
+ *
+ * @return string
+ *
+ */
+ function snake_to_camel(string $snake): string
+ {
+ return collect(explode('_', $snake))->for('ucfirst')->join('');
+ }
+}
+
+if (!function_exists('camel_to_snake')) {
+
+
+ /**
+ *
+ * Get a snakecase string format with camelcase format
+ *
+ * @param string $snake
+ *
+ * @return string
+ *
+ */
+ function camel_to_snake(string $snake): string
+ {
+ return strtolower(strval(preg_replace('/(?<!^)[A-Z]/', '_$0', $snake)));
+ }
+}
+
+if (!function_exists('is_snake')) {
+
+
+ /**
+ *
+ * check if string is a snakecase
+ *
+ * @param string $snake
+ *
+ * @return bool
+ *
+ */
+ function is_snake(string $snake): bool
+ {
+ return preg_match("#^[a-z]([a-z_]+)$#", $snake) == 1;
+ }
+}
+
+if (!function_exists('is_slug')) {
+
+
+ /**
+ *
+ * check if string is a snakecase
+ *
+ * @param string $slug
+ *
+ * @return bool
+ *
+ */
+ function is_slug(string $slug): bool
+ {
+ return preg_match("#^[a-z]([a-z0-9\-]+)$#", $slug) == 1;
+ }
+}
+
+if (!function_exists('sluglify')) {
+
+
+ /**
+ *
+ * convert a sring in a slug
+ *
+ * @param string $slug
+ *
+ * @return string
+ *
+ */
+ function sluglify(string $slug): string
+ {
+ $space = function (string $x) {
+ return collect(explode(' ', $x))->for('trim')->for('strtolower')->join('-');
+ };
+
+ $point = function (string $point) {
+ $x = function ($x) {
+ return str_replace(
+ '__',
+ '_',
+ str_replace(
+ '-',
+ '_',
+ str_replace(
+ '--',
+ '_',
+ str_replace('.', '_', $x)
+ )
+ )
+ );
+ };
+
+ return collect(explode('_', call_user_func_array($x, [$point])))->join('-');
+ };
+ $comma = function (string $comma) {
+ $x = function ($x) {
+ return str_replace('-', '', str_replace(',', '_', $x));
+ };
+
+ return collect(explode('_', call_user_func_array($x, [$comma])))->join('-');
+ };
+
+ if (is_slug($slug)) {
+ return $slug;
+ }
+
+ if (def(strstr($slug, ' '))) {
+ $slug = call_user_func_array($space, [$slug]);
+ }
+
+
+ if (is_slug($slug)) {
+ return $slug;
+ }
+
+ if (def(strstr($slug, ','))) {
+ $slug = call_user_func_array($comma, [$slug]);
+ }
+
+ if (is_slug($slug)) {
+ return $slug;
+ }
+ if (def(strstr($slug, '.'))) {
+ $slug = call_user_func_array($point, [$slug]);
+ }
+
+ if (is_slug($slug)) {
+ return $slug;
+ }
+
+ return '';
+ }
+}
+
+if (!function_exists('is_camel')) {
+
+
+ /**
+ *
+ * convert a sring in a slug
+ *
+ * @param string $camel
+ *
+ * @return bool
+ *
+ */
+ function is_camel(string $camel): bool
+ {
+ return preg_match("#^[A-Z]([A-Za-z]+)$#", $camel) == 1;
+ }
+}
+
+
if (!function_exists('is_true')) {
/**
*
@@ -598,8 +798,13 @@ if (!function_exists('connect')) {
*
* @throws Kedavra
*/
- function connect(string $driver, string $base, string $user = '', string $password = '', string $host = 'localhost'): Connect
- {
+ function connect(
+ string $driver,
+ string $base,
+ string $user = '',
+ string $password = '',
+ string $host = 'localhost'
+ ): Connect {
return new Connect($driver, $base, $user, $password, $host);
}
}
@@ -708,7 +913,7 @@ if (!function_exists('whoops')) {
*/
function whoops(): Run
{
- return (new Run())->appendHandler(new PrettyPageHandler)->register();
+ return (new Run())->appendHandler(new PrettyPageHandler())->register();
}
}
@@ -722,18 +927,26 @@ if (!function_exists('commands')) {
*/
function commands(): array
{
- $commands = base('app', 'Console', '*.php');
- $namespace = 'App\Console';
- $data = files($commands);
- $commands = collect();
- foreach ($data as $c) {
- $command = collect(explode(DIRECTORY_SEPARATOR, $c))->last();
- $command = collect(explode('.', $command))->first();
- $command = "$namespace\\$command";
- $commands->set(new $command());
+ $commands = array_merge(
+ files(base('app', 'Console', '*.php')),
+ files(base('app', 'Console', '*', '*.php'))
+ );
+
+ $x = collect();
+ foreach ($commands as $k => $v) {
+ $v = '\\' .
+ collect(explode(
+ '.',
+ collect(explode(DIRECTORY_SEPARATOR, strval(strstr($v, 'app'))))
+ ->for('ucfirst')
+ ->join('\\')
+ ))
+ ->first();
+
+ $x->set(new $v());
}
- return $commands->all();
+ return $x->all();
}
}
@@ -748,7 +961,7 @@ if (!function_exists('controllers')) {
function controllers(string $directory): array
{
if ($directory !== 'Controllers') {
- $controllers =files(base('app', 'Controllers', $directory, '*.php'));
+ $controllers = files(base('app', 'Controllers', $directory, '*.php'));
} else {
$controllers = files(base('app', 'Controllers', '*.php'));
}
@@ -820,7 +1033,7 @@ if (!function_exists('logged')) {
*/
function logged(): bool
{
- return cli() ? false : (new Auth(new Session()))->connected();
+ return cli() ? false : (new Eywa\Session\Session())->has('user');
}
}
diff --git a/helpers/const.php b/helpers/const.php
index 9845ddb..0ca81d6 100755
--- a/helpers/const.php
+++ b/helpers/const.php
@@ -1,6 +1,5 @@
<?php
-
define('GET', 'GET');
define('POST', 'POST');
define('PUT', 'PUT');
@@ -33,7 +32,16 @@ define('CREATE_TO_WRITE_MODE', 'x');
define('CREATE_TO_WRITE_AND_READ_MODE', 'x+');
define('CREATE_WITHOUT_TRUNCATE_ON_WRITE_MODE', 'c');
define('CREATE_WITHOUT_TRUNCATE_ON_READ_AND_WRITE_MODE', 'c+');
-define('FILES_OPEN_MODE', [READ_FILE_MODE, READ_AND_WRITE_FILE_MODE, EMPTY_AND_WRITE_FILE_MODE, EMPTY_READ_AND_WRITE_FILE_MODE, WRITE_TO_END_FILE_MODE, WRITE_AND_READ_TO_END_FILE_MODE, CREATE_TO_WRITE_MODE, CREATE_TO_WRITE_AND_READ_MODE, CREATE_WITHOUT_TRUNCATE_ON_WRITE_MODE, CREATE_WITHOUT_TRUNCATE_ON_READ_AND_WRITE_MODE]);
+define(
+ 'FILES_OPEN_MODE',
+ [
+ READ_FILE_MODE, READ_AND_WRITE_FILE_MODE, EMPTY_AND_WRITE_FILE_MODE,
+ EMPTY_READ_AND_WRITE_FILE_MODE, WRITE_TO_END_FILE_MODE,
+ WRITE_AND_READ_TO_END_FILE_MODE, CREATE_TO_WRITE_MODE,
+ CREATE_TO_WRITE_AND_READ_MODE, CREATE_WITHOUT_TRUNCATE_ON_WRITE_MODE,
+ CREATE_WITHOUT_TRUNCATE_ON_READ_AND_WRITE_MODE
+ ]
+);
define('LOCALHOST', 'localhost');
@@ -431,37 +439,37 @@ define('STATUS', [
HTTP_METHOD_NOT_ALLOWED => HTTP_METHOD_NOT_ALLOWED_TEXT,
HTTP_METHOD_NOT_ACCEPTABLE => HTTP_METHOD_NOT_ACCEPTABLE_TEXT,
HTTP_PROXY_AUTHENTICATION_REQUIRED => HTTP_PROXY_AUTHENTICATION_REQUIRED_TEXT,
- HTTP_REQUEST_TIMEOUT=> HTTP_REQUEST_TIMEOUT_TEXT,
+ HTTP_REQUEST_TIMEOUT => HTTP_REQUEST_TIMEOUT_TEXT,
HTTP_CONFLICT => HTTP_CONFLICT_TEXT,
- HTTP_GONE =>HTTP_GONE_TEXT ,
+ HTTP_GONE => HTTP_GONE_TEXT ,
HTTP_LENGTH_REQUIRED => HTTP_LENGTH_REQUIRED_TEXT ,
- HTTP_PRECONDITION_FAILED =>HTTP_PRECONDITION_FAILED_TEXT,
+ HTTP_PRECONDITION_FAILED => HTTP_PRECONDITION_FAILED_TEXT,
HTTP_PAYLOAD_TOO_LARGE => HTTP_PAYLOAD_TOO_LARGE_TEXT,
HTTP_URI_TOO_LONG => HTTP_URI_TOO_LONG_TEXT ,
HTTP_UNSUPORTED_MEDIA_TYPE => HTTP_UNSUPORTED_MEDIA_TYPE_TEXT,
HTTP_RANGE_NOT_SATISFIABLE => HTTP_RANGE_NOT_SATISFIABLE_TEXT,
HTTP_EXPECTATION_FAILED => HTTP_EXPECTATION_FAILED_TEXT ,
HTTP_I_AM_TEAPOT => HTTP_I_AM_TEAPOT_TEXT ,
- HTTP_MISDIRECTED_REQUEST =>HTTP_MISDIRECTED_REQUEST_TEXT ,
- HTTP_UMPROCESSABLE_ENTITY =>HTTP_UMPROCESSABLE_ENTITY_TEXT,
- HTTP_LOCKED =>HTTP_LOCKED_TEXT,
- HTTP_FAILED_DEPENDENCY=>HTTP_FAILED_DEPENDENCY_TEXT,
- HTTP_TOO_EARLY=>HTTP_TOO_EARLY_TEXT,
- HTTP_UPGRADE_REQUIRED=>HTTP_UPGRADE_REQUIRED_TEXT,
- HTTP_PRECONDITION_REQUIRED=>HTTP_PRECONDITION_REQUIRED_TEXT,
- HTTP_TOO_MANY_REQUESTS=>HTTP_TOO_MANY_REQUESTS_TEXT,
- HTTP_REQUEST_HEADER_FIELD_TOO_LARGE=>HTTP_REQUEST_HEADER_FIELD_TOO_LARGE_TEXT,
- HTTP_UNAVAILABLE_FOR_LEGAL_REASONS=>HTTP_UNAVAILABLE_FOR_LEGAL_REASONS_TEXT,
- HTTP_INTERNAL_SERVER_ERROR=>HTTP_INTERNAL_SERVER_ERROR_TEXT,
- HTTP_NOT_IMPLEMENTED=> HTTP_NOT_IMPLEMENTED_TEXT,
- HTTP_BAD_GATEWAY =>HTTP_BAD_GATEWAY_TEXT,
- HTTP_SERVICE_UNAVAILABLE =>HTTP_SERVICE_UNAVAILABLE_TEXT,
- HTTP_GATEWAY_TIMEOUT =>HTTP_GATEWAY_TIMEOUT_TEXT,
- HTTP_VERSION_NOT_SUPPORTED =>HTTP_VERSION_NOT_SUPPORTED_TEXT,
- HTTP_VARIANT_ALSO_NEGOTIATES=> HTTP_VARIANT_ALSO_NEGOTIATES_TEXT,
- HTTP_INSUFFICIANT_STORAGE=>HTTP_INSUFFICIANT_STORAGE_TEXT,
- HTTP_LOOP_DETECTED =>HTTP_LOOP_DETECTED_TEXT,
- HTTP_NOT_EXTENDED=>HTTP_NOT_EXTENDED_TEXT,
+ HTTP_MISDIRECTED_REQUEST => HTTP_MISDIRECTED_REQUEST_TEXT ,
+ HTTP_UMPROCESSABLE_ENTITY => HTTP_UMPROCESSABLE_ENTITY_TEXT,
+ HTTP_LOCKED => HTTP_LOCKED_TEXT,
+ HTTP_FAILED_DEPENDENCY => HTTP_FAILED_DEPENDENCY_TEXT,
+ HTTP_TOO_EARLY => HTTP_TOO_EARLY_TEXT,
+ HTTP_UPGRADE_REQUIRED => HTTP_UPGRADE_REQUIRED_TEXT,
+ HTTP_PRECONDITION_REQUIRED => HTTP_PRECONDITION_REQUIRED_TEXT,
+ HTTP_TOO_MANY_REQUESTS => HTTP_TOO_MANY_REQUESTS_TEXT,
+ HTTP_REQUEST_HEADER_FIELD_TOO_LARGE => HTTP_REQUEST_HEADER_FIELD_TOO_LARGE_TEXT,
+ HTTP_UNAVAILABLE_FOR_LEGAL_REASONS => HTTP_UNAVAILABLE_FOR_LEGAL_REASONS_TEXT,
+ HTTP_INTERNAL_SERVER_ERROR => HTTP_INTERNAL_SERVER_ERROR_TEXT,
+ HTTP_NOT_IMPLEMENTED => HTTP_NOT_IMPLEMENTED_TEXT,
+ HTTP_BAD_GATEWAY => HTTP_BAD_GATEWAY_TEXT,
+ HTTP_SERVICE_UNAVAILABLE => HTTP_SERVICE_UNAVAILABLE_TEXT,
+ HTTP_GATEWAY_TIMEOUT => HTTP_GATEWAY_TIMEOUT_TEXT,
+ HTTP_VERSION_NOT_SUPPORTED => HTTP_VERSION_NOT_SUPPORTED_TEXT,
+ HTTP_VARIANT_ALSO_NEGOTIATES => HTTP_VARIANT_ALSO_NEGOTIATES_TEXT,
+ HTTP_INSUFFICIANT_STORAGE => HTTP_INSUFFICIANT_STORAGE_TEXT,
+ HTTP_LOOP_DETECTED => HTTP_LOOP_DETECTED_TEXT,
+ HTTP_NOT_EXTENDED => HTTP_NOT_EXTENDED_TEXT,
HTTP_NETWORK_AUTHENTICATIONJ_REQUIRED => HTTP_NETWORK_AUTHENTICATION_REQUIRED_TEXT
]);
@@ -477,3 +485,20 @@ define('VALIDATOR_ARGUMENT_NOT_UNIQUE', 4);
define('VALIDATOR_ARGUMENT_NOT_BETWEEN', 5);
define('VALIDATOR_ARGUMENT_SUPERIOR_OF_MAX_VALUE', 6);
define('VALIDATOR_ARGUMENT_SUPERIOR_MIN_OF_VALUE', 7);
+define('VALIDATOR_ARGUMENT_SLUG', 8);
+define('VALIDATOR_ARGUMENT_SNAKE', 9);
+define('VALIDATOR_ARGUMENT_CAMEL_CASE', 10);
+
+
+define('LONGTEXT', [POSTGRESQL => 'TEXT' , MYSQL => 'LONGTEXT' ,SQLITE => 'TEXT' ]);
+define('VARCHAR', [POSTGRESQL => 'VARCHAR' , MYSQL => 'VARCHAR', SQLITE => 'TEXT' ]);
+
+define('TINYINT', [POSTGRESQL => 'VARCHAR' , MYSQL => 'TINYINT', SQLITE => 'INTEGER' ]);
+define('SMALLINT', [POSTGRESQL => 'SMALLINT' , MYSQL => 'SMALLINT', SQLITE => 'INTEGER' ]);
+define('MEDIUMINT', [POSTGRESQL => 'VARCHAR' , MYSQL => 'MEDIUMINT', SQLITE => 'INTEGER' ]);
+define('BIGINT', [POSTGRESQL => 'VARCHAR' , MYSQL => 'BIGINT', SQLITE => 'INTEGER' ]);
+define('REAL', [POSTGRESQL => 'REAL' , MYSQL => 'REAL', SQLITE => 'REAL' ]);
+define('DOUBLE', [POSTGRESQL => 'DOUBLE PRECISION' , MYSQL => 'DOUBLE PRECISION', SQLITE => 'REAL' ]);
+define('FLOAT', [POSTGRESQL => 'DOUBLE PRECISION' , MYSQL => 'FLOAT', SQLITE => 'REAL' ]);
+
+define('PRIMARY', [POSTGRESQL => 'SERIAL' , MYSQL => 'INT', SQLITE => 'INTEGER' ]);
diff --git a/helpers/web.php b/helpers/web.php
index c3983f1..ba45ddf 100755
--- a/helpers/web.php
+++ b/helpers/web.php
@@ -151,7 +151,11 @@ if (!function_exists('root')) {
*/
function root(): string
{
- return php_sapi_name() !== 'cli' ? https() ? 'https://' . Request::make()->server()->get('HTTP_HOST') : 'http://' . Request::make()->server()->get('HTTP_HOST') : '/';
+ return php_sapi_name() !== 'cli'
+ ? https()
+ ? 'https://' . Request::make()->server()->get('HTTP_HOST')
+ : 'http://' . Request::make()->server()->get('HTTP_HOST')
+ : '/';
}
}
@@ -163,7 +167,7 @@ if (!function_exists('cli')) {
* @return bool
*
*/
- function cli():bool
+ function cli(): bool
{
return php_sapi_name() === 'cli';
}
@@ -177,7 +181,7 @@ if (!function_exists('not_cli')) {
* @return bool
*
*/
- function not_cli():bool
+ function not_cli(): bool
{
return ! cli();
}
@@ -188,16 +192,20 @@ if (!function_exists('url')) {
*
* Generate the url
*
- * @param string $url
+ * @param string ...$urls
*
* @return string
*
* @throws Kedavra
- *
*/
- function url(string $url):string
+ function url(string ...$urls): string
{
- return php_sapi_name() !== 'cli' ? https() ? sprintf('https://%s/%s', Request::make()->server()->get('HTTP_HOST'), $url) : sprintf('http://%s/%s', Request::make()->server()->get('HTTP_HOST'), $url) : sprintf('/%s', $url);
+ return php_sapi_name() !== 'cli'
+ ? https()
+ ?
+ sprintf('https://%s/%s', Request::make()->server()->get('HTTP_HOST'), collect($urls)->join('/'))
+ : sprintf('http://%s/%s', Request::make()->server()->get('HTTP_HOST'), collect($urls)->join('/'))
+ : sprintf('/%s', collect($urls)->join('/'));
}
}
if (!function_exists('alert')) {
@@ -208,7 +216,7 @@ if (!function_exists('alert')) {
* @return string
* @throws Kedavra
*/
- function alert(array $messages, bool $success = false) :string
+ function alert(array $messages, bool $success = false): string
{
$file = 'alert';
$ul_class = config($file, 'ul-class');
@@ -255,7 +263,9 @@ if (!function_exists('route')) {
}
return $url;
}
- $url = https() ? 'https://'. Request::make()->server()->get('SERVER_NAME') . $x[0]->url : 'http://'.Request::make()->server()->get('SERVER_NAME').$x[0]->url;
+ $url =
+ https() ? 'https://' . Request::make()->server()->get('SERVER_NAME') . $x[0]->url
+ : 'http://' . Request::make()->server()->get('SERVER_NAME') . $x[0]->url;
if (def($args)) {
foreach ($args as $k => $v) {
@@ -279,7 +289,7 @@ if (!function_exists('ago')) {
* @throws Exception
*
*/
- function ago(string $time, $tz = null):string
+ function ago(string $time, $tz = null): string
{
Carbon::setLocale(app()->lang());
@@ -316,7 +326,7 @@ if (!function_exists('flash')) {
* @throws Kedavra
*
*/
- function flash():string
+ function flash(): string
{
return (new Flash())->display();
}
diff --git a/ioc/Admin/Admin.php b/ioc/Admin/Admin.php
index 2277cfd..c696a20 100755
--- a/ioc/Admin/Admin.php
+++ b/ioc/Admin/Admin.php
@@ -1,6 +1,5 @@
<?php
-
namespace Ioc\Admin;
use Eywa\Http\Request\Request;
diff --git a/ioc/App.php b/ioc/App.php
index b39fb5b..ad16d7c 100644
--- a/ioc/App.php
+++ b/ioc/App.php
@@ -1,6 +1,5 @@
<?php
-
namespace Ioc;
use Eywa\Ioc\Container;
diff --git a/ioc/Dev/Dev.php b/ioc/Dev/Dev.php
index 749f777..50ed579 100644
--- a/ioc/Dev/Dev.php
+++ b/ioc/Dev/Dev.php
@@ -1,6 +1,5 @@
<?php
-
namespace Ioc\Dev;
use Eywa\Ioc\Container;
diff --git a/ioc/Web/Web.php b/ioc/Web/Web.php
index bfcd9b7..68ae811 100755
--- a/ioc/Web/Web.php
+++ b/ioc/Web/Web.php
@@ -1,8 +1,8 @@
<?php
-
namespace Ioc\Web;
+use Eywa\Cache\FileCache;
use Eywa\Html\Form\Form;
use Eywa\Ioc\Container;
use Eywa\Ioc\Ioc;
@@ -16,8 +16,6 @@ class Web extends Container
public function add(): Ioc
{
return
- $this->init(Form::class, function () {
- return 'form';
- });
+ $this->set('cache', new FileCache());
}
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..b0d9f2c
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ruleset name="eywa">
+ <description>Eywa rules</description>
+ <arg name="colors"/>
+ <arg value="p"/>
+
+ <file>eywa</file>
+ <file>helpers</file>
+ <file>ioc</file>
+ <file>db</file>
+ <file>app</file>
+ <file>tests</file>
+ <rule ref="PSR12"/>
+ <rule ref="PSR1"/>
+</ruleset> \ No newline at end of file
diff --git a/shaolin b/shaolin
index b00aefe..75f970f 100755
--- a/shaolin
+++ b/shaolin
@@ -6,4 +6,4 @@ use Eywa\Console\Console;
require __DIR__.'/vendor/autoload.php';
-exit((new Console('EYWA','11'))->run()); \ No newline at end of file
+exit((new Console('EYWA', '11'))->run());
diff --git a/tests/Container/IocTest.php b/tests/Container/IocTest.php
index 1ebe784..c0255a0 100644
--- a/tests/Container/IocTest.php
+++ b/tests/Container/IocTest.php
@@ -1,10 +1,10 @@
<?php
-
namespace Testing\Container {
use App\Application;
+ use Eywa\Cache\FileCache;
use Eywa\Exception\Kedavra;
use Eywa\Testing\Unit;
use ReflectionException;
@@ -18,9 +18,26 @@ namespace Testing\Container {
* @throws ReflectionException
*
*/
- public function test_multiple()
+ public function testMultiple()
+ {
+ $this->assertInstanceOf(Application::class, ioc(Application::class, ['env' => 'dev','table' => 'users']));
+ $this->assertInstanceOf(Application::class, ioc(Application::class));
+ $this->assertInstanceOf(FileCache::class, ioc('cache'));
+ }
+
+ public function testException()
+ {
+ $this->expectException(Kedavra::class);
+ ioc('a');
+ }
+
+ /**
+ * @throws Kedavra
+ * @throws ReflectionException
+ */
+ public function testSuccess()
{
- $this->assertInstanceOf(Application::class, ioc(Application::class, ['env'=> 'dev','table'=>'users']));
+ $this->assertInstanceOf(FileCache::class, ioc('cache'));
}
}
}
diff --git a/tests/Helpers/AdminTest.php b/tests/Helpers/AdminTest.php
new file mode 100644
index 0000000..394431f
--- /dev/null
+++ b/tests/Helpers/AdminTest.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace Testing\Helpers;
+
+use Eywa\Application\App;
+use Eywa\Database\Connexion\Connect;
+use Eywa\Database\Query\Sql;
+use Eywa\Testing\Unit;
+
+class AdminTest extends Unit
+{
+ public function testSnake()
+ {
+ $this->assertFalse(is_snake('ALaMode'));
+ $this->assertFalse(is_snake('aMode'));
+ $this->assertFalse(is_snake('A_mode'));
+ $this->assertFalse(is_snake('a_aAAEZode'));
+ $this->assertFalse(is_snake('a_Aode'));
+ $this->assertFalse(is_snake(''));
+ $this->assertTrue(is_snake('a_superb_linux_operating_system'));
+ $this->assertEquals('SuperbLinuxOperatingSystem', snake_to_camel('superb_linux_operating_system'));
+ }
+
+ public function tesCamel()
+ {
+ $this->assertTrue(is_camel('ALaMode'));
+ $this->assertFalse(is_camel('aMode'));
+ $this->assertFalse(is_camel('A_mode'));
+ $this->assertFalse(is_camel('a_aAAEZode'));
+ $this->assertFalse(is_camel('a_Aode'));
+ $this->assertFalse(is_camel(''));
+ $this->assertTrue(is_camel(snake_to_camel('a_superb_linux_operating_system')));
+ $this->assertTrue(is_camel('UsersController'));
+ $this->assertEquals('SuperbLinuxOperatingSystem', snake_to_camel('superb_linux_operating_system'));
+ }
+
+ public function testSlug()
+ {
+ $this->assertFalse(is_slug('A-AZA-AZDAZ-QQQX'));
+ $this->assertFalse(is_slug('a_azda_azdazazzezcredczscdsdc_rzz'));
+ $this->assertFalse(is_slug('A_HEd_adzedzEREZAczc_rzz'));
+ $this->assertFalse(is_slug('Alouer'));
+ $this->assertFalse(is_slug('A'));
+ $this->assertFalse(is_slug(''));
+ $this->assertTrue(is_slug('post'));
+ $this->assertTrue(is_slug('post-3'));
+ $this->assertTrue(is_slug(sluglify('I am a title')));
+ $this->assertEquals('i-am-a-title', sluglify('I am a title'));
+ $this->assertEquals('i-am-a-title', sluglify('I , am , a , title'));
+ $this->assertEquals('i-am-a-title-super-easy', sluglify('I am a title. super easy'));
+ $this->assertEquals('blog', sluglify('blog'));
+ $this->assertEmpty(sluglify('a'));
+ }
+
+ public function testControllers()
+ {
+ $this->assertNotEmpty(controllers_directory());
+ $this->assertIsArray(controllers_directory());
+ }
+
+ public function testViews()
+ {
+ $this->assertNotEmpty(views());
+ $this->assertIsArray(views());
+ }
+
+ public function testHttps()
+ {
+ $this->assertFalse(https());
+ }
+ public function testUrl()
+ {
+ $this->assertEquals('/blog', url('blog'));
+ $this->assertEquals('/comments/all', url('comments', 'all'));
+ $this->assertEquals('/comments/edit/1', url('comments', 'edit', '1'));
+ }
+ public function testFiles()
+ {
+ $this->assertIsArray(files(base('*.md')));
+ $this->assertIsArray(files(base('eywa', '*', '*.php')));
+ $this->assertEmpty(files(base('*.php')));
+ }
+
+ public function testBase()
+ {
+ $this->assertNotEmpty(base('config'));
+ $this->assertStringContainsString('/config', base('config'));
+ $this->assertNotEmpty(base('app', 'Views'));
+ $this->assertStringContainsString('/app/Views', base('app', 'Views'));
+ $this->assertNotEmpty(base(''));
+ }
+ public function testApp()
+ {
+ $this->assertInstanceOf(App::class, app());
+ $this->assertInstanceOf(Connect::class, production());
+ $this->assertInstanceOf(Connect::class, development());
+ $this->assertNotEquals(production(), development());
+ }
+
+ public function testSql()
+ {
+ $this->assertInstanceOf(Sql::class, \sql('auth'));
+ }
+}
diff --git a/tests/Helpers/WebTest.php b/tests/Helpers/WebTest.php
index a214f46..ff0b2a8 100644
--- a/tests/Helpers/WebTest.php
+++ b/tests/Helpers/WebTest.php
@@ -1,6 +1,5 @@
<?php
-
namespace Testing\Helpers {
use Carbon\Carbon;
@@ -18,7 +17,7 @@ namespace Testing\Helpers {
/**
*
*/
- public function test_collect()
+ public function testCollect()
{
$this->assertInstanceOf(Collect::class, collect());
}
@@ -26,7 +25,7 @@ namespace Testing\Helpers {
/**
*
*/
- public function test_env()
+ public function testEnv()
{
$this->assertEquals('not_found', env('A', 'not_found'));
$this->assertEquals(env('DB_DRIVER', ''), env('DB_DRIVER', ''));
@@ -35,7 +34,7 @@ namespace Testing\Helpers {
/**
*
*/
- public function test_now()
+ public function testNow()
{
$this->assertInstanceOf(Carbon::class, now());
}
@@ -43,7 +42,7 @@ namespace Testing\Helpers {
/**
* @throws Kedavra
*/
- public function test_root()
+ public function testRoot()
{
$this->assertEquals('/', root());
}
@@ -51,7 +50,7 @@ namespace Testing\Helpers {
/**
* @throws Kedavra
*/
- public function test_flash()
+ public function testFlash()
{
$this->assertEquals('', flash());
}
@@ -59,14 +58,14 @@ namespace Testing\Helpers {
/**
* @throws Kedavra
*/
- public function test_sum()
+ public function testSum()
{
$this->assertEquals(5, sum([0,1,2,3,4]));
$this->assertEquals(5, sum(5));
$this->assertEquals(5, sum('equal'));
}
- public function test_sum_error()
+ public function testSumError()
{
$this->expectException(Kedavra::class);
sum(false);
@@ -74,7 +73,7 @@ namespace Testing\Helpers {
/**
*
*/
- public function test_cli()
+ public function testCli()
{
$this->assertTrue(cli());
$this->assertFalse(not_cli());
@@ -83,19 +82,20 @@ namespace Testing\Helpers {
/**
* @throws Kedavra
*/
- public function test_route()
+ public function testRoute()
{
$this->assertEquals('/', route('root'));
+ $this->assertEquals('hello/marc', route('hello', ['name' => 'marc']));
}
/***
* @throws Kedavra
*/
- public function test_ago()
+ public function testAgo()
{
$this->assertNotEmpty(ago('2020-02-17'));
}
- public function test_total()
+ public function testTotal()
{
$this->assertEquals('1', total(1));
$this->assertEquals('10', total(10));
@@ -112,7 +112,7 @@ namespace Testing\Helpers {
/**
*
*/
- public function test_append()
+ public function testAppend()
{
$x = '';
append($x, 'php', 'is', 'super');
@@ -122,7 +122,7 @@ namespace Testing\Helpers {
/**
*
*/
- public function test_is_pair()
+ public function testPair()
{
$this->assertTrue(is_pair(2));
$this->assertTrue(is_pair(4));
diff --git a/tests/Html/FormTest.php b/tests/Html/FormTest.php
index e755a26..9c91255 100644
--- a/tests/Html/FormTest.php
+++ b/tests/Html/FormTest.php
@@ -1,6 +1,5 @@
<?php
-
namespace Testing\Html {
use App\Forms\UsersForm;
@@ -13,13 +12,13 @@ namespace Testing\Html {
/**
* @throws Kedavra
*/
- public function test_success()
+ public function testSuccess()
{
$form = (new UsersForm())->make();
$this->assertNotEmpty($form);
$this->assertStringContainsString('/', $form);
- $this->assertStringContainsString('<input type="hidden" name="_method" class="hide" value="GET">', $form);
- $this->assertStringContainsString('<input type="hidden" name="csrf_token" class="hide" ', $form);
+ $this->assertStringContainsString('<input type="hidden" name="_method" class="hide" value="GET">', $form);
+ $this->assertStringContainsString('<input type="hidden" name="csrf_token" class="hide" ', $form);
$this->assertStringContainsString('type="text"', $form);
$this->assertStringContainsString('textarea', $form);
$this->assertStringContainsString('name="username"', $form);
@@ -34,7 +33,7 @@ namespace Testing\Html {
/**
* @throws Kedavra
*/
- public function test_validator()
+ public function testValidator()
{
$form = new UsersForm();
$this->assertEmpty($form->validate(new Request(['username' => 'aza']))->errors()->all());
diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php
index 3a453ba..f6fe9b6 100644
--- a/tests/Http/RequestTest.php
+++ b/tests/Http/RequestTest.php
@@ -1,8 +1,8 @@
<?php
-
namespace Testing\Http {
+ use Eywa\Exception\Kedavra;
use Eywa\Http\Request\Request;
use Eywa\Testing\Unit;
@@ -16,58 +16,82 @@ namespace Testing\Http {
*/
private Request $args;
+ /**
+ * @throws Kedavra
+ */
public function setUp(): void
{
$this->request = new Request();
- $this->args = new Request([], [], [], [], [], ['name' => 'Willy','username' => 'fumseckworld','age' => 31]);
+ $this->args = new Request(
+ [],
+ [],
+ [],
+ [],
+ [],
+ [
+ 'name' => 'Willy',
+ 'username' => 'fumseckworld',
+ 'age' => 31
+ ]
+ );
}
- public function tests_post()
+ public function testsPost()
{
$this->assertNull($this->request->request()->get('a'));
$this->assertEquals([], $this->request->request()->all());
$this->assertFalse($this->request->request()->has('a'));
}
- public function tests_get()
+
+ public function testsGet()
{
$this->assertNull($this->request->query()->get('a'));
$this->assertEquals([], $this->request->query()->all());
$this->assertFalse($this->request->query()->has('a'));
}
- public function tests_cookie()
+ public function testsCookie()
{
$this->assertNull($this->request->cookie()->get('a'));
$this->assertEquals([], $this->request->cookie()->all());
$this->assertFalse($this->request->cookie()->has('a'));
}
- public function tests_server()
+ public function testsServer()
{
$this->assertNull($this->request->server()->get('a'));
$this->assertEquals([], $this->request->server()->all());
$this->assertFalse($this->request->server()->has('a'));
}
- public function test_ip()
+
+ public function testIp()
{
$this->assertEquals('127.0.0.1', $this->request->ip());
}
- public function test_args()
+ public function testArgs()
{
$this->assertEquals([], $this->request->args()->all());
- $this->assertEquals(['name' => 'Willy','username' => 'fumseckworld','age' => 31], $this->args->args()->all());
+ $this->assertEquals(
+ [
+ 'name' => 'Willy',
+ 'username' => 'fumseckworld',
+ 'age' => 31
+ ],
+ $this->args->args()->all()
+ );
$this->assertEquals(31, $this->args->args()->get('age', 58));
$this->assertEquals('fumseckworld', $this->args->args()->get('username', 'will'));
$this->assertEquals('Willy', $this->args->args()->get('name', 'will'));
$this->assertEquals('alex', $this->args->args()->get('names', 'alex'));
}
- public function test_secure()
+ public function testSecure()
{
$this->assertFalse($this->request->secure());
}
- public function test_local()
+
+ public function testLocal()
{
$this->assertTrue($this->request->local());
}
diff --git a/tests/Http/RouterTest.php b/tests/Http/RouterTest.php
index f63049f..22e07da 100644
--- a/tests/Http/RouterTest.php
+++ b/tests/Http/RouterTest.php
@@ -1,6 +1,5 @@
<?php
-
namespace Testing\Http {
use Eywa\Exception\Kedavra;
diff --git a/tests/Security/AuthTest.php b/tests/Security/AuthTest.php
index 2f45168..7a16907 100644
--- a/tests/Security/AuthTest.php
+++ b/tests/Security/AuthTest.php
@@ -1,27 +1,36 @@
<?php
-
namespace Testing\Security {
+ use App\Models\Auth\Authentication;
+ use Eywa\Exception\Kedavra;
use Eywa\Testing\Unit;
+ use stdClass;
class AuthTest extends Unit
{
- public function test_success()
+
+ /**
+ * @throws Kedavra
+ */
+ public function testSuccess()
{
- $this->assertTrue($this->auth()->login('Helmer Torphy', '00000000')->to('/home'));
- $this->assertTrue($this->auth()->login('Helmer Torphy', '0000000')->to('/login'));
- $this->assertTrue($this->auth()->login('a', 'azd')->to('/login'));
- $this->assertTrue($this->auth()->login('', '')->to('/login'));
- $this->assertFalse($this->auth()->connected());
- $this->assertInstanceOf(\stdClass::class, $this->auth()->current());
- $this->assertTrue($this->auth()->logout()->to('/'));
- $this->assertTrue($this->auth()->clean());
- $this->assertTrue($this->auth()->delete_account()->to('/'));
- $this->assertFalse($this->auth()->is('admin'));
- $this->assertFalse($this->auth()->is('redac'));
- $this->assertFalse($this->auth()->is('superuser'));
- $this->assertTrue($this->auth()->login('a', 'a')->to('/login'));
+
+ $username = Authentication::find(1)->username;
+
+ $this->assertTrue($this->auth(Authentication::class)->login($username, '00000000')->to('/home'));
+ $this->assertTrue($this->auth(Authentication::class)->login($username, '0000000')->to('/login'));
+ $this->assertTrue($this->auth(Authentication::class)->login('a', 'azd')->to('/login'));
+ $this->assertTrue($this->auth(Authentication::class)->login('', '')->to('/login'));
+ $this->assertFalse($this->auth(Authentication::class)->connected());
+ $this->assertInstanceOf(stdClass::class, $this->auth(Authentication::class)->current());
+ $this->assertTrue($this->auth(Authentication::class)->logout()->to('/'));
+ $this->assertTrue($this->auth(Authentication::class)->clean());
+ $this->assertTrue($this->auth(Authentication::class)->deleteAccount()->to('/'));
+ $this->assertFalse($this->auth(Authentication::class)->is('admin'));
+ $this->assertFalse($this->auth(Authentication::class)->is('redac'));
+ $this->assertFalse($this->auth(Authentication::class)->is('superuser'));
+ $this->assertTrue($this->auth(Authentication::class)->login('a', 'a')->to('/login'));
}
}
}
diff --git a/web/index.php b/web/index.php
index 4bede0e..c30bafe 100755
--- a/web/index.php
+++ b/web/index.php
@@ -1,7 +1,5 @@
<?php
-
-
require '../vendor/autoload.php';
app()->run();