aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2020-03-04 14:44:48 +0000
committerWilly Micieli <micieli@laposte.net>2020-03-04 14:44:48 +0000
commit23c0282561beccb798e8296275dab9441a33d6d6 (patch)
tree9ea6465da04c3efd9840ea1c7fd52af2c4458d4c
parent7c08d9b1ab4413b7be3c29df84d8c1594335609c (diff)
downloadimperium-omaticayas.zip
imperium-omaticayas.tar.gz
refactor codeomaticayas
-rwxr-xr-x[-rw-r--r--].env.example0
-rwxr-xr-x[-rw-r--r--].gitignore0
-rwxr-xr-x[-rw-r--r--]LICENSE0
-rwxr-xr-x[-rw-r--r--]Makefile4
-rwxr-xr-x[-rw-r--r--]README.md0
-rwxr-xr-x[-rw-r--r--]app/Console/Hello.php0
-rwxr-xr-x[-rw-r--r--]app/Controllers/Auth/AuthController.php4
-rwxr-xr-x[-rw-r--r--]app/Controllers/Email/WriteController.php4
-rwxr-xr-x[-rw-r--r--]app/Controllers/Home/HomeController.php6
-rwxr-xr-x[-rw-r--r--]app/Middleware/IpMiddleware.php0
-rwxr-xr-x[-rw-r--r--]app/Models/Auth.php99
-rwxr-xr-x[-rw-r--r--]app/Models/User.php101
-rwxr-xr-x[-rw-r--r--]app/Validators/Users/UsersValidator.php0
-rwxr-xr-x[-rw-r--r--]app/Views/Home/home.php0
-rwxr-xr-x[-rw-r--r--]app/Views/layout.php0
-rwxr-xr-x[-rw-r--r--]app/Views/maintenance.php0
-rwxr-xr-x[-rw-r--r--]bidon/.gitignore0
-rwxr-xr-x[-rw-r--r--]cache/.gitignore0
-rwxr-xr-x[-rw-r--r--]composer.json10
-rwxr-xr-x[-rw-r--r--]config/alert.yaml0
-rwxr-xr-x[-rw-r--r--]config/app.yaml0
-rwxr-xr-x[-rw-r--r--]config/auth.yaml0
-rwxr-xr-x[-rw-r--r--]config/connexion.yaml0
-rwxr-xr-x[-rw-r--r--]config/flash.yaml0
-rwxr-xr-x[-rw-r--r--]config/form.yaml0
-rwxr-xr-x[-rw-r--r--]config/hash.yaml0
-rwxr-xr-x[-rw-r--r--]config/history.yaml0
-rwxr-xr-x[-rw-r--r--]config/i18n.yaml0
-rwxr-xr-x[-rw-r--r--]config/mail.yaml0
-rwxr-xr-x[-rw-r--r--]config/migrations.yaml0
-rwxr-xr-x[-rw-r--r--]config/pagination.yaml0
-rwxr-xr-x[-rw-r--r--]config/validator.yaml0
-rwxr-xr-x[-rw-r--r--]db/Migrations/AddPhoneToUsers.php0
-rwxr-xr-x[-rw-r--r--]db/Migrations/CreateAuthTable.php0
-rwxr-xr-x[-rw-r--r--]db/Migrations/CreateUsersTable.php0
-rwxr-xr-x[-rw-r--r--]db/Seeds/AuthSeeder.php0
-rwxr-xr-x[-rw-r--r--]db/Seeds/UserSeeder.php0
-rwxr-xr-x[-rw-r--r--]db/dump/.gitignore0
-rwxr-xr-x[-rw-r--r--]eywa/Application/App.php27
-rwxr-xr-x[-rw-r--r--]eywa/Application/Environment/Env.php6
-rwxr-xr-x[-rw-r--r--]eywa/Application/Eywa.php60
-rwxr-xr-x[-rw-r--r--]eywa/Application/Zen.php0
-rwxr-xr-x[-rw-r--r--]eywa/Cache/ApcuCache.php0
-rwxr-xr-x[-rw-r--r--]eywa/Cache/CacheInterface.php2
-rwxr-xr-x[-rw-r--r--]eywa/Cache/FileCache.php19
-rwxr-xr-x[-rw-r--r--]eywa/Cache/MemcacheCache.php0
-rwxr-xr-x[-rw-r--r--]eywa/Cache/RedisCache.php0
-rwxr-xr-x[-rw-r--r--]eywa/Collection/Collect.php278
-rwxr-xr-x[-rw-r--r--]eywa/Configuration/Config.php7
-rwxr-xr-x[-rw-r--r--]eywa/Console/App/AppSend.php6
-rwxr-xr-x[-rw-r--r--]eywa/Console/App/Coverage.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/App/Dkim.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/App/Key.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/App/Serve.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/App/TestCommand.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Cache/ClearCache.php84
-rwxr-xr-x[-rw-r--r--]eywa/Console/Console.php10
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/CleanDatabase.php6
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/DropTable.php53
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/ExportDatabase.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/Grant.php0
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/ImportDatabase.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/InstallDatabase.php62
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/MigrateDatabase.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/RollbackDatabase.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/SeedDatabase.php7
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/ShowTable.php9
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/ShowUsers.php4
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/TruncateTable.php6
-rwxr-xr-x[-rw-r--r--]eywa/Console/Database/UninstallDatabase.php80
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateCommand.php76
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateController.php123
-rw-r--r--eywa/Console/Generate/GenerateCrud.php206
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateMiddleware.php12
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateMigration.php10
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateModel.php10
-rw-r--r--eywa/Console/Generate/GenerateRouteBase.php65
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateSeeds.php12
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateTest.php18
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateValidator.php14
-rwxr-xr-x[-rw-r--r--]eywa/Console/Generate/GenerateView.php12
-rwxr-xr-x[-rw-r--r--]eywa/Console/Get/Documentation.php4
-rwxr-xr-x[-rw-r--r--]eywa/Console/Get/Wanted.php4
-rwxr-xr-x[-rw-r--r--]eywa/Console/Git/GetWanted.php0
-rwxr-xr-x[-rw-r--r--]eywa/Console/Lang/CreateCatalogues.php43
-rwxr-xr-x[-rw-r--r--]eywa/Console/Lang/UpdateCatalogues.php32
-rwxr-xr-x[-rw-r--r--]eywa/Console/Mode/DevMode.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Mode/Maintenance.php2
-rwxr-xr-x[-rw-r--r--]eywa/Console/Mode/ProductionMode.php3
-rwxr-xr-x[-rw-r--r--]eywa/Console/Routes/AddRoute.php12
-rwxr-xr-x[-rw-r--r--]eywa/Console/Routes/FindRoute.php239
-rwxr-xr-x[-rw-r--r--]eywa/Console/Routes/ListRoute.php21
-rwxr-xr-x[-rw-r--r--]eywa/Console/Routes/RemoveRoute.php167
-rwxr-xr-x[-rw-r--r--]eywa/Console/Routes/UpdateRoute.php90
-rwxr-xr-x[-rw-r--r--]eywa/Console/Shell.php158
-rwxr-xr-x[-rw-r--r--]eywa/Database/Base/Base.php0
-rwxr-xr-x[-rw-r--r--]eywa/Database/Connexion/Connect.php63
-rwxr-xr-x[-rw-r--r--]eywa/Database/Connexion/Connexion.php11
-rwxr-xr-x[-rw-r--r--]eywa/Database/Export/Export.php15
-rwxr-xr-x[-rw-r--r--]eywa/Database/Import/Import.php15
-rwxr-xr-x[-rw-r--r--]eywa/Database/Migration/CreateMigrationTable.php0
-rwxr-xr-x[-rw-r--r--]eywa/Database/Migration/Migrate.php141
-rwxr-xr-x[-rw-r--r--]eywa/Database/Migration/Migration.php131
-rwxr-xr-x[-rw-r--r--]eywa/Database/Model/Model.php193
-rwxr-xr-x[-rw-r--r--]eywa/Database/Query/Sql.php164
-rwxr-xr-x[-rw-r--r--]eywa/Database/Seed/Seeder.php4
-rwxr-xr-x[-rw-r--r--]eywa/Database/Seed/Seeding.php49
-rwxr-xr-x[-rw-r--r--]eywa/Database/Table/Table.php51
-rwxr-xr-x[-rw-r--r--]eywa/Database/User/User.php9
-rwxr-xr-x[-rw-r--r--]eywa/Debug/Dumper.php0
-rwxr-xr-x[-rw-r--r--]eywa/Debug/HtmlDumper.php3
-rwxr-xr-x[-rw-r--r--]eywa/Detection/Detect.php0
-rwxr-xr-x[-rw-r--r--]eywa/Exception/Kedavra.php0
-rwxr-xr-x[-rw-r--r--]eywa/File/File.php39
-rwxr-xr-x[-rw-r--r--]eywa/Html/Form/Form.php49
-rwxr-xr-x[-rw-r--r--]eywa/Html/Pagination/Pagination.php0
-rwxr-xr-x[-rw-r--r--]eywa/Http/Controller/Controller.php110
-rwxr-xr-x[-rw-r--r--]eywa/Http/Curl/Curl.php0
-rwxr-xr-x[-rw-r--r--]eywa/Http/Middleware/Middleware.php0
-rwxr-xr-x[-rw-r--r--]eywa/Http/Parameter/Bag.php9
-rwxr-xr-x[-rw-r--r--]eywa/Http/Parameter/Uploaded/UploadedFile.php53
-rwxr-xr-x[-rw-r--r--]eywa/Http/Parameter/Uploaded/UploadedFileInterface.php24
-rwxr-xr-xeywa/Http/Request/FormRequest.php117
-rwxr-xr-x[-rw-r--r--]eywa/Http/Request/Request.php117
-rwxr-xr-x[-rw-r--r--]eywa/Http/Request/ServerRequest.php10
-rwxr-xr-x[-rw-r--r--]eywa/Http/Response/JsonResponse.php0
-rwxr-xr-x[-rw-r--r--]eywa/Http/Response/RedirectResponse.php0
-rwxr-xr-x[-rw-r--r--]eywa/Http/Response/Response.php0
-rwxr-xr-x[-rw-r--r--]eywa/Http/Routing/RouteResult.php39
-rwxr-xr-x[-rw-r--r--]eywa/Http/Routing/Router.php0
-rw-r--r--eywa/Http/Routing/Task.php33
-rwxr-xr-x[-rw-r--r--]eywa/Http/Routing/Web.php107
-rwxr-xr-x[-rw-r--r--]eywa/Http/View/View.php0
-rwxr-xr-x[-rw-r--r--]eywa/Ioc/Container.php162
-rwxr-xr-xeywa/Ioc/Ioc.php247
-rwxr-xr-x[-rw-r--r--]eywa/Message/Email/Write.php0
-rwxr-xr-x[-rw-r--r--]eywa/Message/Flash/Flash.php0
-rwxr-xr-x[-rw-r--r--]eywa/Security/Authentication/Auth.php0
-rwxr-xr-x[-rw-r--r--]eywa/Security/Crypt/Crypter.php0
-rwxr-xr-x[-rw-r--r--]eywa/Security/Csrf/Csrf.php12
-rwxr-xr-x[-rw-r--r--]eywa/Security/Hashing/Hash.php0
-rwxr-xr-x[-rw-r--r--]eywa/Security/Middleware/CsrfMiddleware.php0
-rwxr-xr-x[-rw-r--r--]eywa/Session/ArraySession.php0
-rwxr-xr-x[-rw-r--r--]eywa/Session/Session.php0
-rwxr-xr-x[-rw-r--r--]eywa/Session/SessionInterface.php0
-rwxr-xr-x[-rw-r--r--]eywa/Testing/Unit.php0
-rwxr-xr-x[-rw-r--r--]eywa/Time/Timing.php0
-rwxr-xr-x[-rw-r--r--]eywa/Validate/Validator.php3
-rwxr-xr-xgrumphp.yml29
-rwxr-xr-x[-rw-r--r--]helpers/admin.php24
-rwxr-xr-x[-rw-r--r--]helpers/const.php5
-rwxr-xr-x[-rw-r--r--]helpers/web.php3
-rwxr-xr-xioc/Admin.php22
-rwxr-xr-xioc/Web.php25
-rw-r--r--ioc/admin.php2
-rw-r--r--ioc/web.php2
-rwxr-xr-x[-rw-r--r--]logs/.gitignore0
-rwxr-xr-x[-rw-r--r--]phpunit-printer.yml0
-rwxr-xr-x[-rw-r--r--]phpunit.xml0
-rw-r--r--po/en_US/LC_MESSAGES/messages.po22
-rw-r--r--po/eywa.pot22
-rw-r--r--po/fr_FR/LC_MESSAGES/messages.po22
-rwxr-xr-x[-rw-r--r--]sql/mysql/achats.sql0
-rwxr-xr-x[-rw-r--r--]sql/mysql/auth.sql0
-rwxr-xr-x[-rw-r--r--]sql/mysql/users.sql0
-rwxr-xr-x[-rw-r--r--]sql/oracle/achats.sql0
-rwxr-xr-x[-rw-r--r--]sql/oracle/users.sql0
-rwxr-xr-x[-rw-r--r--]sql/pgsql/achats.sql0
-rwxr-xr-x[-rw-r--r--]sql/pgsql/users.sql0
-rwxr-xr-x[-rw-r--r--]sql/sqlite/achats.sql0
-rwxr-xr-x[-rw-r--r--]sql/sqlite/users.sql0
-rwxr-xr-x[-rw-r--r--]sql/sqlsrv/achats.sql0
-rwxr-xr-x[-rw-r--r--]sql/sqlsrv/users.sql0
-rwxr-xr-x[-rw-r--r--]tests/App/ApplicationTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Auth/AuthTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Cache/ApcuCacheTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Cache/MemCacheTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Cache/RedisCacheTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Collection/CollectionTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Crypt/CryptTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Database/ConnectTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Database/ModelTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Database/SeedTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Database/SqlTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Database/TableTest.php0
-rwxr-xr-x[-rw-r--r--]tests/File/FileTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Form/FormTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Helpers/AdminHelperTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Html/PaginationTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Http/JsonReponseTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Http/ReponseTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Http/RequestTest.php21
-rwxr-xr-x[-rw-r--r--]tests/Ioc/ContainerTest.php50
-rwxr-xr-x[-rw-r--r--]tests/Message/WriteTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Routing/RouterTest.php0
-rwxr-xr-x[-rw-r--r--]tests/Validator/ValidatorTest.php0
-rwxr-xr-x[-rw-r--r--]tests/View/EywaTest.php0
-rwxr-xr-x[-rw-r--r--]tests/View/ViewTest.php0
-rwxr-xr-x[-rw-r--r--]web/.gitignore0
-rwxr-xr-x[-rw-r--r--]web/.htaccess0
-rwxr-xr-x[-rw-r--r--]web/css/app.css0
-rwxr-xr-x[-rw-r--r--]web/favicon.icobin6518 -> 6518 bytes
-rwxr-xr-x[-rw-r--r--]web/index.php3
-rwxr-xr-x[-rw-r--r--]web/js/app.js0
-rwxr-xr-x[-rw-r--r--]web/robots.txt0
205 files changed, 2259 insertions, 2280 deletions
diff --git a/.env.example b/.env.example
index e822287..e822287 100644..100755
--- a/.env.example
+++ b/.env.example
diff --git a/.gitignore b/.gitignore
index fdd1cab..fdd1cab 100644..100755
--- a/.gitignore
+++ b/.gitignore
diff --git a/LICENSE b/LICENSE
index 9cecc1d..9cecc1d 100644..100755
--- a/LICENSE
+++ b/LICENSE
diff --git a/Makefile b/Makefile
index 83911ce..6140991 100644..100755
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
-test:
+.PHONY: tests
+
+tests:
php -d memory_limit=4G vendor/bin/phpstan analyse -l 8 eywa
phpunit --coverage-html=coverage
diff --git a/README.md b/README.md
index 944ace7..944ace7 100644..100755
--- a/README.md
+++ b/README.md
diff --git a/app/Console/Hello.php b/app/Console/Hello.php
index 5add32d..5add32d 100644..100755
--- a/app/Console/Hello.php
+++ b/app/Console/Hello.php
diff --git a/app/Controllers/Auth/AuthController.php b/app/Controllers/Auth/AuthController.php
index 6e0e8ad..e34e54b 100644..100755
--- a/app/Controllers/Auth/AuthController.php
+++ b/app/Controllers/Auth/AuthController.php
@@ -80,7 +80,7 @@ namespace App\Controllers\Auth {
/**
* @inheritDoc
*/
- public function before_action(Request $request)
+ public function before_action(Request $request):void
{
// TODO: Implement before_action() method.
}
@@ -88,7 +88,7 @@ namespace App\Controllers\Auth {
/**
* @inheritDoc
*/
- public function after_action(Request $request)
+ public function after_action(Request $request):void
{
// TODO: Implement after_action() method.
}
diff --git a/app/Controllers/Email/WriteController.php b/app/Controllers/Email/WriteController.php
index 9190afd..b8dce92 100644..100755
--- a/app/Controllers/Email/WriteController.php
+++ b/app/Controllers/Email/WriteController.php
@@ -80,7 +80,7 @@ namespace App\Controllers\Email {
/**
* @inheritDoc
*/
- public function before_action(Request $request)
+ public function before_action(Request $request):void
{
// TODO: Implement before_action() method.
}
@@ -88,7 +88,7 @@ namespace App\Controllers\Email {
/**
* @inheritDoc
*/
- public function after_action(Request $request)
+ public function after_action(Request $request):void
{
// TODO: Implement after_action() method.
}
diff --git a/app/Controllers/Home/HomeController.php b/app/Controllers/Home/HomeController.php
index 56fa6c5..dd07520 100644..100755
--- a/app/Controllers/Home/HomeController.php
+++ b/app/Controllers/Home/HomeController.php
@@ -84,15 +84,15 @@ namespace App\Controllers\Home {
/**
* @inheritDoc
*/
- public function before_action(Request $request)
+ public function before_action(Request $request):void
{
- // TODO: Implement before_action() method.
+
}
/**
* @inheritDoc
*/
- public function after_action(Request $request)
+ public function after_action(Request $request):void
{
// TODO: Implement after_action() method.
}
diff --git a/app/Middleware/IpMiddleware.php b/app/Middleware/IpMiddleware.php
index 466b5bc..466b5bc 100644..100755
--- a/app/Middleware/IpMiddleware.php
+++ b/app/Middleware/IpMiddleware.php
diff --git a/app/Models/Auth.php b/app/Models/Auth.php
index d05e05b..7e37712 100644..100755
--- a/app/Models/Auth.php
+++ b/app/Models/Auth.php
@@ -4,8 +4,9 @@ namespace App\Models
{
use Eywa\Database\Model\Model;
+ use Eywa\Http\Request\Request;
- Class Auth extends Model
+ Class Auth extends Model
{
protected static string $table = 'auth';
@@ -17,6 +18,102 @@ namespace App\Models
{
return parent::destroy($id); // TODO: Change the autogenerated stub
}
+
+ /**
+ * @inheritDoc
+ */
+ public function before_validation(Request $request): bool
+ {
+ // TODO: Implement before_validation() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_validation(Request $request): bool
+ {
+ // TODO: Implement after_validation() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_save(Request $request): bool
+ {
+ // TODO: Implement before_save() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_save(Request $request): bool
+ {
+ // TODO: Implement after_save() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_commit(Request $request): bool
+ {
+ // TODO: Implement after_commit() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_rollback(Request $request): bool
+ {
+ // TODO: Implement after_rollback() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_update(Request $request): bool
+ {
+ // TODO: Implement before_update() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_update(Request $request): bool
+ {
+ // TODO: Implement after_update() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_create(Request $request): bool
+ {
+ // TODO: Implement before_create() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_create(Request $request): bool
+ {
+ // TODO: Implement after_create() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_destroy(Request $request): bool
+ {
+ // TODO: Implement before_destroy() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_destroy(Request $request): bool
+ {
+ // TODO: Implement after_destroy() method.
+ }
}
}
diff --git a/app/Models/User.php b/app/Models/User.php
index e0f5e26..f527037 100644..100755
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -4,8 +4,9 @@ namespace App\Models
{
use Eywa\Database\Model\Model;
+ use Eywa\Http\Request\Request;
- Class User extends Model
+ Class User extends Model
{
protected static string $table = 'auth';
@@ -14,6 +15,102 @@ namespace App\Models
protected static int $limit = 20;
- }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_validation(Request $request): bool
+ {
+ // TODO: Implement before_validation() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_validation(Request $request): bool
+ {
+ // TODO: Implement after_validation() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_save(Request $request): bool
+ {
+ // TODO: Implement before_save() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_save(Request $request): bool
+ {
+ // TODO: Implement after_save() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_commit(Request $request): bool
+ {
+ // TODO: Implement after_commit() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_rollback(Request $request): bool
+ {
+ // TODO: Implement after_rollback() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_update(Request $request): bool
+ {
+ // TODO: Implement before_update() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_update(Request $request): bool
+ {
+ // TODO: Implement after_update() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_create(Request $request): bool
+ {
+ // TODO: Implement before_create() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_create(Request $request): bool
+ {
+ // TODO: Implement after_create() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_destroy(Request $request): bool
+ {
+ // TODO: Implement before_destroy() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_destroy(Request $request): bool
+ {
+ // TODO: Implement after_destroy() method.
+ }
+ }
}
diff --git a/app/Validators/Users/UsersValidator.php b/app/Validators/Users/UsersValidator.php
index 06fda1b..06fda1b 100644..100755
--- a/app/Validators/Users/UsersValidator.php
+++ b/app/Validators/Users/UsersValidator.php
diff --git a/app/Views/Home/home.php b/app/Views/Home/home.php
index 1a03b16..1a03b16 100644..100755
--- a/app/Views/Home/home.php
+++ b/app/Views/Home/home.php
diff --git a/app/Views/layout.php b/app/Views/layout.php
index 73f1799..73f1799 100644..100755
--- a/app/Views/layout.php
+++ b/app/Views/layout.php
diff --git a/app/Views/maintenance.php b/app/Views/maintenance.php
index 9dfb1ee..9dfb1ee 100644..100755
--- a/app/Views/maintenance.php
+++ b/app/Views/maintenance.php
diff --git a/bidon/.gitignore b/bidon/.gitignore
index d6b7ef3..d6b7ef3 100644..100755
--- a/bidon/.gitignore
+++ b/bidon/.gitignore
diff --git a/cache/.gitignore b/cache/.gitignore
index d6b7ef3..d6b7ef3 100644..100755
--- a/cache/.gitignore
+++ b/cache/.gitignore
diff --git a/composer.json b/composer.json
index 9f270e0..3a41446 100644..100755
--- a/composer.json
+++ b/composer.json
@@ -11,9 +11,7 @@
"swiftmailer/swiftmailer": "^6.2",
"symfony/var-dumper": "^5.0",
"filp/whoops": "^2.5",
- "doctrine/annotations": "^1.8",
"ocramius/proxy-manager": "^2.2",
- "php-di/php-di": "^6.0",
"erusev/parsedown": "^1.7",
"scrivo/highlight.php": "^9.17",
"fzaninotto/faker": "^1.9",
@@ -31,8 +29,7 @@
"sinergi/browser-detector": "^6.1",
"mobiledetect/mobiledetectlib": "^2.8",
"vlucas/phpdotenv": "^4.1",
- "wapmorgan/file-type-detector": "^1.1",
- "phpstan/phpstan": "^0.12.11"
+ "wapmorgan/file-type-detector": "^1.1"
},
"authors": [
{
@@ -44,7 +41,8 @@
"psr-4": {
"Testing\\": "tests/",
"Base\\": "db/",
- "App\\": "app/"
+ "App\\": "app/",
+ "Ioc\\": "ioc/"
}
},
"autoload": {
@@ -62,5 +60,7 @@
"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": {
}
}
diff --git a/config/alert.yaml b/config/alert.yaml
index d769511..d769511 100644..100755
--- a/config/alert.yaml
+++ b/config/alert.yaml
diff --git a/config/app.yaml b/config/app.yaml
index 9aee7be..9aee7be 100644..100755
--- a/config/app.yaml
+++ b/config/app.yaml
diff --git a/config/auth.yaml b/config/auth.yaml
index 420676d..420676d 100644..100755
--- a/config/auth.yaml
+++ b/config/auth.yaml
diff --git a/config/connexion.yaml b/config/connexion.yaml
index 16d9d9a..16d9d9a 100644..100755
--- a/config/connexion.yaml
+++ b/config/connexion.yaml
diff --git a/config/flash.yaml b/config/flash.yaml
index 1049b77..1049b77 100644..100755
--- a/config/flash.yaml
+++ b/config/flash.yaml
diff --git a/config/form.yaml b/config/form.yaml
index 33ef1d2..33ef1d2 100644..100755
--- a/config/form.yaml
+++ b/config/form.yaml
diff --git a/config/hash.yaml b/config/hash.yaml
index b77b61e..b77b61e 100644..100755
--- a/config/hash.yaml
+++ b/config/hash.yaml
diff --git a/config/history.yaml b/config/history.yaml
index 1ae8258..1ae8258 100644..100755
--- a/config/history.yaml
+++ b/config/history.yaml
diff --git a/config/i18n.yaml b/config/i18n.yaml
index b3fc3da..b3fc3da 100644..100755
--- a/config/i18n.yaml
+++ b/config/i18n.yaml
diff --git a/config/mail.yaml b/config/mail.yaml
index f86564f..f86564f 100644..100755
--- a/config/mail.yaml
+++ b/config/mail.yaml
diff --git a/config/migrations.yaml b/config/migrations.yaml
index b8a1cc5..b8a1cc5 100644..100755
--- a/config/migrations.yaml
+++ b/config/migrations.yaml
diff --git a/config/pagination.yaml b/config/pagination.yaml
index 9ed7542..9ed7542 100644..100755
--- a/config/pagination.yaml
+++ b/config/pagination.yaml
diff --git a/config/validator.yaml b/config/validator.yaml
index be2efcf..be2efcf 100644..100755
--- a/config/validator.yaml
+++ b/config/validator.yaml
diff --git a/db/Migrations/AddPhoneToUsers.php b/db/Migrations/AddPhoneToUsers.php
index 43e738d..43e738d 100644..100755
--- a/db/Migrations/AddPhoneToUsers.php
+++ b/db/Migrations/AddPhoneToUsers.php
diff --git a/db/Migrations/CreateAuthTable.php b/db/Migrations/CreateAuthTable.php
index c96dfcc..c96dfcc 100644..100755
--- a/db/Migrations/CreateAuthTable.php
+++ b/db/Migrations/CreateAuthTable.php
diff --git a/db/Migrations/CreateUsersTable.php b/db/Migrations/CreateUsersTable.php
index ad1542c..ad1542c 100644..100755
--- a/db/Migrations/CreateUsersTable.php
+++ b/db/Migrations/CreateUsersTable.php
diff --git a/db/Seeds/AuthSeeder.php b/db/Seeds/AuthSeeder.php
index 94fb2f1..94fb2f1 100644..100755
--- a/db/Seeds/AuthSeeder.php
+++ b/db/Seeds/AuthSeeder.php
diff --git a/db/Seeds/UserSeeder.php b/db/Seeds/UserSeeder.php
index e1be53a..e1be53a 100644..100755
--- a/db/Seeds/UserSeeder.php
+++ b/db/Seeds/UserSeeder.php
diff --git a/db/dump/.gitignore b/db/dump/.gitignore
index 48e029b..48e029b 100644..100755
--- a/db/dump/.gitignore
+++ b/db/dump/.gitignore
diff --git a/eywa/Application/App.php b/eywa/Application/App.php
index df10461..f2fa35e 100644..100755
--- a/eywa/Application/App.php
+++ b/eywa/Application/App.php
@@ -12,12 +12,13 @@ namespace Eywa\Application {
use Eywa\Cache\RedisCache;
use Eywa\Collection\Collect;
use Eywa\Configuration\Config;
- use Eywa\Database\Connexion\Connexion;
+ use Eywa\Database\Connexion\Connect;
use Eywa\Database\Query\Sql;
use Eywa\Detection\Detect;
use Eywa\Exception\Kedavra;
use Eywa\File\File;
use Eywa\Html\Form\Form;
+ use Eywa\Http\Request\FormRequest;
use Eywa\Http\Request\Request;
use Eywa\Http\Request\ServerRequest;
use Eywa\Http\Response\JsonResponse;
@@ -25,7 +26,7 @@ namespace Eywa\Application {
use Eywa\Http\Response\Response;
use Eywa\Http\Routing\Router;
use Eywa\Http\View\View;
- use Eywa\Ioc\Container;
+ use Eywa\Ioc\Ioc;
use Eywa\Message\Email\Write;
use Eywa\Message\Flash\Flash;
use Eywa\Security\Authentication\Auth;
@@ -34,6 +35,7 @@ namespace Eywa\Application {
use Eywa\Session\Session;
use Eywa\Session\SessionInterface;
use Eywa\Time\Timing;
+ use Eywa\Validate\Validator;
use Redis;
class App extends Zen implements Eywa
@@ -100,7 +102,7 @@ namespace Eywa\Application {
*/
public function ioc(string $key)
{
- return Container::ioc()->get($key);
+ return (new Ioc())->get($key);
}
/**
@@ -188,9 +190,9 @@ namespace Eywa\Application {
* @inheritDoc
*
*/
- public function request(): Request
+ public function request(array $args = []): Request
{
- return cli() ? new Request() : Request::generate();
+ return cli() ? new Request() : Request::make($args);
}
/**
@@ -212,9 +214,9 @@ namespace Eywa\Application {
/**
* @inheritDoc
*/
- public function form(string $url,string $method = POST,array $options = []): Form
+ public function form(FormRequest $request) : Form
{
- return new Form($url,$method,$options);
+ return new Form($request);
}
/**
@@ -265,19 +267,14 @@ namespace Eywa\Application {
{
case APCU_CACHE:
return new ApcuCache();
- break;
case FILE_CACHE:
return new FileCache();
- break;
case MEMCACHE_CACHE:
return new MemcacheCache();
- break;
case REDIS_CACHE:
return new RedisCache();
- break;
default:
throw new Kedavra('The apdater is not supported');
- break;
}
}
@@ -338,7 +335,7 @@ namespace Eywa\Application {
* @inheritDoc
*
*/
- public function validator(string $validator): Response
+ public function validator(Validator $validator): Response
{
return $this->request()->validate($validator);
}
@@ -384,9 +381,9 @@ namespace Eywa\Application {
/**
* @inheritDoc
*/
- public function connexion(): Connexion
+ public function connexion(): Connect
{
- return equal($this->config('mode','connexion'),'prod') ? production() : development();
+ return $this->ioc(Connect::class);
}
/**
diff --git a/eywa/Application/Environment/Env.php b/eywa/Application/Environment/Env.php
index 5f432bb..84738f8 100644..100755
--- a/eywa/Application/Environment/Env.php
+++ b/eywa/Application/Environment/Env.php
@@ -40,12 +40,12 @@ namespace Eywa\Application\Environment {
*
* Get an environement variable
*
- * @param $variable
+ * @param string $variable
*
- * @return array|false|string
+ * @return array<mixed>|false|string
*
*/
- public function get($variable)
+ public function get(string $variable)
{
return getenv($variable);
}
diff --git a/eywa/Application/Eywa.php b/eywa/Application/Eywa.php
index 4ae79e8..bccbfd8 100644..100755
--- a/eywa/Application/Eywa.php
+++ b/eywa/Application/Eywa.php
@@ -10,18 +10,21 @@ namespace Eywa\Application {
use Exception;
use Eywa\Cache\CacheInterface;
use Eywa\Collection\Collect;
+ use Eywa\Database\Connexion\Connect;
use Eywa\Database\Connexion\Connexion;
use Eywa\Database\Query\Sql;
use Eywa\Detection\Detect;
use Eywa\Exception\Kedavra;
use Eywa\File\File;
use Eywa\Html\Form\Form;
+ use Eywa\Http\Request\FormRequest;
use Eywa\Http\Request\Request;
use Eywa\Http\Response\Response;
use Eywa\Message\Email\Write;
use Eywa\Security\Authentication\Auth;
use Eywa\Security\Crypt\Crypter;
use Eywa\Session\SessionInterface;
+ use Eywa\Validate\Validator;
use Redis;
interface Eywa
@@ -94,7 +97,7 @@ namespace Eywa\Application {
*
* @param string $content
* @param int $status
- * @param array $headers
+ * @param array<string> $headers
* @param string $url
*
* @return Response
@@ -109,7 +112,7 @@ namespace Eywa\Application {
* Redirect user to an another route
*
* @param string $route
- * @param array $route_args
+ * @param array<mixed> $route_args
* @param string $message
* @param bool $success
* @param int $status
@@ -127,7 +130,7 @@ namespace Eywa\Application {
*
* Get an instance of collect
*
- * @param array $data
+ * @param array<mixed> $data
*
* @return Collect
*
@@ -138,14 +141,14 @@ namespace Eywa\Application {
*
* Get the validator
*
- * @param string $validator
+ * @param Validator $validator
*
* @return Response
*
* @throws Kedavra
*
*/
- public function validator(string $validator): Response;
+ public function validator(Validator $validator): Response;
/**
*
@@ -156,8 +159,6 @@ namespace Eywa\Application {
* @return Sql
*
* @throws Kedavra
- * @throws DependencyException
- * @throws NotFoundException
* @throws Exception
*
*/
@@ -202,16 +203,15 @@ namespace Eywa\Application {
*
* Get the form builder instance
*
- * @param string $url
- * @param string $method
- * @param array $options
+ * @param FormRequest $request
*
* @return Form
- * @throws Exception
*
+ * @throws Kedavra
+ * @throws Exception
*
*/
- public function form(string $url,string $method = POST,array $options = []) : Form;
+ public function form(FormRequest $request) : Form;
/**
*
@@ -222,6 +222,9 @@ namespace Eywa\Application {
*
* @return mixed
*
+ * @throws Kedavra
+ *
+ *
*/
public function get(string $key,$default = null);
@@ -234,6 +237,8 @@ namespace Eywa\Application {
*
* @return mixed
*
+ * @throws Kedavra
+ *
*/
public function post(string $key,$default = null);
@@ -246,6 +251,8 @@ namespace Eywa\Application {
*
* @return mixed
*
+ * @throws Kedavra
+ *
*/
public function cookie(string $key,$default = null);
@@ -259,6 +266,8 @@ namespace Eywa\Application {
*
* @return mixed
*
+ * @throws Kedavra
+ *
*/
public function server(string $key,$default = null);
@@ -280,10 +289,15 @@ namespace Eywa\Application {
*
* Get a request instance
*
+ * @param array<mixed> $args
+ *
* @return Request
*
+ * @throws Kedavra
+ *
+ *
*/
- public function request(): Request;
+ public function request(array $args = []): Request;
/**
*
@@ -301,13 +315,13 @@ namespace Eywa\Application {
* @param string $view
* @param string $title
* @param string $description
- * @param array $args
+ * @param array<mixed> $args
*
* @return Response
*
* @throws Kedavra
- * @throws DependencyException
- * @throws NotFoundException
+ * @throws Exception
+ *
*
*/
public function view(string $view,string $title,string $description,array $args =[]): Response;
@@ -319,8 +333,7 @@ namespace Eywa\Application {
* @return Response
*
* @throws Kedavra
- * @throws DependencyException
- * @throws NotFoundException
+ * @throws Exception
*
*/
public function run(): Response;
@@ -329,7 +342,7 @@ namespace Eywa\Application {
*
* Return a json response
*
- * @param array $data
+ * @param array<mixed> $data
* @param int $status
*
* @return Response
@@ -343,12 +356,13 @@ namespace Eywa\Application {
*
* Get an instance of connexion (PDO)
*
- * @return Connexion
+ * @return Connect
*
* @throws Kedavra
+ * @throws Exception
*
*/
- public function connexion(): Connexion;
+ public function connexion(): Connect;
/**
*
@@ -380,8 +394,6 @@ namespace Eywa\Application {
* @return Response
*
* @throws Kedavra
- * @throws DependencyException
- * @throws NotFoundException
*
*/
public function back(string $message ='',bool $success = true): Response;
@@ -391,7 +403,7 @@ namespace Eywa\Application {
* Go to a specific url by a route it's route name
*
* @param string $route
- * @param array $route_args
+ * @param array<mixed> $route_args
* @param string $message
* @param bool $success
*
diff --git a/eywa/Application/Zen.php b/eywa/Application/Zen.php
index 2a89181..2a89181 100644..100755
--- a/eywa/Application/Zen.php
+++ b/eywa/Application/Zen.php
diff --git a/eywa/Cache/ApcuCache.php b/eywa/Cache/ApcuCache.php
index b368f13..b368f13 100644..100755
--- a/eywa/Cache/ApcuCache.php
+++ b/eywa/Cache/ApcuCache.php
diff --git a/eywa/Cache/CacheInterface.php b/eywa/Cache/CacheInterface.php
index a1e7612..acf5324 100644..100755
--- a/eywa/Cache/CacheInterface.php
+++ b/eywa/Cache/CacheInterface.php
@@ -28,7 +28,7 @@ namespace Eywa\Cache {
* Set a value
*
* @param string $key
- * @param $value
+ * @param mixed $value
*
* @return $this
*
diff --git a/eywa/Cache/FileCache.php b/eywa/Cache/FileCache.php
index 9c89ccc..31ece48 100644..100755
--- a/eywa/Cache/FileCache.php
+++ b/eywa/Cache/FileCache.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Eywa\Cache {
- use Exception;
use Eywa\File\File;
class FileCache implements CacheInterface
@@ -60,26 +59,18 @@ namespace Eywa\Cache {
return intval(env('CACHE_TTL',CACHE_DEFAULT_TTL));
}
+
/**
- *
- * Get the directory path
- *
- * @return string
- *
- * @throws Exception
- *
+ * @inheritDoc
*/
public function directory(): string
{
- return env('CACHE_DIRECTORY','cache');
+ return 'cache';
}
+
/**
- * @param string $key
- * @return string
- *
- * @throws Exception
- *
+ * @inheritDoc
*/
public function file(string $key): string
{
diff --git a/eywa/Cache/MemcacheCache.php b/eywa/Cache/MemcacheCache.php
index 43c2995..43c2995 100644..100755
--- a/eywa/Cache/MemcacheCache.php
+++ b/eywa/Cache/MemcacheCache.php
diff --git a/eywa/Cache/RedisCache.php b/eywa/Cache/RedisCache.php
index 51e1bd7..51e1bd7 100644..100755
--- a/eywa/Cache/RedisCache.php
+++ b/eywa/Cache/RedisCache.php
diff --git a/eywa/Collection/Collect.php b/eywa/Collection/Collect.php
index f5d6855..23da506 100644..100755
--- a/eywa/Collection/Collect.php
+++ b/eywa/Collection/Collect.php
@@ -15,8 +15,10 @@ namespace Eywa\Collection {
*
* The data
*
+ * @var array<mixed>
+ *
*/
- private $data = [];
+ private array $data = [];
/**
*
@@ -38,31 +40,31 @@ namespace Eywa\Collection {
*
* Collection constructor
*
- * @method __construct
- *
- * @param mixed $data
+ * @param array<mixed> $data
*
*/
- public function __construct($data)
+ public function __construct(array $data)
{
- $this->data = (is_object($data) ? obj($data) : is_array($data)) ? $data : [];
-
+ $this->data = $data;
$this->position();
}
/**
*
- * @param array $keys
- * @param array $values
+ * @param array<mixed> $keys
+ * @param array<mixed> $values
*
* @return Collect
*
*/
public function combine(array $keys, array $values): Collect
{
- return $this->checkout(array_combine($keys, $values));
+ $x = array_combine($keys, $values);
+
+ return is_bool($x) ? $this : $this->checkout($x);
+
}
/**
@@ -93,7 +95,6 @@ namespace Eywa\Collection {
/**
*
*
- *
* @return int|mixed|string
*
*/
@@ -106,8 +107,6 @@ namespace Eywa\Collection {
*
* Count all values found
*
- * @method count
- *
* @return Collect
*
*/
@@ -120,8 +119,6 @@ namespace Eywa\Collection {
*
* Initialise position counter
*
- * @method init
- *
* @param int $i
*
* @return int
@@ -137,8 +134,6 @@ namespace Eywa\Collection {
*
* Extract a slice of the array
*
- * @method slice
- *
* @param int $offset
* @param int|null $limit
*
@@ -155,8 +150,6 @@ namespace Eywa\Collection {
*
* Chunk the array in separate array
*
- * @method chunk
- *
* @param int $x
*
* @return Collect
@@ -179,9 +172,7 @@ namespace Eywa\Collection {
*
* Return the array generated
*
- * @method all
- *
- * @return array
+ * @return array<mixed>
*
**/
public function all(): array
@@ -193,14 +184,13 @@ namespace Eywa\Collection {
*
* Get specifics keys
*
- * @method only
*
- * @param mixed ...$keys
+ * @param array<mixed> $keys
*
* @return Collect
*
*/
- public function only(...$keys): Collect
+ public function only(array $keys): Collect
{
$x = collect();
foreach ($this->all() as $k => $v)
@@ -216,9 +206,7 @@ namespace Eywa\Collection {
*
* Compare the array with the x array
*
- * @method diff
- *
- * @param array $x
+ * @param array<mixed> $x
*
* @return Collect
*
@@ -232,8 +220,6 @@ namespace Eywa\Collection {
*
* Return the last element of the array
*
- * @method last
- *
* @return mixed
*
*/
@@ -246,7 +232,6 @@ namespace Eywa\Collection {
*
* Return the first element of the array
*
- * @method first
*
* @return mixed
*
@@ -260,7 +245,6 @@ namespace Eywa\Collection {
*
* Return the reverse of the array
*
- * @method reverse
*
* @return Collect
*
@@ -274,14 +258,13 @@ namespace Eywa\Collection {
*
* Return a value before a key
*
- * @method value_before_key
*
- * @param mixed $key The next value key
+ * @param string $key The next value key
*
* @return mixed
*
*/
- public function value_before_key($key)
+ public function value_before_key(string $key)
{
if ($this->has($key))
{
@@ -298,8 +281,6 @@ namespace Eywa\Collection {
*
* Collect all values
*
- * @method values
- *
* @return Collect
*
*/
@@ -312,8 +293,6 @@ namespace Eywa\Collection {
*
* Collect all keys
*
- * @method keys
- *
* @return Collect
*
*/
@@ -327,8 +306,6 @@ namespace Eywa\Collection {
* Move pointer to the before position
* and return the current value
*
- * @method before
- *
* @return mixed
*
*/
@@ -343,7 +320,6 @@ namespace Eywa\Collection {
* Move pointer to the after position
* and return the current value
*
- * @method after
*
* @return mixed
*
@@ -358,24 +334,22 @@ namespace Eywa\Collection {
*
* Get a value in the array by a key
*
- * @method get
*
* @param mixed $key
*
- * @return mixed|string
+ * @return mixed
+ *
*
*/
public function get($key)
{
- return $this->has($key) ? $this->data[$key] : '';
+ return $this->data[$key];
}
/**
*
* Return the max value in the array
*
- * @method max
- *
* @return mixed
*
*/
@@ -388,7 +362,6 @@ namespace Eywa\Collection {
*
* Get the min value in the array
*
- * @method min
*
* @return mixed
*
@@ -402,9 +375,7 @@ namespace Eywa\Collection {
*
* Check if the array has not a key
*
- * @method has_not
- *
- * @param $key
+ * @param mixed $key
*
* @return bool
*
@@ -479,8 +450,6 @@ namespace Eywa\Collection {
*
* Check if array is empty
*
- * @method empty
- *
* @return bool
*
*/
@@ -493,9 +462,7 @@ namespace Eywa\Collection {
*
* Computes the intersection of arrays
*
- * @method intersect
- *
- * @param array $x
+ * @param array<mixed> $x
*
* @return Collect
*
@@ -509,9 +476,8 @@ namespace Eywa\Collection {
*
* Replaces elements in the array
*
- * @method refresh
*
- * @param array ...$data
+ * @param array<mixed> ...$data
*
* @return Collect
*
@@ -525,8 +491,6 @@ namespace Eywa\Collection {
*
* Sort an array in reverse order and maintain index association
*
- * @method arsort
- *
* @return Collect
*
*/
@@ -540,8 +504,6 @@ namespace Eywa\Collection {
*
* Sort the array and maintain index association
*
- * @method asort
- *
* @param int $flag
*
* @return Collect
@@ -557,14 +519,13 @@ namespace Eywa\Collection {
*
* Removes an item from the collection by its key
*
- * @method forget
*
- * @param mixed ...$keys
+ * @param array<mixed> $keys
*
* @return Collect
*
*/
- public function forget(...$keys): Collect
+ public function forget(array $keys): Collect
{
foreach ($keys as $key)
$this->del($key);
@@ -575,8 +536,6 @@ namespace Eywa\Collection {
*
* Removes duplicate values from an array
*
- * @method unique
- *
* @return Collect
*
*/
@@ -589,8 +548,6 @@ namespace Eywa\Collection {
*
* Take specified items in the array
*
- * @method take
- *
* @param int $x
*
* @return Collect
@@ -605,20 +562,37 @@ namespace Eywa\Collection {
*
* Calculate the product of values in an array
*
- * @return int
+ * @return int|float
*
*/
- public function product(): int
+ public function product()
{
return array_product($this->all());
}
+ /**
+ *
+ *
+ * @param callable $callable
+ *
+ * @return Collect
+ *
+ */
public function map($callable)
{
return $this->checkout(array_map($callable, $this->all()));
}
- public function reduce($callable)
+ /**
+ *
+ *
+ *
+ * @param callable $callable
+ *
+ * @return Collect
+ *
+ */
+ public function reduce($callable): Collect
{
return $this->checkout(array_reduce($this->all(), $callable));
}
@@ -627,10 +601,9 @@ namespace Eywa\Collection {
*
* Filters elements of the array
*
- * @method filter
*
- * @param $callable
- * @param int $flag
+ * @param callable $callable
+ * @param int $flag
*
* @return Collect
*
@@ -644,7 +617,6 @@ namespace Eywa\Collection {
*
* Display element for a page
*
- * @method display
*
* @param int $page
* @param int $limit
@@ -661,8 +633,6 @@ namespace Eywa\Collection {
*
* Sort the array
*
- * @method sort
- *
* @param int $flag
*
* @return Collect
@@ -679,7 +649,6 @@ namespace Eywa\Collection {
*
* Exchanges all keys with their associated values in an array
*
- * @method flip
*
* @return Collect
*
@@ -693,7 +662,6 @@ namespace Eywa\Collection {
*
* Shuffle an array
*
- * @method shuffle
*
* @return Collect
*
@@ -704,6 +672,13 @@ namespace Eywa\Collection {
return $this->checkout($this->all());
}
+ /**
+ *
+ * @param int $flag
+ *
+ * @return Collect
+ *
+ */
public function krsort(int $flag = SORT_REGULAR): Collect
{
krsort($this->data, $flag);
@@ -711,6 +686,7 @@ namespace Eywa\Collection {
}
/**
+ *
* @param int $flag
*
* @return Collect
@@ -726,7 +702,6 @@ namespace Eywa\Collection {
*
* Create an array containing a range of elements
*
- * @method range
*
* @param int $start
* @param int $end
@@ -744,10 +719,9 @@ namespace Eywa\Collection {
*
* Assign a new value to an existing value
*
- * @method refresh
*
- * @param $old_value
- * @param $new_value
+ * @param mixed $old_value
+ * @param mixed $new_value
*
* @return Collect
*
@@ -769,85 +743,69 @@ namespace Eywa\Collection {
*
* Add values to the end of the array
*
- * @method push
*
- * @param mixed[] $values The values to add
+ * @param mixed $value
*
* @return Collect
*
*/
- public function push(...$values): Collect
+ public function push($value): Collect
{
- foreach ($values as $value)
- {
- array_push($this->data,$value);
-
- }
+ array_push($this->data,$value);
return $this->checkout($this->data);
}
-
/**
*
* Add the values to the begin ot the array
*
- * @method stack
- *
- * @param mixed[] $values The values to add
+ * @param mixed $value
*
* @return Collect
*
*/
- public function stack(...$values): Collect
+ public function stack($value): Collect
{
- foreach ($values as $value)
- array_unshift($this->data, $value);
- return $this;
+ array_unshift($this->data, $value);
+
+ return $this->checkout($this->data);
}
/**
*
* Merge multiples array
*
- * @method merge
- *
- * @param $array
+ * @param array<mixed> $array
*
* @return Collect
+ *
*/
- public function merge(array ...$array): Collect
+ public function merge(array $array): Collect
{
- foreach ($array as $x)
- $this->data = array_merge($this->data, $x);
- return $this;
+ $this->data = array_merge($this->data, $array);
+ return $this->checkout($this->data);
}
/**
*
* Defines only values
*
- * @method set
- *
- * @param mixed ...$values
+ * @param mixed $value
*
* @return Collect
*
*/
- public function set(...$values): Collect
+ public function set($value): Collect
{
- foreach ($values as $value)
- $this->add($value);
- return $this;
+ return $this->add($value);
}
/**
*
* Add the value accessible by the key
*
- * @method put
- *
* @param mixed $key
* @param mixed $value
*
@@ -863,17 +821,16 @@ namespace Eywa\Collection {
*
* Remove values or keys inside the array
*
- * @method del
- *
- * @param mixed ...$data
+ * @param array<mixed> $data
*
* @return Collect
*
*/
- public function del(...$data): Collect
+ public function del(array $data): Collect
{
foreach ($data as $datum)
$this->exist($datum) ? $this->remove_value($datum) : $this->remove($datum);
+
return $this->checkout($this->all());
}
@@ -881,9 +838,7 @@ namespace Eywa\Collection {
*
* Join all values by a glue
*
- * @method join
- *
- * @param string $glue The values separator
+ * @param string $glue
*
* @return string
*
@@ -897,8 +852,6 @@ namespace Eywa\Collection {
*
* Join all keys by a glue
*
- * @method join_keys
- *
* @param string $glue
*
* @return string
@@ -913,8 +866,6 @@ namespace Eywa\Collection {
*
* Check if false was not found
*
- * @method ok
- *
* @return bool
*
*/
@@ -927,9 +878,7 @@ namespace Eywa\Collection {
*
* Check if a value exist in the array
*
- * @method exist
- *
- * @param mixed $value The value to check
+ * @param mixed $value
*
* @return bool
*
@@ -943,24 +892,20 @@ namespace Eywa\Collection {
*
* Check if a key exist in the array
*
- * @method has_key
- *
- * @param mixed $key The key to check
+ * @param int|string $key
*
* @return bool
*
*/
public function has($key): bool
{
- return is_string($key) || is_numeric($key) ? array_key_exists($key, $this->all()) : false;
+ return array_key_exists($key, $this->all());
}
/**
*
* Check if the value not exist in the array
*
- * @method not_exist
- *
* @param mixed $value The value to check
*
* @return bool
@@ -975,8 +920,6 @@ namespace Eywa\Collection {
*
* Clear the array
*
- * @method clear
- *
* @return Collect
*
*/
@@ -989,8 +932,6 @@ namespace Eywa\Collection {
*
* Return the number of elements in the array
*
- * @method sum
- *
* @return int
*
*/
@@ -1003,23 +944,20 @@ namespace Eywa\Collection {
*
* Remove the first element
*
- * @method shift
- *
* @return Collect
*
*/
public function shift(): Collect
{
array_shift($this->data);
- return $this;
+
+ return $this->checkout($this->data);
}
/**
*
* Remove the last element
*
- * @method pop
- *
* @return Collect
*
*/
@@ -1027,37 +965,35 @@ namespace Eywa\Collection {
{
array_pop($this->data);
- return $this;
+ return $this->checkout($this->data);
}
/**
*
* Checkout on the new array
*
- * @method checkout
- *
- * @param array $data
+ * @param array<mixed> $data
*
* @return Collect
*
*/
public function checkout(array $data): Collect
{
- return new static($data);
+ return new self($data);
}
/**
*
* Convert the array in a json string
*
- * @method json
- *
* @return string
*
*/
public function json(): string
{
- return json_encode($this->all(), JSON_FORCE_OBJECT);
+ $x = json_encode($this->all(), JSON_FORCE_OBJECT);
+
+ return is_bool($x) ? '' : $x;
}
@@ -1066,18 +1002,17 @@ namespace Eywa\Collection {
*
* Run callable function for each values and keys in the array
*
- * @method each
- *
* @param callable $callable
*
* @return Collect
*
*/
- public function each($callable): Collect
+ public function each(callable $callable): Collect
{
$result = collect();
foreach ($this->all() as $k => $v)
- $result->set($callable($k, $v));
+ $result->put($k,call_user_func_array($callable,[$k,$v]));
+
return $this->checkout($result->all());
}
@@ -1085,18 +1020,16 @@ namespace Eywa\Collection {
*
* Execute the callable with all value in the array
*
- * @method for
- *
* @param callable $callable
*
* @return Collect
*
*/
- public function for($callable): Collect
+ public function for(callable $callable): Collect
{
$result = collect();
foreach ($this->all() as $k => $items) {
- $result->put($k, $callable($items));
+ $result->put($k, call_user_func_array($callable,[$items]));
}
return $this->checkout($result->all());
}
@@ -1105,12 +1038,12 @@ namespace Eywa\Collection {
*
* Initialise all keys to value
*
- * @param $value
+ * @param mixed $value
*
* @return Collect
*
*/
- public function init($value)
+ public function init($value): Collect
{
return $this->checkout(array_fill_keys($this->keys()->all(), $value));
}
@@ -1119,14 +1052,12 @@ namespace Eywa\Collection {
*
* Add the value only if not exist
*
- * @method uniq
- *
- * @param array $values
+ * @param array<mixed> $values
*
* @return Collect
*
*/
- public function uniq(...$values): Collect
+ public function uniq(array $values): Collect
{
foreach ($values as $value)
{
@@ -1140,8 +1071,6 @@ namespace Eywa\Collection {
*
* Append value to the array with optional key
*
- * @method add
- *
* @param mixed $value The value to add
* @param mixed $key The value's key
*
@@ -1151,6 +1080,7 @@ namespace Eywa\Collection {
private function add($value, $key = ''): Collect
{
not_def($key) ? $this->data[] = $value : $this->data[$key] = $value;
+
return $this;
}
@@ -1158,14 +1088,12 @@ namespace Eywa\Collection {
*
* Remove a data by a key
*
- * @method remove
- *
- * @param array $keys
+ * @param array<mixed> $keys
*
* @return Collect
*
*/
- private function remove(...$keys): Collect
+ private function remove(array $keys): Collect
{
foreach ($keys as $key)
{
@@ -1179,12 +1107,12 @@ namespace Eywa\Collection {
*
* Remove a value in the array
*
- * @param array $values
+ * @param array<mixed> $values
*
* @return Collect
*
*/
- private function remove_value(...$values): Collect
+ private function remove_value(array $values): Collect
{
foreach ($values as $value)
{
diff --git a/eywa/Configuration/Config.php b/eywa/Configuration/Config.php
index b6ef642..d9db8d3 100644..100755
--- a/eywa/Configuration/Config.php
+++ b/eywa/Configuration/Config.php
@@ -7,7 +7,6 @@ namespace Eywa\Configuration {
use Eywa\Collection\Collect;
use Eywa\Exception\Kedavra;
- use Eywa\File\File;
use Symfony\Component\Yaml\Yaml;
class Config extends Yaml
@@ -65,11 +64,11 @@ namespace Eywa\Configuration {
$file = $this->path() . DIRECTORY_SEPARATOR . collect(explode('.', $file))->first() . self::EXT;
- is_false(File::exist($file), true, "The $file file was not found at " . $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, "The $key key was not found in the $file at " . $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;
@@ -79,7 +78,6 @@ namespace Eywa\Configuration {
/**
* Get config.yaml path
*
- * @method path
*
* @return string
*
@@ -93,7 +91,6 @@ namespace Eywa\Configuration {
*
* Get the config.yaml value
*
- * @method value
*
* @return mixed
*
diff --git a/eywa/Console/App/AppSend.php b/eywa/Console/App/AppSend.php
index 83389e4..0ce578e 100644..100755
--- a/eywa/Console/App/AppSend.php
+++ b/eywa/Console/App/AppSend.php
@@ -12,10 +12,12 @@
{
protected static $defaultName = 'app:send';
-
- protected function configure()
+
+
+ protected function configure():void
{
$this->setDescription('Send the application to the server');
+
}
public function execute(InputInterface $input, OutputInterface $output)
diff --git a/eywa/Console/App/Coverage.php b/eywa/Console/App/Coverage.php
index 961d5af..9c6e7b3 100644..100755
--- a/eywa/Console/App/Coverage.php
+++ b/eywa/Console/App/Coverage.php
@@ -16,7 +16,7 @@
protected static $defaultName = "app:coverage";
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Run a server to show the code coverage');
}
diff --git a/eywa/Console/App/Dkim.php b/eywa/Console/App/Dkim.php
index bb0c360..d17f8ec 100644..100755
--- a/eywa/Console/App/Dkim.php
+++ b/eywa/Console/App/Dkim.php
@@ -15,7 +15,7 @@
protected static $defaultName = 'dkim:generate';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Generate dkim keys');
}
diff --git a/eywa/Console/App/Key.php b/eywa/Console/App/Key.php
index 0cb5fba..ec6bc84 100644..100755
--- a/eywa/Console/App/Key.php
+++ b/eywa/Console/App/Key.php
@@ -14,7 +14,7 @@ class Key extends Command
protected static $defaultName = 'key:generate';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Generate app key');
diff --git a/eywa/Console/App/Serve.php b/eywa/Console/App/Serve.php
index 834bdcf..fe03a4a 100644..100755
--- a/eywa/Console/App/Serve.php
+++ b/eywa/Console/App/Serve.php
@@ -16,7 +16,7 @@
protected static $defaultName = "app:run";
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Run a development server');
}
diff --git a/eywa/Console/App/TestCommand.php b/eywa/Console/App/TestCommand.php
index b712bae..52f6ecc 100644..100755
--- a/eywa/Console/App/TestCommand.php
+++ b/eywa/Console/App/TestCommand.php
@@ -13,7 +13,7 @@
protected static $defaultName = 'app:test';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Test the application');
}
diff --git a/eywa/Console/Cache/ClearCache.php b/eywa/Console/Cache/ClearCache.php
index bff07df..cc3c368 100644..100755
--- a/eywa/Console/Cache/ClearCache.php
+++ b/eywa/Console/Cache/ClearCache.php
@@ -14,11 +14,12 @@ namespace Eywa\Console\Cache {
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
+
class ClearCache extends Command
{
protected static $defaultName = 'cache:clear';
- protected function configure()
+ protected function configure():void
{
$this->setDescription("Clean all cache systems")->addArgument('system', InputArgument::OPTIONAL, 'The cahe system name to clear')->addArgument('mode',InputArgument::OPTIONAL,'The clear mode')->addArgument('interval',InputArgument::OPTIONAL,'The clear interval for watch mode');;
}
@@ -32,13 +33,14 @@ namespace Eywa\Console\Cache {
{
$io = new SymfonyStyle($input,$output);
- $x = $input->getArgument('system');
+ $x = strval($input->getArgument('system'));
+
- $mode = $input->getArgument('mode');
+ $mode = strval($input->getArgument('mode'));
$time = def($input->getArgument('interval')) ? intval($input->getArgument('interval')) : 20;
- if (is_null($x))
+ if (def($x))
{
if ((new FileCache())->clear())
@@ -56,6 +58,11 @@ namespace Eywa\Console\Cache {
else
$io->error('The apcu cache has not been removed');
+ if ((new MemcacheCache())->clear())
+ $io->success('The memcache cache has been removed sucessfully');
+ else
+ $io->error('The memcache cache has not been removed');
+
$io->success('All cache systems are now empty');
return 0;
}
@@ -63,7 +70,7 @@ namespace Eywa\Console\Cache {
{
if (def($mode) && $mode === 'watch')
{
- $io->title("Clearing the $x cache after every $time seconds of interval");
+ $io->title(sprintf("Clearing the %s cache after every %d seconds of interval",$x,$time));
if ($x == 'all')
{
@@ -73,24 +80,26 @@ namespace Eywa\Console\Cache {
sleep($time);
if ((new FileCache())->clear())
- $io->success('The file cache has been removed sucessfully');
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
else
$io->error('The file cache has not been removed');
if ((new RedisCache())->clear())
- $io->success('The redis cache has been removed sucessfully');
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
else
$io->error('The redis cache has not been removed');
if ((new ApcuCache())->clear())
- $io->success('The apcu cache has been removed sucessfully');
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
else
$io->error('The apcu cache has not been removed');
-
+ if ((new MemcacheCache())->clear())
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error('The memcache cache has not been removed');
}
- $io->success('Cancel command has be found exit');
- return 0;
+
}else
{
while (true)
@@ -101,62 +110,73 @@ namespace Eywa\Console\Cache {
{
case 'redis':
if((new RedisCache())->clear())
- $io->success("The $x cache has been reset successfully");
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
case 'file':
if((new FileCache())->clear())
- $io->success("The $x cache has been reset successfully");
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
case 'apcu':
if((new ApcuCache())->clear())
- $io->success("The $x cache has been reset successfully");
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
case 'memcache':
if((new MemcacheCache())->clear())
- $io->success("The $x cache has been reset successfully");
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
default:
$io->error('The cache system used is not a valid system');
break;
}
}
- $io->success('Cancel command has be found exit');
- return 0;
}
}else{
-
- $io->title('We clearing the cache');
+ $io->title(sprintf("Clearing the %s cache",$x));
switch ($x)
{
case 'redis':
- (new RedisCache())->clear();
- $io->success("The $x cache has been reset successfully");
- return 0;
+ if((new RedisCache())->clear())
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
case 'file':
- (new FileCache())->clear();
- $io->success("The $x cache has been reset successfully");
- return 0;
+ if((new FileCache())->clear())
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
case 'apcu':
- (new ApcuCache())->clear();
- $io->success("The $x cache has been reset successfully");
- return 0;
+ if((new ApcuCache())->clear())
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
case 'memcache':
- (new MemcacheCache())->clear();
- $io->success("The $x cache has been reset successfully");
- return 0;
+ if((new MemcacheCache())->clear())
+ $io->success(sprintf('The %s cache has been reset successfully',$x));
+ else
+ $io->error(sprintf('The %s cache has not been reset',$x));
break;
default:
$io->error('The cache system used is not a valid system');
break;
}
}
+ $io->success('All cache systems are now empty');
return 0;
}
-
+ $io->error('command not work');
+ return 1;
}
}
} \ No newline at end of file
diff --git a/eywa/Console/Console.php b/eywa/Console/Console.php
index deece4a..987abc4 100644..100755
--- a/eywa/Console/Console.php
+++ b/eywa/Console/Console.php
@@ -24,11 +24,11 @@ namespace Eywa\Console {
use Eywa\Console\Database\ShowUsers;
use Eywa\Console\Database\TruncateTable;
use Eywa\Console\Database\UninstallDatabase;
+ use Eywa\Console\Generate\GenerateCommand;
use Eywa\Console\Generate\GenerateController;
use Eywa\Console\Generate\GenerateMiddleware;
use Eywa\Console\Generate\GenerateMigration;
use Eywa\Console\Generate\GenerateModel;
- use Eywa\Console\Generate\GenerateRouteBase;
use Eywa\Console\Generate\GenerateSeeds;
use Eywa\Console\Generate\GenerateTest;
use Eywa\Console\Generate\GenerateValidator;
@@ -41,10 +41,12 @@ namespace Eywa\Console {
use Eywa\Console\Mode\Maintenance;
use Eywa\Console\Mode\ProductionMode;
use Eywa\Console\Routes\AddRoute;
+ use Eywa\Console\Routes\FindRoute;
use Eywa\Console\Routes\ListRoute;
use Eywa\Console\Routes\RemoveRoute;
use Eywa\Console\Routes\UpdateRoute;
use Symfony\Component\Console\Application;
+ use Symfony\Component\Console\Command\Command;
class Console
@@ -61,7 +63,7 @@ namespace Eywa\Console {
*
* Add a command
*
- * @param array $commands
+ * @param array<mixed> $commands
*
* @return Console
*
@@ -88,9 +90,9 @@ namespace Eywa\Console {
{
$commands = [
- new CreateCatalogues(),new UpdateCatalogues(), new AddRoute(), new UpdateRoute(), new ListRoute(), new RemoveRoute(), new GenerateRouteBase(), new GenerateView(), new GenerateController(),new GenerateModel(),new GenerateMigration(),new GenerateSeeds(),new GenerateTest(),new GenerateMiddleware(),
+ 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 InstallDatabase(), new UninstallDatabase(),new ShowUsers(),new Documentation(),new Wanted(),new GenerateValidator(),new AppSend(),new TestCommand(),new GenerateCommand(),new FindRoute()
];
$this->add($commands)->add(commands());
diff --git a/eywa/Console/Database/CleanDatabase.php b/eywa/Console/Database/CleanDatabase.php
index d440fa0..a9b4f68 100644..100755
--- a/eywa/Console/Database/CleanDatabase.php
+++ b/eywa/Console/Database/CleanDatabase.php
@@ -17,7 +17,7 @@ namespace Eywa\Console\Database {
{
protected static $defaultName = 'db:clean';
- protected function configure()
+ protected function configure():void
{
$this->setDescription("Truncate all tables")->addArgument('env',InputArgument::REQUIRED,'The base environment');
}
@@ -30,14 +30,12 @@ namespace Eywa\Console\Database {
*/
public function execute(InputInterface $input, OutputInterface $output)
{
- $env = $input->getArgument('env');
+ $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);
-
-
if((new Base($env))->clean())
{
$io->success('All tables are now empty');
diff --git a/eywa/Console/Database/DropTable.php b/eywa/Console/Database/DropTable.php
index 0ddd014..832546e 100644..100755
--- a/eywa/Console/Database/DropTable.php
+++ b/eywa/Console/Database/DropTable.php
@@ -15,7 +15,7 @@
protected static $defaultName = 'table:drop';
- protected function configure()
+ protected function configure():void
{
$this->setDescription("Drop a table")->addArgument('table',InputArgument::REQUIRED,'The table name')->addArgument('env',InputArgument::REQUIRED,'The base environment');
@@ -23,13 +23,13 @@
public function execute(InputInterface $input, OutputInterface $output)
{
- $env = $input->getArgument('env');
+ $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 = $input->getArgument('table');
+ $x = strval($input->getArgument('table'));
if (equal($env, 'dev'))
{
@@ -37,69 +37,74 @@
if (not_def($table->show()))
{
- $io->error("No tables found");
+ $io->error('No tables has been found');
return 1;
}
if (is_false($table->exist($x)))
{
- $io->error("The $x table not exist");
+ $io->error(sprintf('The %s table not exist',$x));
return 1;
}
if ($table->from($x)->drop())
{
- $io->success("The $x table was removed successfully");
+ $io->success(sprintf('The %s table has been removed successfully',$x));
return 0;
}else{
- $io->error("Failed to remove the $x table");
+ $io->error(sprintf('Failed to remove the %s table',$x));
return 1;
}
}
- if (equal($env, 'prod'))
+
+ if (equal($env, 'prod'))
{
+
+
$table = new Table(production());
if (not_def($table->show()))
{
- $io->error("No tables found");
+ $io->error('No tables has been found');
return 1;
}
if (is_false($table->exist($x)))
{
- $io->error("The $x table not exist");
+ $io->error(sprintf('The %s table not exist',$x));
return 1;
}
if ($table->from($x)->drop())
{
- $io->success("The $x table was removed successfully");
+ $io->success(sprintf('The %s table has been removed successfully',$x));
return 0;
}else{
- $io->error("Failed to remove the $x table");
+ $io->error(sprintf('Failed to remove the %s table',$x));
return 1;
}
}
+
if (equal($env, 'any'))
{
+
$table = new Table(development());
if (not_def($table->show()))
{
- $io->error("No tables found");
+ $io->error('No tables has been found');
return 1;
}
if (is_false($table->exist($x)))
{
- $io->error("The $x table not exist");
+ $io->error(sprintf('The %s table not exist',$x));
return 1;
}
if ($table->from($x)->drop())
{
- $io->success("The $x table was removed successfully");
- return 0;
- }else{
- $io->error("Failed to remove the $x table");
+ $io->success(sprintf('The %s table has been removed successfully',$x));
+ }else
+ {
+ $io->error(sprintf('Failed to remove the %s table',$x));
return 1;
}
@@ -107,26 +112,26 @@
if (not_def($table->show()))
{
- $io->error("No tables found");
+ $io->error('No tables has been found');
return 1;
}
if (is_false($table->exist($x)))
{
- $io->error("The $x table not exist");
+ $io->error(sprintf('The %s table not exist',$x));
return 1;
}
if ($table->from($x)->drop())
{
- $io->success("The $x table was removed successfully");
- return 0;
+ $io->success(sprintf('The %s table has been removed successfully',$x));
}else{
- $io->error("Failed to remove the $x table");
+ $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 not valid");
+ $io->error("Environment is not valid");
return 1;
}
diff --git a/eywa/Console/Database/ExportDatabase.php b/eywa/Console/Database/ExportDatabase.php
index 68afa06..617373a 100644..100755
--- a/eywa/Console/Database/ExportDatabase.php
+++ b/eywa/Console/Database/ExportDatabase.php
@@ -20,7 +20,7 @@ namespace Eywa\Console\Database {
* @throws Kedavra
* @throws Exception
*/
- protected function configure()
+ protected function configure():void
{
$base = app()->connexion()->base();
$this->setDescription("Export the $base base content into a sql file");
diff --git a/eywa/Console/Database/Grant.php b/eywa/Console/Database/Grant.php
index 5e04e91..5e04e91 100644..100755
--- a/eywa/Console/Database/Grant.php
+++ b/eywa/Console/Database/Grant.php
diff --git a/eywa/Console/Database/ImportDatabase.php b/eywa/Console/Database/ImportDatabase.php
index 7ebff9c..044d191 100644..100755
--- a/eywa/Console/Database/ImportDatabase.php
+++ b/eywa/Console/Database/ImportDatabase.php
@@ -20,7 +20,7 @@ namespace Eywa\Console\Database {
* @throws Kedavra
* @throws Exception
*/
- protected function configure()
+ protected function configure():void
{
$base = app()->connexion()->base();
$this->setDescription("Import sql file content into the $base database");
diff --git a/eywa/Console/Database/InstallDatabase.php b/eywa/Console/Database/InstallDatabase.php
index 55d5400..0f8cdc5 100644..100755
--- a/eywa/Console/Database/InstallDatabase.php
+++ b/eywa/Console/Database/InstallDatabase.php
@@ -32,7 +32,7 @@ namespace Eywa\Console\Database {
*/
private string $pgsql_pass;
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Create all databases and users rights');
}
@@ -89,7 +89,7 @@ namespace Eywa\Console\Database {
$prod = connect(MYSQL,'','root',$this->pass);
- if ($dev->create_database(env('DEVELOP_DB_NAME')))
+ if ($dev->create_database(strval(strval(env('DEVELOP_DB_NAME')))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -97,7 +97,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->create_database(env('DB_NAME')))
+ if ($prod->create_database(strval(strval(env('DB_NAME')))))
{
$io->success($prod_base_created_successfully);
@@ -111,7 +111,7 @@ namespace Eywa\Console\Database {
$prod = connect(MYSQL,'','root',$this->pass);
- if ($prod->create_user(env('DB_USERNAME'), env('DB_PASSWORD'), env('DB_NAME')))
+ if ($prod->create_user(strval(strval(env('DB_USERNAME'))), strval(strval(env('DB_PASSWORD'))), strval(strval(env('DB_NAME')))))
{
$io->success($prod_user_created_successfully);
@@ -120,7 +120,7 @@ namespace Eywa\Console\Database {
$io->error($prod_user_created_fail);
return 1;
}
- if ($dev->create_user(env('DEVELOP_DB_USERNAME'), env('DEVELOP_DB_PASSWORD'), env('DEVELOP_DB_NAME')))
+ if ($dev->create_user(strval(strval(env('DEVELOP_DB_USERNAME'))), strval(strval(env('DEVELOP_DB_PASSWORD'))), strval(strval(env('DEVELOP_DB_NAME')))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -149,7 +149,7 @@ namespace Eywa\Console\Database {
$dev = connect(MYSQL, '', 'root', $this->mysql_pass);
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($dev->create_database(env('DEVELOP_DB_NAME')))
+ if ($dev->create_database(strval(strval(env('DEVELOP_DB_NAME')))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -157,7 +157,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->create_database(env('DB_NAME')))
+ if ($prod->create_database(strval(strval(env('DB_NAME')))))
{
$io->success($prod_base_created_successfully);
} else {
@@ -168,7 +168,7 @@ namespace Eywa\Console\Database {
$dev = connect(MYSQL, '', 'root', $this->mysql_pass);
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($dev->create_user(env('DEVELOP_DB_USERNAME'), env('DEVELOP_DB_PASSWORD'), env('DEVELOP_DB_NAME')))
+ if ($dev->create_user(strval(strval(env('DEVELOP_DB_USERNAME'))), strval(strval(env('DEVELOP_DB_PASSWORD'))), strval(strval(env('DEVELOP_DB_NAME')))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -179,7 +179,7 @@ namespace Eywa\Console\Database {
- if ($prod->create_user(env('DB_USERNAME'), env('DB_PASSWORD'), env('DB_NAME')))
+ if ($prod->create_user(strval(strval(env('DB_USERNAME'))), strval(strval(env('DB_PASSWORD'))),strval(strval(env('DB_NAME')))))
{
$io->success($prod_user_created_successfully);
} else {
@@ -209,7 +209,7 @@ namespace Eywa\Console\Database {
$dev = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
- if ($dev->create_database(env('DEVELOP_DB_NAME')))
+ if ($dev->create_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -217,7 +217,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->create_database(env('DB_NAME')))
+ if ($prod->create_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
} else {
@@ -227,7 +227,7 @@ namespace Eywa\Console\Database {
$dev = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
- if ($prod->create_user(env('DB_USERNAME'), env('DB_PASSWORD'), env('DB_NAME')))
+ if ($prod->create_user(strval(env('DB_USERNAME')), strval(env('DB_PASSWORD')), strval(env('DB_NAME'))))
{
$io->success($prod_user_created_successfully);
} else {
@@ -235,7 +235,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($dev->create_user(env('DEVELOP_DB_USERNAME'), env('DEVELOP_DB_PASSWORD'), env('DEVELOP_DB_NAME')))
+ if ($dev->create_user(strval(env('DEVELOP_DB_USERNAME')), strval(env('DEVELOP_DB_PASSWORD')), strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -260,7 +260,7 @@ namespace Eywa\Console\Database {
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($dev->create_database(env('DEVELOP_DB_NAME')))
+ if ($dev->create_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -268,7 +268,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->create_database(env('DB_NAME')))
+ if ($prod->create_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
} else {
@@ -280,7 +280,7 @@ namespace Eywa\Console\Database {
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($prod->create_user(env('DB_USERNAME'), env('DB_PASSWORD'), env('DB_NAME')))
+ if ($prod->create_user(strval(env('DB_USERNAME')), strval(env('DB_PASSWORD')), strval(env('DB_NAME'))))
{
$io->success($prod_user_created_successfully);
} else {
@@ -289,7 +289,7 @@ namespace Eywa\Console\Database {
}
- if ($dev->create_user(env('DEVELOP_DB_USERNAME'), env('DEVELOP_DB_PASSWORD'), env('DEVELOP_DB_NAME')))
+ if ($dev->create_user(strval(env('DEVELOP_DB_USERNAME')), strval(env('DEVELOP_DB_PASSWORD')), strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -313,7 +313,7 @@ namespace Eywa\Console\Database {
- $dev = connect(SQLITE, env('DEVELOP_DB_NAME'));
+ $dev = connect(SQLITE, strval(env('DEVELOP_DB_NAME')));
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
@@ -324,7 +324,7 @@ namespace Eywa\Console\Database {
$io->error($dev_base_created_fail);
}
- if ($prod->create_database(env('DB_NAME')))
+ if ($prod->create_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
}else{
@@ -332,7 +332,7 @@ namespace Eywa\Console\Database {
}
$prod = connect(MYSQL, '', 'root', $this->pass);
- if ($prod->create_user(env('DB_USERNAME'),env('DB_PASSWORD'),env('DB_NAME')))
+ if ($prod->create_user(strval(env('DB_USERNAME')),strval(env('DB_PASSWORD')),strval(env('DB_NAME'))))
{
$io->success($prod_user_created_successfully);
}else{
@@ -351,7 +351,7 @@ namespace Eywa\Console\Database {
$dev = connect(MYSQL,'','root',$this->mysql_pass);
- $prod = connect(SQLITE, env('DB_NAME'));
+ $prod = connect(SQLITE, strval(env('DB_NAME')));
if ($prod->connected())
{
@@ -360,14 +360,14 @@ namespace Eywa\Console\Database {
$io->error($prod_base_created_fail);
}
- if ($dev->create_database(env('DEVELOP_DB_NAME')))
+ if ($dev->create_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
$io->error($dev_base_created_fail);
}
$dev = connect(MYSQL,'','root',$this->pass);
- if ($dev->create_user(env('DEVELOP_DB_USERNAME'),env('DEVELOP_DB_PASSWORD'),env('DEVELOP_DB_NAME')))
+ if ($dev->create_user(strval(env('DEVELOP_DB_USERNAME')),strval(env('DEVELOP_DB_PASSWORD')),strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_user_created_successfully);
}else{
@@ -388,7 +388,7 @@ namespace Eywa\Console\Database {
$prod = connect(POSTGRESQL,'','postgres',$this->pgsql_pass,5432);
- $dev = connect(SQLITE, env('DEVELOP_DB_NAME'));
+ $dev = connect(SQLITE, strval(env('DEVELOP_DB_NAME')));
if ($dev->connected())
{
@@ -397,14 +397,14 @@ namespace Eywa\Console\Database {
$io->error($dev_base_created_fail);
}
- if ($prod->create_database(env('DB_NAME')))
+ if ($prod->create_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
}else{
$io->error($prod_base_created_fail);
}
$prod = connect(POSTGRESQL,'','postgres',$this->pass,5432);
- if ($prod->create_user(env('DB_USERNAME'),env('DB_PASSWORD'),env('DB_NAME')))
+ if ($prod->create_user(strval(env('DB_USERNAME')),strval(env('DB_PASSWORD')),strval(env('DB_NAME'))))
{
$io->success($dev_user_created_successfully);
}else{
@@ -422,7 +422,7 @@ namespace Eywa\Console\Database {
} while (!connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432)->connected());
- $prod = connect(SQLITE,env('DB_NAME'));
+ $prod = connect(SQLITE,strval(env('DB_NAME')));
$dev = connect(POSTGRESQL, '','postgres',$this->pgsql_pass,5432);
if ($prod->connected())
@@ -432,14 +432,14 @@ namespace Eywa\Console\Database {
$io->error($prod_base_created_fail);
}
- if ($dev->create_database(env('DEVELOP_DB_NAME')))
+ if ($dev->create_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
$io->error($dev_base_created_fail);
}
$dev = connect(POSTGRESQL, '','postgres',$this->pass,5432);
- if ($dev->create_user(env('DEVELOP_DB_USERNAME'),env('DEVELOP_DB_PASSWORD'),env('DEVELOP_DB_NAME')))
+ if ($dev->create_user(strval(env('DEVELOP_DB_USERNAME')),strval(env('DEVELOP_DB_PASSWORD')),strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_user_created_successfully);
}else{
@@ -449,8 +449,8 @@ namespace Eywa\Console\Database {
}
if (development()->driver() === SQLITE && production()->driver() === SQLITE)
{
- $prod = connect(SQLITE,env('DB_NAME'));
- $dev = connect(SQLITE,env('DEVELOP_DB_NAME'));
+ $prod = connect(SQLITE,strval(env('DB_NAME')));
+ $dev = connect(SQLITE,strval(env('DEVELOP_DB_NAME')));
if ($prod->connected())
{
diff --git a/eywa/Console/Database/MigrateDatabase.php b/eywa/Console/Database/MigrateDatabase.php
index 7a76cd0..4433efb 100644..100755
--- a/eywa/Console/Database/MigrateDatabase.php
+++ b/eywa/Console/Database/MigrateDatabase.php
@@ -14,7 +14,7 @@ namespace Eywa\Console\Database {
{
protected static $defaultName = 'db:migrate';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Run the migrations')
->setHelp('php shaolin db:migrate env');
diff --git a/eywa/Console/Database/RollbackDatabase.php b/eywa/Console/Database/RollbackDatabase.php
index 632a204..3771953 100644..100755
--- a/eywa/Console/Database/RollbackDatabase.php
+++ b/eywa/Console/Database/RollbackDatabase.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Database {
{
protected static $defaultName = 'db:rollback';
- protected function configure()
+ 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 91cbef1..a13bf95 100644..100755
--- a/eywa/Console/Database/SeedDatabase.php
+++ b/eywa/Console/Database/SeedDatabase.php
@@ -14,7 +14,7 @@
protected static $defaultName = 'db:seed';
- protected function configure()
+ protected function configure():void
{
$this->setDescription("Seed the development database");
}
@@ -26,9 +26,12 @@
if (Seeding::run($input,$output))
{
$io->success("The database has been seeded");
+ return 0;
}
+ $io->error('The database seeder has been failed');
+ return 1;
+
- return 0;
}
}
diff --git a/eywa/Console/Database/ShowTable.php b/eywa/Console/Database/ShowTable.php
index a433bac..bc5830a 100644..100755
--- a/eywa/Console/Database/ShowTable.php
+++ b/eywa/Console/Database/ShowTable.php
@@ -15,12 +15,13 @@
{
protected static $defaultName = 'table:list';
+
/**
- * @var array
+ * @var array<string>
*/
- private array $tables;
+ private array $tables = [];
- protected function configure()
+ protected function configure(): void
{
$this->setDescription("List all tables found in the base")->addArgument('env',InputArgument::REQUIRED,'The base environment');
}
@@ -31,7 +32,7 @@
$table = new \Symfony\Component\Console\Helper\Table($output);
- $env = $input->getArgument('env');
+ $env = strval($input->getArgument('env'));
not_in(['dev','prod'],$env,true,'The env must be dev or prod');
diff --git a/eywa/Console/Database/ShowUsers.php b/eywa/Console/Database/ShowUsers.php
index b1aa458..e298aad 100644..100755
--- a/eywa/Console/Database/ShowUsers.php
+++ b/eywa/Console/Database/ShowUsers.php
@@ -16,7 +16,7 @@
protected static $defaultName = 'users:show';
- protected function configure()
+ protected function configure():void
{
$this->setDescription("List all users found in the base")->addArgument('env',InputArgument::REQUIRED,'The base environment');
}
@@ -31,7 +31,7 @@
{
$io = new SymfonyStyle($input,$output);
- $env = $input->getArgument('env');
+ $env = strval($input->getArgument('env'));
not_in(['dev','prod'],$env,true,'The env must be dev or prod');
diff --git a/eywa/Console/Database/TruncateTable.php b/eywa/Console/Database/TruncateTable.php
index 156daed..9f4277a 100644..100755
--- a/eywa/Console/Database/TruncateTable.php
+++ b/eywa/Console/Database/TruncateTable.php
@@ -16,7 +16,7 @@
protected static $defaultName = 'table:clear';
- protected function configure()
+ protected function configure():void
{
$this->setDescription("Truncate a table")->addArgument('table',InputArgument::REQUIRED,'The table name')->addArgument('env',InputArgument::REQUIRED,'The base environment');
}
@@ -25,8 +25,8 @@
{
$io = new SymfonyStyle($input,$output);
- $env = $input->getArgument('env');
- $table = $input->getArgument('table');
+ $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'))
diff --git a/eywa/Console/Database/UninstallDatabase.php b/eywa/Console/Database/UninstallDatabase.php
index 3808559..ff2df72 100644..100755
--- a/eywa/Console/Database/UninstallDatabase.php
+++ b/eywa/Console/Database/UninstallDatabase.php
@@ -14,23 +14,29 @@ namespace Eywa\Console\Database {
class UninstallDatabase extends Command
{
protected static $defaultName = 'db:uninstall';
+
/**
*
* The root password
*
*/
- private string $pass;
+ private string $pass = '';
/**
- * @var string
+ *
+ * The mysql root password
+ *
*/
- private string $mysql_pass;
+ private string $mysql_pass = '';
+
/**
- * @var string
+ *
+ * The pgsql postgres password
+ *
*/
- private string $pgsql_pass;
+ private string $pgsql_pass = '';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Reverse the install command');
}
@@ -40,8 +46,10 @@ namespace Eywa\Console\Database {
* @param InputInterface $input
* @param OutputInterface $output
* @return int
+ *
* @throws Kedavra
* @throws Exception
+ *
*/
public function execute(InputInterface $input, OutputInterface $output)
{
@@ -84,7 +92,7 @@ namespace Eywa\Console\Database {
$prod = connect(MYSQL,'','root',$this->pass);
- if ($dev->remove_database(env('DEVELOP_DB_NAME')))
+ if ($dev->remove_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -92,7 +100,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->remove_database(env('DB_NAME')))
+ if ($prod->remove_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
@@ -106,7 +114,7 @@ namespace Eywa\Console\Database {
$prod = connect(MYSQL,'','root',$this->pass);
- if ($prod->remove_user(env('DB_USERNAME')))
+ if ($prod->remove_user(strval(env('DB_USERNAME'))))
{
$io->success($prod_user_created_successfully);
@@ -115,7 +123,7 @@ namespace Eywa\Console\Database {
$io->error($prod_user_created_fail);
return 1;
}
- if ($dev->remove_user(env('DEVELOP_DB_USERNAME')))
+ if ($dev->remove_user(strval(env('DEVELOP_DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -144,7 +152,7 @@ namespace Eywa\Console\Database {
$dev = connect(MYSQL, '', 'root', $this->mysql_pass);
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($dev->remove_database(env('DEVELOP_DB_NAME')))
+ if ($dev->remove_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -152,7 +160,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->remove_database(env('DB_NAME')))
+ if ($prod->remove_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
} else {
@@ -163,7 +171,7 @@ namespace Eywa\Console\Database {
$dev = connect(MYSQL, '', 'root', $this->mysql_pass);
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($dev->remove_user(env('DEVELOP_DB_USERNAME')))
+ if ($dev->remove_user(strval(env('DEVELOP_DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -174,7 +182,7 @@ namespace Eywa\Console\Database {
- if ($prod->remove_user(env('DB_USERNAME')))
+ if ($prod->remove_user(strval(env('DB_USERNAME'))))
{
$io->success($prod_user_created_successfully);
} else {
@@ -205,7 +213,7 @@ namespace Eywa\Console\Database {
$dev = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
- if ($dev->remove_database(env('DEVELOP_DB_NAME')))
+ if ($dev->remove_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -213,7 +221,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->remove_database(env('DB_NAME')))
+ if ($prod->remove_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
} else {
@@ -223,7 +231,7 @@ namespace Eywa\Console\Database {
$dev = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
- if ($prod->remove_user(env('DB_USERNAME')))
+ if ($prod->remove_user(strval(env('DB_USERNAME'))))
{
$io->success($prod_user_created_successfully);
} else {
@@ -231,7 +239,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($dev->remove_user(env('DEVELOP_DB_USERNAME')))
+ if ($dev->remove_user(strval(env('DEVELOP_DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -255,7 +263,7 @@ namespace Eywa\Console\Database {
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($dev->remove_database(env('DEVELOP_DB_NAME')))
+ if ($dev->remove_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
} else {
@@ -263,7 +271,7 @@ namespace Eywa\Console\Database {
return 1;
}
- if ($prod->remove_database(env('DB_NAME')))
+ if ($prod->remove_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
} else {
@@ -275,7 +283,7 @@ namespace Eywa\Console\Database {
$prod = connect(POSTGRESQL, '', 'postgres', $this->pgsql_pass,5432);
- if ($prod->remove_user(env('DB_USERNAME')))
+ if ($prod->remove_user(strval(env('DB_USERNAME'))))
{
$io->success($prod_user_created_successfully);
} else {
@@ -284,7 +292,7 @@ namespace Eywa\Console\Database {
}
- if ($dev->remove_user(env('DEVELOP_DB_USERNAME')))
+ if ($dev->remove_user(strval(env('DEVELOP_DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
} else {
@@ -311,14 +319,14 @@ namespace Eywa\Console\Database {
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
- if (unlink(env('DEVELOP_DB_NAME')))
+ if (unlink(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
$io->error($dev_base_created_fail);
}
- if ($prod->remove_database(env('DB_NAME')))
+ if ($prod->remove_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
}else{
@@ -326,7 +334,7 @@ namespace Eywa\Console\Database {
}
$prod = connect(MYSQL, '', 'root', $this->mysql_pass);
- if ($prod->remove_user(env('DB_USERNAME')))
+ if ($prod->remove_user(strval(env('DB_USERNAME'))))
{
$io->success($prod_user_created_successfully);
}else{
@@ -348,21 +356,21 @@ namespace Eywa\Console\Database {
- if (unlink(env('DB_NAME')))
+ if (unlink(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
}else{
$io->error($prod_base_created_fail);
}
- if ($dev->remove_database(env('DEVELOP_DB_NAME')))
+ if ($dev->remove_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
$io->error($dev_base_created_fail);
}
$dev = connect(MYSQL,'','root',$this->mysql_pass);
- if ($dev->remove_user(env('DEVELOP_DB_USERNAME')))
+ if ($dev->remove_user(strval(env('DEVELOP_DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
}else{
@@ -386,21 +394,21 @@ namespace Eywa\Console\Database {
- if (unlink(env('DEVELOP_DB_NAME')))
+ if (unlink(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
$io->error($dev_base_created_fail);
}
- if ($prod->remove_database(env('DB_NAME')))
+ if ($prod->remove_database(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
}else{
$io->error($prod_base_created_fail);
}
$prod = connect(POSTGRESQL,'','postgres',$this->pgsql_pass,5432);
- if ($prod->remove_user(env('DB_USERNAME')))
+ if ($prod->remove_user(strval(env('DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
}else{
@@ -420,21 +428,21 @@ namespace Eywa\Console\Database {
$dev = connect(POSTGRESQL, '','postgres',$this->pgsql_pass,5432);
- if (unlink(env('DB_NAME')))
+ if (unlink(strval(env('DB_NAME'))))
{
$io->success($prod_base_created_successfully);
}else{
$io->error($prod_base_created_fail);
}
- if ($dev->remove_database(env('DEVELOP_DB_NAME')))
+ if ($dev->remove_database(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
$io->error($dev_base_created_fail);
}
$dev = connect(POSTGRESQL, '','postgres',$this->pgsql_pass,5432);
- if ($dev->remove_user(env('DEVELOP_DB_USERNAME')))
+ if ($dev->remove_user(strval(env('DEVELOP_DB_USERNAME'))))
{
$io->success($dev_user_created_successfully);
}else{
@@ -447,13 +455,13 @@ namespace Eywa\Console\Database {
- if (unlink((env('DB_NAME'))))
+ if (unlink((strval(env('DB_NAME')))))
{
$io->success($prod_base_created_successfully);
}else{
$io->error($prod_base_created_fail);
}
- if (unlink(env('DEVELOP_DB_NAME')))
+ if (unlink(strval(env('DEVELOP_DB_NAME'))))
{
$io->success($dev_base_created_successfully);
}else{
diff --git a/eywa/Console/Generate/GenerateCommand.php b/eywa/Console/Generate/GenerateCommand.php
index 625eaee..1478955 100644..100755
--- a/eywa/Console/Generate/GenerateCommand.php
+++ b/eywa/Console/Generate/GenerateCommand.php
@@ -8,46 +8,94 @@ namespace Eywa\Console\Generate {
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 GenerateCommand extends Command
{
- protected static $defaultName = "make:command";
+ protected static $defaultName = 'make:console';
- protected function configure()
+ protected function configure():void
{
- $this->setDescription('Generate a command')->addArgument('cmd', InputArgument::REQUIRED, 'the command name');
+ $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.');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|void|null
+ * @return int|null
* @throws Kedavra
*/
public function execute(InputInterface $input, OutputInterface $output)
{
+ $io = new SymfonyStyle($input,$output);
- $command = ucfirst(strtolower(str_replace('Command', '', $input->getArgument('cmd')))) . 'Command';
+ $x = strval($input->getArgument('console'));
+ if(preg_match("#^[a-z]([a-z_]+)$#",$x) !== 1)
+ {
+ $io->error('You must use snake case syntax to generate the console');
+ return 1;
+ }
- $file = base('app') . DIRECTORY_SEPARATOR . 'Console' . DIRECTORY_SEPARATOR . $command . '.php';
+ $io->title('Generation of the console');
- if (!file_exists($file))
- {
- if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\n\t\tnamespace App\Console;\n\n\t\tuse Symfony\Component\Console\Command\Command;\n\t\tuse Symfony\Component\Console\Input\InputInterface;\n\t\tuse Symfony\Component\Console\Output\OutputInterface;\n\n\t\tclass {$command} extends Command\n\t\t{\n\n\t\t\tprotected static \$defaultName = '';\n\n\t\t\tprotected function configure()\n\t\t\t{\n\t\t\t\t\$this->setDescription('');\n\t\t\t}\n\n\t\t\tpublic function interact(InputInterface \$input, OutputInterface \$output)\n\t\t\t{\n\n\n\t\t\t}\n\n\t\t\tpublic function execute(InputInterface \$input, OutputInterface \$output)\n\t\t\t{\n\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t}\n")->flush())
- $output->writeln('<info>The command has been generated successfully</info>');
- return 0;
- }
- else
+ $console = collect(explode('_',$x))->for('ucfirst')->join('');
+
+ $namespace = 'App\Console';
+
+ $file = base( 'app' , 'Console' , "$console.php");
+
+ if (file_exists($file))
{
- $output->writeln('<bg=red;fg=white>The view already exist </>');
+ $io->error(sprintf('The %s console already exist',$console));
return 1;
}
+ 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;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+class $console extends Command
+{
+ protected static \$defaultName = '';
+
+ protected function configure(): void
+ {
+
+ \$this->setDescription('');
+
+ }
+ public function execute(InputInterface \$input, OutputInterface \$output): int
+ {
+ \$io = new SymfonyStyle(\$input,\$output);
+
+
+ return 0;
+ }
+
+}")->flush()) {
+ $io->success(sprintf('The %s console has been created successfully',$console));
+
+ return 0;
+ }
+ $io->error(sprintf('The %s console creation has failede',$console));
+ return 1;
}
}
diff --git a/eywa/Console/Generate/GenerateController.php b/eywa/Console/Generate/GenerateController.php
index 1a78a38..21aae3c 100644..100755
--- a/eywa/Console/Generate/GenerateController.php
+++ b/eywa/Console/Generate/GenerateController.php
@@ -16,7 +16,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:controller';
- protected function configure()
+ protected function configure():void
{
$this
@@ -38,9 +38,9 @@ namespace Eywa\Console\Generate {
{
$io = new SymfonyStyle($input,$output);
- $controller = $input->getArgument('controller');
- $layout = $input->getArgument('layout');
- $directory = ucfirst($input->getArgument('directory'));
+ $controller = strval($input->getArgument('controller'));
+ $layout = strval($input->getArgument('layout'));
+ $directory = ucfirst(strval($input->getArgument('directory')));
if(preg_match("#^[a-z]([a-z_]+)$#",$controller) !== 1)
{
@@ -58,7 +58,7 @@ namespace Eywa\Console\Generate {
if (file_exists($controller_file))
{
- $io->error("The $controller_class controller already exist");
+ $io->error(sprintf('The %s controller already exist',$controller_class));
return 1;
}
@@ -84,118 +84,7 @@ namespace $namespace {
$directory
-
- /**
- * @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)
- {
- // TODO: Implement before_action() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_action(Request \$request)
- {
- // 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)
- {
- // TODO: Implement before_destroy() method.
- }
-
- /**
- * @inheritDoc
- */
- public function after_destroy(Request \$request)
- {
- // TODO: Implement after_destroy() method.
- }
+
}
}")->flush()) {
diff --git a/eywa/Console/Generate/GenerateCrud.php b/eywa/Console/Generate/GenerateCrud.php
deleted file mode 100644
index 4817a49..0000000
--- a/eywa/Console/Generate/GenerateCrud.php
+++ /dev/null
@@ -1,206 +0,0 @@
-<?php
-
-namespace Eywa\Console\Generate {
-
-
- use Eywa\Exception\Kedavra;
- use Eywa\File\File;
- 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 GenerateCrud extends Command
- {
-
- protected static $defaultName = 'make:crud';
-
- protected function configure()
- {
-
- $this
-
- ->setDescription('Create a new crud')
- ->addArgument('controller', InputArgument::REQUIRED, 'The controller name')
- ->addArgument('model', InputArgument::REQUIRED, 'The model name')
- ->addArgument('table', InputArgument::REQUIRED, 'The table name');
- }
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return int|null
- * @throws Kedavra
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input,$output);
-
-
- $controller = $input->getArgument('controller');
- $model = $input->getArgument('model');
- $table = $input->getArgument('table');
-
- if(preg_match("#^[a-z]([a-z_]+)$#",$controller) !== 1)
- {
- $io->error('You must use snake case syntax to generate the controller');
- return 1;
- }
-
- if(preg_match("#^[a-z]([a-z_]+)$#",$model) !== 1)
- {
- $io->error('You must use snake case syntax to generate the model');
- return 1;
- }
-
- $model_class = collect(explode('_',$model))->for('ucfirst')->join('');
-
- $controller_class = collect(explode('_',$controller))->for('ucfirst')->join('');
-
-
- $model_file = base('app','Models',"$model_class.php");
- $controller_file = base('app','Controllers',"$controller_class.php");
-
-
- if (file_exists($controller_file))
- {
- $io->error('The controller already exist');
- return 1;
- }
-
- if (file_exists($model_file))
- {
- $io->error('The model already exist');
- return 1;
- }
-
- $io->title('Generation of the model');
-
-
- $namespace = 'App\Models';
-
- if ((new File($model_file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\nnamespace $namespace\n{ \n\n\tuse Eywa\Database\Model\Model;\n\n\tClass $model_class 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->success("The $model model has been generated successfully");
-
- }else{
- $io->error('Generation of the model has failed');
- return 1;
- }
-
-
- $io->title('Generation of the controller');
-
- $namespace = 'App' . '\\' . 'Controllers';
-
-
- if (file_exists($controller_file))
- {
- $io->error("The $controller_class controller already exist");
-
- return 1;
- }
-
- if ((new File("$controller_file", EMPTY_AND_WRITE_FILE_MODE))->write("<?php
-
-namespace $namespace {
-
- use Eywa\Http\Controller\Controller;
- use Eywa\Http\Response\Response;
- use Eywa\Exception\Kedavra;
- use Eywa\Http\Request\Request;
- use Eywa\Html\Form\Form;
-
- Class $controller_class extends Controller
- {
-
- protected static string \$layout = 'admin';
-
- protected static string \$directory = 'Crud';
-
- /**
- *
- * @param Request \$request
- *
- * @return Response
- *
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- *
- */
- public function show(Request \$request): Response
- {
- \$records = $model_class::paginate([\$this,'display-$table'],\$request->args()->get('page'));
- return \$this->view('show', 'show', 'show', compact('records'));
- }
-
- /**
- *
- * @param Request \$request
- *
- * @return Response
- *
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- *
- */
- public function edit(Request \$request): Response
- {
- \$id = \$request->args()->get('id');
- \$form = \$this->form(route(edit-$table,compact('id')))->edit(\$id);
- return \$this->view('edit', 'edit', 'edit', compact('form'));
- }
-
- /**
- *
- * @param Request \$request
- *
- * @return Response
- *
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- *
- */
- public function update(Request \$request): Response
- {
- if($model_class::update(intval(\$request->request()->get('id')),\$request->request()->all())
- \$this->flash(SUCCESS,'The record has been updated successfully');
- else
- \$this->flash(FAILURE,'The record has not been udated',false);
-
- return \$this->back();
- }
-
- public function destroy(Request \$request): Response
- {
- \$id = intval(\$request->args()->get('id'));
-
- if($model_class::destroy(\$id))
- \$this->flash(SUCCESS,'The record has been deleted successfully');
- else
- \$this->flash(FAILURE,'The record has not been deleted',false);
-
- return \$this->back();
- }
-
- }
-
-}
-")->flush()) {
- $io->success("The $controller_class controller has been generated successfully");
- }else{
- $io->error("The $controller_class controller has not been generated");
-
- return 1;
- }
-
- }
-
-
-
- }
-} \ No newline at end of file
diff --git a/eywa/Console/Generate/GenerateMiddleware.php b/eywa/Console/Generate/GenerateMiddleware.php
index b3c34fb..1e2e2fc 100644..100755
--- a/eywa/Console/Generate/GenerateMiddleware.php
+++ b/eywa/Console/Generate/GenerateMiddleware.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:middleware';
- protected function configure()
+ protected function configure():void
{
$this
@@ -35,11 +35,9 @@ namespace Eywa\Console\Generate {
*/
public function execute(InputInterface $input, OutputInterface $output)
{
-
-
$io = new SymfonyStyle($input,$output);
- $middleware = $input->getArgument('middleware');
+ $middleware = strval($input->getArgument('middleware'));
if(preg_match("#^[a-z]([a-z_]+)$#",$middleware) !== 1)
{
@@ -53,7 +51,7 @@ namespace Eywa\Console\Generate {
if (file_exists($file))
{
- $io->error('The middleware already exist');
+ $io->error(sprintf('The %s middleware already exist',$class));
return 1;
}
@@ -72,13 +70,13 @@ namespace App\Middleware {
/**
* @inheritDoc
*/
- public function check(ServerRequest \$request): Response
+ public function check(ServerRequest \$request): void
{
// TODO: Implement check() method.
}
}
}")->flush()) {
- $io->success('The middleware was generated successfully');
+ $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 db857b8..81943b8 100644..100755
--- a/eywa/Console/Generate/GenerateMigration.php
+++ b/eywa/Console/Generate/GenerateMigration.php
@@ -16,7 +16,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:migration';
- protected function configure()
+ protected function configure():void
{
$this
@@ -37,7 +37,7 @@ namespace Eywa\Console\Generate {
{
$io = new SymfonyStyle($input,$output);
- $migration = $input->getArgument('migration');
+ $migration = strval($input->getArgument('migration'));
if(preg_match("#^[a-z]([a-z_]+)$#",$migration) !== 1)
{
@@ -51,11 +51,11 @@ namespace Eywa\Console\Generate {
if (file_exists($file))
{
- $io->error('The migration already exist');
+ $io->error(sprintf('The %s migration already exist',$class));
return 1;
}
$io->title('Generation of the migration');
- $table = $input->getArgument('table');
+ $table = strval($input->getArgument('table'));
$time = date('Y-m-d-H-i-s');
@@ -97,7 +97,7 @@ namespace Base\Migrations {
}
}")->flush())
{
- $io->success('The migration was successfully generated');
+ $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 9ed2930..99db3b5 100644..100755
--- a/eywa/Console/Generate/GenerateModel.php
+++ b/eywa/Console/Generate/GenerateModel.php
@@ -15,7 +15,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:model';
- protected function configure()
+ protected function configure():void
{
$this
@@ -37,7 +37,7 @@ namespace Eywa\Console\Generate {
{
$io = new SymfonyStyle($input,$output);
- $x = $input->getArgument('model');
+ $x = strval($input->getArgument('model'));
if(preg_match("#^[a-z]([a-z_]+)$#",$x) !== 1)
{
@@ -47,7 +47,7 @@ namespace Eywa\Console\Generate {
$io->title('Generation of the model');
- $table = $input->getArgument('table');
+ $table = strval($input->getArgument('table'));
$model = collect(explode('_',$x))->for('ucfirst')->join('');
@@ -62,11 +62,11 @@ namespace Eywa\Console\Generate {
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->success("The $model model has been generated successfully");
+ $io->success(sprintf('The %s model has been generated successfully',$model));
return 0;
}
- $io->error("The $model generation has failed");
+ $io->error(sprintf('The %s model generation has failed',$model));
return 1;
}
diff --git a/eywa/Console/Generate/GenerateRouteBase.php b/eywa/Console/Generate/GenerateRouteBase.php
deleted file mode 100644
index 3a1d059..0000000
--- a/eywa/Console/Generate/GenerateRouteBase.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
- namespace Eywa\Console\Generate {
-
-
- use DI\DependencyException;
- use DI\NotFoundException;
- use Eywa\Exception\Kedavra;
- use Eywa\Http\Routing\Admin;
- use Eywa\Http\Routing\Task;
- use Eywa\Http\Routing\Web;
- 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 GenerateRouteBase extends Command
- {
-
- protected static $defaultName = 'route:configure';
-
- protected function configure()
- {
-
- $this->setDescription('Generate all routes bases');
- }
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return bool|int|null
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- */
- public function execute(InputInterface $input, OutputInterface $output)
- {
- $io = new SymfonyStyle($input,$output);
-
- $io->title('Starting route configuration');
-
- if (!is_dir(base('routes')))
- mkdir(base('routes'));
-
-
- if (file_exists(base('routes','web.sqlite3')))
- {
- $io->error('The configuration wizard has been already executed');
- return 1;
- }
- if (Web::generate())
- {
- $io->success('The configuration has been generated successfully');
- return 0;
- }
-
- $io->error('The base generation failed');
-
- return 1;
-
- }
-
- }
- }
diff --git a/eywa/Console/Generate/GenerateSeeds.php b/eywa/Console/Generate/GenerateSeeds.php
index 31a0aa2..c30e9aa 100644..100755
--- a/eywa/Console/Generate/GenerateSeeds.php
+++ b/eywa/Console/Generate/GenerateSeeds.php
@@ -16,7 +16,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:seed';
- protected function configure()
+ protected function configure():void
{
$this
@@ -37,7 +37,7 @@ namespace Eywa\Console\Generate {
{
$io = new SymfonyStyle($input,$output);
- $seed = $input->getArgument('seed');
+ $seed = strval($input->getArgument('seed'));
if(preg_match("#^[a-z]([a-z_]+)$#",$seed) !== 1)
{
@@ -51,13 +51,13 @@ namespace Eywa\Console\Generate {
if (file_exists($file))
{
- $io->error('The seeder already exist');
+ $io->error(sprintf('The %s seeder already exist',$class));
return 1;
}
$io->title('Generation of the seeder');
- $table = $input->getArgument('table');
+ $table = strval($input->getArgument('table'));
if ((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php
@@ -101,11 +101,11 @@ namespace Base\Seeds {
}
}")->flush())
{
- $io->success('The seeder was successfully generated');
+ $io->success(sprintf('The %s seeder was successfully generated',$class));
return 0;
}
- $io->error('The creation of the seeder has failed');
+ $io->error(sprintf('The %s seeder creation has failed',$class));
return 1;
diff --git a/eywa/Console/Generate/GenerateTest.php b/eywa/Console/Generate/GenerateTest.php
index 876f155..d982fa2 100644..100755
--- a/eywa/Console/Generate/GenerateTest.php
+++ b/eywa/Console/Generate/GenerateTest.php
@@ -16,7 +16,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:test';
- protected function configure()
+ protected function configure():void
{
$this
@@ -37,24 +37,24 @@ namespace Eywa\Console\Generate {
{
$io = new SymfonyStyle($input,$output);
- $migration = $input->getArgument('test');
+ $test = strval($input->getArgument('test'));
- if(preg_match("#^[a-z]([a-z_]+)$#",$migration) !== 1)
+ if(preg_match("#^[a-z]([a-z_]+)$#",$test) !== 1)
{
$io->error('You must use snake case syntax to generate the test');
return 1;
}
- $class = collect(explode('_',$migration))->for('ucfirst')->join('');
+ $class = collect(explode('_',$test))->for('ucfirst')->join('');
- $file = base('tests',ucfirst($input->getArgument('directory')),"$class.php");
+ $file = base('tests',ucfirst(strval($input->getArgument('directory'))),"$class.php");
if (file_exists($file))
{
- $io->error('The tests already exist');
+ $io->error(sprintf('The %s tests already exist',$class));
return 1;
}
- $x= ucfirst($input->getArgument('directory'));
+ $x= ucfirst(strval($input->getArgument('directory')));
if (def($x) && !is_dir(base('tests',$x)))
{
@@ -78,11 +78,11 @@ namespace $namespace {
}
")->flush())
{
- $io->success('The test was successfully generated');
+ $io->success(sprintf('The %s test has been created successfully',$class));
return 0;
}
- $io->error('The creation of the test has failed');
+ $io->error(sprintf('The creation of the %s test has failed',$class));
return 1;
diff --git a/eywa/Console/Generate/GenerateValidator.php b/eywa/Console/Generate/GenerateValidator.php
index b1a04a4..0725120 100644..100755
--- a/eywa/Console/Generate/GenerateValidator.php
+++ b/eywa/Console/Generate/GenerateValidator.php
@@ -16,7 +16,7 @@ namespace Eywa\Console\Generate {
protected static $defaultName = 'make:validator';
- protected function configure()
+ protected function configure():void
{
$this
@@ -38,7 +38,7 @@ namespace Eywa\Console\Generate {
$io = new SymfonyStyle($input,$output);
- $validator = $input->getArgument('validator');
+ $validator = strval($input->getArgument('validator'));
if(preg_match("#^[a-z]([a-z_]+)$#",$validator) !== 1)
{
@@ -49,7 +49,7 @@ namespace Eywa\Console\Generate {
$class = collect(explode('_',$validator))->for('ucfirst')->join('');
- $dir = ucfirst($input->getArgument('directory')) ?? '';
+ $dir = ucfirst(strval($input->getArgument('directory'))) ?? '';
$namespace = def($dir) ? "App\Validators\\$dir" : 'App\Validators';
@@ -59,7 +59,7 @@ namespace Eywa\Console\Generate {
if (file_exists($file))
{
- $io->error('The validator already exist');
+ $io->error(sprintf('The %s validator already exist',$class));
return 1;
}
@@ -75,7 +75,7 @@ namespace Eywa\Console\Generate {
if (file_exists($file))
{
- $io->error("The $class validator already exist");
+ $io->error(sprintf('The %s validator already exist',$class));
return 1;
}
@@ -108,11 +108,11 @@ namespace $namespace {
}
}
")->flush()) {
- $io->success("The validator has been generated successfully");
+ $io->success(sprintf('The %s validator has been generated successfully',$class));
return 0;
}
- $io->error("Generation of the validator has failed");
+ $io->error(sprintf('The %s validator generation has failed',$class));
return 1;
}
diff --git a/eywa/Console/Generate/GenerateView.php b/eywa/Console/Generate/GenerateView.php
index 99bb23e..1e11df3 100644..100755
--- a/eywa/Console/Generate/GenerateView.php
+++ b/eywa/Console/Generate/GenerateView.php
@@ -14,7 +14,7 @@
protected static $defaultName = "make:view";
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Generate a view')->addArgument('view', InputArgument::REQUIRED, 'the view name')->addArgument('dir', InputArgument::OPTIONAL, 'the view dir');
@@ -31,7 +31,7 @@
$io = new SymfonyStyle($input,$output);
$io->title('Generation of the view');
- $dir = $input->getArgument('dir') ?? '';
+ $dir = strval($input->getArgument('dir')) ?? '';
if (def($dir))
{
@@ -41,24 +41,24 @@
}
- $view = collect(explode('.', $input->getArgument('view')))->first();
+ $view = collect(explode('.', strval($input->getArgument('view'))))->first();
append($view, '.php');
$view = def($dir) ? base('app','Views',$dir,$view) : base('app','Views',$view);
if (file_exists($view))
{
- $io->error('The view already exist');
+ $io->error(sprintf('The %s view already exist',$view));
return 1;
}
if (touch($view))
{
- $io->success('The view was generated successfully');
+ $io->success(sprintf('The %s view has been generated successfully',$view));
return 0;
}
- $io->error('Failed to generate the view');
+ $io->error(sprintf('The %s view generation has failed',$view));
return 1;
diff --git a/eywa/Console/Get/Documentation.php b/eywa/Console/Get/Documentation.php
index d2c5a8a..466b8e4 100644..100755
--- a/eywa/Console/Get/Documentation.php
+++ b/eywa/Console/Get/Documentation.php
@@ -17,7 +17,7 @@
protected static $defaultName = "get:doc";
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Get the eywa and shaolin documentation')->addArgument('directory',InputArgument::REQUIRED,'The documentation directory name');
}
@@ -34,7 +34,7 @@
$io = new SymfonyStyle($input,$output);
$io->title('Downlaoding or updating the documentation');
- $dir = $input->getArgument('directory');
+ $dir = strval($input->getArgument('directory'));
if(is_dir($dir))
{
if(chdir($dir))
diff --git a/eywa/Console/Get/Wanted.php b/eywa/Console/Get/Wanted.php
index 42b6993..4c988e5 100644..100755
--- a/eywa/Console/Get/Wanted.php
+++ b/eywa/Console/Get/Wanted.php
@@ -17,7 +17,7 @@
protected static $defaultName = "get:wanted";
- protected function configure()
+ protected function configure(): void
{
$this->setDescription('Get the wanted style')->addArgument('directory',InputArgument::REQUIRED,'The documentation directory name');
}
@@ -34,7 +34,7 @@
$io = new SymfonyStyle($input,$output);
$io->title('Downlaoding wanted');
- $dir = $input->getArgument('directory');
+ $dir = strval($input->getArgument('directory'));
if(is_dir($dir))
{
diff --git a/eywa/Console/Git/GetWanted.php b/eywa/Console/Git/GetWanted.php
index afd4f78..afd4f78 100644..100755
--- a/eywa/Console/Git/GetWanted.php
+++ b/eywa/Console/Git/GetWanted.php
diff --git a/eywa/Console/Lang/CreateCatalogues.php b/eywa/Console/Lang/CreateCatalogues.php
index 9ca56d2..3d0c9e6 100644..100755
--- a/eywa/Console/Lang/CreateCatalogues.php
+++ b/eywa/Console/Lang/CreateCatalogues.php
@@ -3,9 +3,8 @@
namespace Eywa\Console\Lang {
-
- use DI\DependencyException;
- use DI\NotFoundException;
+;
+ use Exception;
use Eywa\Console\Shell;
use Eywa\Exception\Kedavra;
use Symfony\Component\Console\Command\Command;
@@ -18,7 +17,7 @@ namespace Eywa\Console\Lang {
protected static $defaultName = "catalogues:generate";
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Create all catalogues');
}
@@ -27,9 +26,8 @@ namespace Eywa\Console\Lang {
* @param InputInterface $input
* @param OutputInterface $output
* @return int
- * @throws DependencyException
* @throws Kedavra
- * @throws NotFoundException
+ * @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output)
{
@@ -42,17 +40,17 @@ namespace Eywa\Console\Lang {
{
if ($this->generate($locale))
{
- $io->title("Generating the $locale catalog");
- $io->success("The $locale catalog was successfully generated");
+ $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("The $locale catalog already exist");
+ $io->warning(sprintf('The %s catalog already exist',$locale));
$x->push(false);
}
}
if ($x->ok())
{
- $io->success("All catalogs was successfully generated");
+ $io->success("All catalogs has been successfully generated");
return 0;
}
@@ -61,26 +59,33 @@ namespace Eywa\Console\Lang {
}
/**
- * @param $locale
+ * @param string $locale
* @return bool
- * @throws DependencyException
- * @throws NotFoundException
+ * @throws Exception
+ *
*/
- public function generate($locale)
+ public function generate(string $locale): bool
{
if (!is_dir('po'))
mkdir('po');
if (!is_dir("po/$locale"))
{
- $files = collect(glob(base('app','Views') .DIRECTORY_SEPARATOR.'*.php'))->merge(glob(base('app','Views').DIRECTORY_SEPARATOR. '*'.DIRECTORY_SEPARATOR.'*.php'))->join(' ');
+ $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'));
- $app_name = env('APP_NAME','eywa');
- $app_version = env('APP_VERSION','1.0');
- $translator_email = env('TRANSLATOR_EMAIL','translator@free.fr');
+ $translator_email = strval(env('TRANSLATOR_EMAIL','translator@free.fr'));
mkdir("po/$locale");
mkdir("po/$locale/LC_MESSAGES");
- (new Shell("xgettext --keyword=_ --language=PHP --add-comments --msgid-bugs-address=$translator_email --package-version=$app_version --package-name=$app_name --sort-output -o po/$app_name.pot -f $files"))->run();
+ (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 po/$app_name.pot -f $files"))->run();
(new Shell("msginit --locale=$locale -i po/$app_name.pot -o po/$locale/LC_MESSAGES/messages.po"))->run();
return true;
}
diff --git a/eywa/Console/Lang/UpdateCatalogues.php b/eywa/Console/Lang/UpdateCatalogues.php
index 7b2d34c..fb14354 100644..100755
--- a/eywa/Console/Lang/UpdateCatalogues.php
+++ b/eywa/Console/Lang/UpdateCatalogues.php
@@ -4,9 +4,9 @@
namespace Eywa\Console\Lang {
+ use Exception;
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;
@@ -15,7 +15,7 @@ namespace Eywa\Console\Lang {
{
protected static $defaultName = "catalogues:refresh";
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Update all catalogues');
@@ -31,10 +31,10 @@ namespace Eywa\Console\Lang {
{
if ($this->update($catalogue))
{
- $io->success("The $catalogue catalog has been updating successfully");
+ $io->error(sprintf('The %s catologue has been updated successfully',$catalogue));
$x->push(true);
}else{
- $io->error("The update $catalogue catalog has been fail");
+ $io->error(sprintf('The %s catologue update has failed',$catalogue));
$x->push(false);
}
}
@@ -51,25 +51,37 @@ namespace Eywa\Console\Lang {
}
- public function update($locale)
+ /**
+ * @param string $locale
+ * @return bool
+ *
+ *
+ * @throws Exception
+ */
+ public function update(string $locale): bool
{
if (is_dir("po/$locale"))
{
- $files = collect(glob(base('app','Views','*.php')))->merge(glob(base('app','Views','*','*.php')))->join(' ');
+ $view_base = files(base('app','Views','*.php'));
+ $view_prof = files(base('app','Views','*','*.php'));
- $app_name = env('APP_NAME','eywa');
+ $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 = env('APP_VERSION','1.0');
- $translator_email = env('TRANSLATOR_EMAIL','translator@free.fr');
+ $app_version = strval(env('APP_VERSION','1.0'));
+ $translator_email = strval(env('TRANSLATOR_EMAIL','translator@free.fr'));
if((new Shell("xgettext --keyword=_ --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 c7b5437..a2224f9 100644..100755
--- a/eywa/Console/Mode/DevMode.php
+++ b/eywa/Console/Mode/DevMode.php
@@ -14,7 +14,7 @@ namespace Eywa\Console\Mode {
protected static $defaultName = 'app:dev';
- protected function configure()
+ 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 5c5a5f4..1d2e472 100644..100755
--- a/eywa/Console/Mode/Maintenance.php
+++ b/eywa/Console/Mode/Maintenance.php
@@ -14,7 +14,7 @@
protected static $defaultName = 'app:down';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Put the application in maintenance mode');
}
diff --git a/eywa/Console/Mode/ProductionMode.php b/eywa/Console/Mode/ProductionMode.php
index 68f5824..e2cd15f 100644..100755
--- a/eywa/Console/Mode/ProductionMode.php
+++ b/eywa/Console/Mode/ProductionMode.php
@@ -14,9 +14,8 @@ namespace Eywa\Console\Mode {
protected static $defaultName = 'app:prod';
- protected function configure()
+ protected function configure():void
{
-
$this->setDescription('Put the application in production mode');
}
diff --git a/eywa/Console/Routes/AddRoute.php b/eywa/Console/Routes/AddRoute.php
index 4599393..479461d 100644..100755
--- a/eywa/Console/Routes/AddRoute.php
+++ b/eywa/Console/Routes/AddRoute.php
@@ -20,7 +20,7 @@ namespace Eywa\Console\Routes {
private Collect $entry;
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Create a new route');
}
@@ -90,15 +90,13 @@ namespace Eywa\Console\Routes {
$this->entry->put('created_at',now()->toDateTimeString())->put('updated_at',now()->toDateTimeString());
-
-
- if($this->routes->push(Web::create($this->entry->all())))
+ if(Web::create($this->entry->all()))
{
- $route = $this->entry->get('route');
- $io->success("The $route route has been created successfully");
+ $route = $this->entry->get('name');
+ $io->success(sprintf('The %s route has been created successfully',$route));
}else
{
- $io->error("Failed to create the $route route");
+ $io->error(sprintf('Failed to create the %s route',$route));
return 1;
}
diff --git a/eywa/Console/Routes/FindRoute.php b/eywa/Console/Routes/FindRoute.php
index 1843b49..c201c99 100644..100755
--- a/eywa/Console/Routes/FindRoute.php
+++ b/eywa/Console/Routes/FindRoute.php
@@ -3,16 +3,14 @@
namespace Eywa\Console\Routes {
- use DI\DependencyException;
- use DI\NotFoundException;
use Eywa\Exception\Kedavra;
- use Eywa\Http\Routing\Admin;
- use Eywa\Http\Routing\Task;
use Eywa\Http\Routing\Web;
use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
+ use Symfony\Component\Console\Style\SymfonyStyle;
class FindRoute extends Command
{
@@ -24,16 +22,11 @@ namespace Eywa\Console\Routes {
* The search value
*
*/
- private string $search;
+ private string $search ='';
+
- /**
- *
- * The base choose
- *
- */
- private string $choose;
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Find a route');
@@ -45,73 +38,40 @@ namespace Eywa\Console\Routes {
* @param InputInterface $input
* @param OutputInterface $output
*
+ * @return int
* @throws Kedavra
- * @throws DependencyException
- * @throws NotFoundException
*/
- public function interact(InputInterface $input, OutputInterface $output)
+ public function interact(InputInterface $input, OutputInterface $output):int
{
- $helper = $this->getHelper('question');
-
- do {
-
- do {
- clear_terminal();
-
- $question = new Question("<info>Route for admin, web or task ?</info> : ");
-
- $question->setAutocompleterValues(['admin', 'web','task']);
-
- $this->choose = $helper->ask($input, $output, $question);
-
- } while (is_null($this->choose) || not_in(['admin', 'web','task'], $this->choose));
-
- do {
- clear_terminal();
-
- $question = new Question("<info>Please enter the search value : </info>");
-
- switch ($this->choose)
- {
- case 'admin':
- $question->setAutocompleterValues($this->admin());
- break;
- case 'task':
- $question->setAutocompleterValues($this->task());
- break;
- default:
- $question->setAutocompleterValues($this->web());
- break;
- }
-
- $this->search = $helper->ask($input, $output, $question);
+ $io = new SymfonyStyle($input,$output);
+ do
+ {
+ do
+ {
+ $this->search = $io->askQuestion((new Question('Type your search : '))->setAutocompleterValues($this->all()));
+ } while (not_def($this->search));
- } while (is_null($this->search));
+ $table = new Table($output);
+ $io = new SymfonyStyle($input,$output);
- clear_terminal();
- switch ($this->choose)
- {
- case 'admin':
- routes($output,Admin::search($this->search)) ;
- break;
- case 'task':
- routes($output, Task::search($this->search));
- break;
- default:
- routes($output,Web::search($this->search));
- break;
- }
+ $table
+ ->setStyle('box')
+ ->setHeaders(['id', 'method', 'name','url','controller','action','namespace','created','updated'])
+ ->setRows(
+ Web::like($this->search,\PDO::FETCH_ASSOC)
+ )
+ ;
+ $table->render();
+ }while($io->confirm('Continue ?',true));
+ return 0;
+ }
- $question = new Question("<info>Continue [Y/n] : </info>", 'Y');
- $continue = strtoupper($helper->ask($input, $output, $question)) === 'Y';
- } while ($continue);
- }
/**
* @param InputInterface $input
@@ -122,179 +82,82 @@ namespace Eywa\Console\Routes {
public function execute(InputInterface $input, OutputInterface $output)
{
- $output->writeln('<info>bye</info>');
+ $io = new SymfonyStyle($input,$output);
+ $io->success('Bye');
return 0;
}
+
/**
- * @param bool $web
- * @param bool $admin
- * @return array
- * @throws DependencyException
+ * @return array<string>
* @throws Kedavra
- * @throws NotFoundException
*/
- private function controller(bool $web =true,bool $admin = false): array
+ private function controller(): array
{
$x = collect();
- if ($web)
- {
- foreach (Web::all() as $v)
- $x->push($v->controller);
- return $x->all();
- }
-
- if ($admin)
- {
- foreach (Admin::all() as $v)
- $x->push($v->controller);
-
-
- return $x->all();
- }
-
- foreach (Task::all() as $v)
+ foreach (Web::all() as $v)
$x->push($v->controller);
-
-
return $x->all();
+
}
+
/**
- * @param bool $web
- * @param bool $admin
- * @return array
- * @throws DependencyException
+ * @return array<string>
* @throws Kedavra
- * @throws NotFoundException
*/
- private function name(bool $web = true,bool $admin =false): array
+ private function name(): array
{
$x = collect();
- if ($web)
- {
- foreach (Web::all() as $v)
- $x->push($v->name);
- return $x->all();
- }
- if ($admin)
- {
- foreach (Admin::all() as $v)
- $x->push($v->name);
- return $x->all();
- }
-
- foreach (Task::all() as $v)
+ foreach (Web::all() as $v)
$x->push($v->name);
-
-
return $x->all();
+
}
+
/**
- * @param bool $web
- * @param bool $admin
- * @return array
- * @throws DependencyException
+ * @return array<string>
* @throws Kedavra
- * @throws NotFoundException
*/
- private function url(bool $web = true,bool $admin = false): array
+ private function url(): array
{
$x = collect();
- if ($web)
- {
- foreach (Web::all() as $v)
- $x->push($v->url);
- return $x->all();
- }
-
- if ($admin)
- {
- foreach (Admin::all() as $v)
- $x->push($v->url);
- return $x->all();
- }
-
- foreach (Task::all() as $v)
+ foreach (Web::all() as $v)
$x->push($v->url);
-
return $x->all();
+
}
+
/**
- * @param bool $web
- * @param bool $admin
- * @return array
- * @throws DependencyException
+ * @return array<string>
* @throws Kedavra
- * @throws NotFoundException
*/
- private function action(bool $web =true,bool $admin = false)
+ private function action():array
{
$x = collect();
- if ($web)
- {
- foreach (Web::all() as $v)
- $x->push($v->action);
- return $x->all();
- }
- if ($admin)
- {
- foreach (Admin::all() as $v)
+ foreach (Web::all() as $v)
$x->push($v->action);
-
return $x->all();
- }
-
- foreach (Task::all() as $v)
- $x->push($v->action);
-
- return $x->all();
}
- /**
- * @return array
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- */
- private function web()
- {
-
- return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(), $this->url(),$this->action(), $this->controller())->all();
- }
/**
- * @return array
- * @throws DependencyException
+ * @return array<string>
* @throws Kedavra
- * @throws NotFoundException
*/
- private function admin()
+ private function all():array
{
-
- return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(false,true),$this->url(false,true),$this->action(false,true),$this->controller(false,true))->all();
- }
-
- /**
- * @return array
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- */
- private function task()
- {
-
- return collect()->merge(controllers(), collect(METHOD_SUPPORTED)->for('strtolower')->all(),$this->name(false,false),$this->url(false,false),$this->action(false,false),$this->controller(false,false))->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 7591efa..0ce2da8 100644..100755
--- a/eywa/Console/Routes/ListRoute.php
+++ b/eywa/Console/Routes/ListRoute.php
@@ -3,34 +3,21 @@
namespace Eywa\Console\Routes {
- use DI\DependencyException;
- use DI\NotFoundException;
-
use Eywa\Exception\Kedavra;
- use Eywa\Http\Routing\Admin;
- use Eywa\Http\Routing\Task;
use Eywa\Http\Routing\Web;
+ use PDO;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
- use Symfony\Component\Console\Helper\TableStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Question\Question;
- use Symfony\Component\Console\Style\SymfonyStyle;
class ListRoute extends Command
{
protected static $defaultName = "route:list";
- /**
- *
- * The base choose
- *
- */
- private string $choose;
- protected function configure()
+ protected function configure():void
{
$this->setDescription('List all routes');
}
@@ -49,13 +36,13 @@ namespace Eywa\Console\Routes {
{
$table = new Table($output);
-
+
$table
->setStyle('box')
->setHeaders(['id', 'method', 'name','url','controller','action','namespace','created','updated'])
->setRows(
- Web::all(\PDO::FETCH_ASSOC)
+ Web::all(PDO::FETCH_ASSOC)
)
;
$table->render();
diff --git a/eywa/Console/Routes/RemoveRoute.php b/eywa/Console/Routes/RemoveRoute.php
index 75b5441..53e240c 100644..100755
--- a/eywa/Console/Routes/RemoveRoute.php
+++ b/eywa/Console/Routes/RemoveRoute.php
@@ -3,191 +3,86 @@
namespace Eywa\Console\Routes {
- use DI\DependencyException;
- use DI\NotFoundException;
use Eywa\Exception\Kedavra;
- use Eywa\Http\Routing\Admin;
- use Eywa\Http\Routing\Task;
use Eywa\Http\Routing\Web;
- use Symfony\Component\Console\Helper\Helper;
+ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
-
- class RemoveRoute extends \Symfony\Component\Console\Command\Command
+ class RemoveRoute extends Command
{
protected static $defaultName = "route:destroy";
- /**
- *
- * The route name
- *
- */
- private string $route_name;
-
- /**
- *
- * The route id
- *
- */
- private int $id = 0;
-
- /**
- *
- * The base choose
- *
- */
- private string $choose;
/**
*
- * The routes names
+ * The route name
*
*/
- private array $names;
+ private string $route = '';
- /**
- *
- * Instance of question helper
- *
- */
- private Helper $helper;
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Delete a route');
}
/**
- * @param bool $web
- * @param bool $admin
- * @return array
- * @throws DependencyException
+ * @return array<string>
* @throws Kedavra
- * @throws NotFoundException
*/
- public function name(bool $web = true, $admin = false)
+ public function name():array
{
$x = collect();
- if ($web)
- {
+
foreach (Web::all() as $v)
$x->push($v->name);
return $x->all();
- }
- if ($admin)
- {
- foreach (Admin::all() as $v)
- $x->push($v->name);
-
- return $x->all();
- }
- foreach (Task::all() as $v)
- $x->push($v->name);
-
- return $x->all();
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- */
- public function interact(InputInterface $input, OutputInterface $output)
- {
-
-
- $this->helper = $this->getHelper('question');
-
-
- $this->choose = 'web';
- switch ($this->choose)
- {
- case 'admin':
- $this->names = $this->name(false);
- break;
- case 'task':
- $this->names = $this->name(false, false);
- break;
- default:
- $this->names = $this->name();
- break;
- }
-
-
- }
/**
* @param InputInterface $input
* @param OutputInterface $output
- *
- * @return int|void|null
- * @throws DependencyException
+ * @return int
* @throws Kedavra
- * @throws NotFoundException
*/
- public function execute(InputInterface $input, OutputInterface $output)
+ public function execute(InputInterface $input, OutputInterface $output):int
{
$io = new SymfonyStyle($input,$output);
- $io->title('Removing the route');
- if (not_def($this->names))
+ if (def(Web::all()))
{
- clear_terminal();
- $output->writeln("<error>The table is empty</error>");
- return 1;
- }
-
- do {
- clear_terminal();
+ do
+ {
+ 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(Web::by('name',$this->route)));
- $question = new Question("<info>Enter the route name</info> : ");
- $question->setAutocompleterValues($this->names);
+ $route = intval(Web::by('name',$this->route)[0]->id);
- $x = $this->helper->ask($input, $output, $question);
+ $name = strval(Web::by('name',$this->route)[0]->name);
- $this->route_name = $x;
- } while (is_null($x) || collect($this->names)->not_exist($x));
+ if (Web::destroy($route))
+ $io->success(sprintf('The %s route has been deleted successfully',$name));
+ else
+ $io->error(sprintf('The %s route has not been deleted',$name));
- switch ($this->choose)
- {
- case 'admin':
+ }while($io->confirm('Continue ?',true));
+ $io->success('Bye');
+ return 0;
+ }
- $this->id = collect(collect(Admin::by('name', $this->route_name))->get(0))->first();
- if (Admin::destroy($this->id))
- {
- $io->success('The route was removed successfully');
- return 0;
- }
- break;
- case 'task':
- $this->id = intval(collect(Task::by('name', $this->route_name))->get('id'));
- if (Task::destroy($this->id))
- {
- $io->success('The route was removed successfully');
- return 0;
- }
- break;
- default:
- $this->id = collect(collect(Web::by('name', $this->route_name))->get(0))->first();
-
- if (Web::destroy($this->id))
- {
- $io->success('The route was removed successfully');
+ $io->warning('No routes has been found');
- return 0;
- }
- break;
- }
- $io->error('Fail to remove the route');
- return 1;
+ return 0;
}
}
diff --git a/eywa/Console/Routes/UpdateRoute.php b/eywa/Console/Routes/UpdateRoute.php
index 2810968..d0808ac 100644..100755
--- a/eywa/Console/Routes/UpdateRoute.php
+++ b/eywa/Console/Routes/UpdateRoute.php
@@ -30,13 +30,13 @@ namespace Eywa\Console\Routes {
*/
private string $search = '';
- protected function configure()
+ protected function configure():void
{
$this->setDescription('Update a route');
}
/**
- * @return array
+ * @return array<string>
* @throws Kedavra
*/
private function name()
@@ -62,61 +62,67 @@ namespace Eywa\Console\Routes {
$io = new SymfonyStyle($input,$output);
$this->entry = collect();
- do
+ if (def(Web::all()))
{
+ do
+ {
- do{
- $this->search = $io->askQuestion((new Question('What is the name of the route to update ?','root'))->setAutocompleterValues($this->name()));
- }while(not_def(Web::by('name',$this->search)));
+ do{
+ $this->search = $io->askQuestion((new Question('What is the name of the route to update ?','root'))->setAutocompleterValues($this->name()));
+ }while(not_def(Web::by('name',$this->search)));
- $route = Web::by('name', $this->search)[0];
+ $route = Web::by('name', $this->search)[0];
- do
- {
- $this->entry->put('name', $io->askQuestion((new Question('Change the route name ? ',$route->name))));
- }while(not_def($this->entry->get('name')) || def(Web::by('name',$this->entry->get('name'))) && $this->entry->get('name') !== $route->name);
+ do
+ {
+ $this->entry->put('name', $io->askQuestion((new Question('Change the route name ? ',$route->name))));
+ }while(not_def($this->entry->get('name')) || def(Web::by('name',$this->entry->get('name'))) && $this->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')));
+ 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')));
- do
- {
- $this->entry->put('url', $io->askQuestion((new Question('Change the route url ? ',$route->url))));
- }while(not_def($this->entry->get('url')) || def(Web::by('url',$this->entry->get('url'))) && $this->entry->get('url') !== $route->url);
+ do
+ {
+ $this->entry->put('url', $io->askQuestion((new Question('Change the route url ? ',$route->url))));
+ }while(not_def($this->entry->get('url')) || def(Web::by('url',$this->entry->get('url'))) && $this->entry->get('url') !== $route->url);
- do
- {
- $this->entry->put('controller', $io->askQuestion((new Question('Change the route controller ? ',$route->controller))));
- }while(not_def($this->entry->get('controller')));
- do
- {
- $this->entry->put('action', $io->askQuestion((new Question('Change the route action ? ',$route->action))));
- }while(not_def($this->entry->get('action')) || def(Web::by('action',$this->entry->get('action'))) && $this->entry->get('action') !== $route->action);
- do
- {
- $this->entry->put('directory', $io->askQuestion((new Question('Change the route namespace ? ',$route->directory))));
- }while(not_def($this->entry->get('directory')));
+ do
+ {
+ $this->entry->put('controller', $io->askQuestion((new Question('Change the route controller ? ',$route->controller))));
+ }while(not_def($this->entry->get('controller')));
+ do
+ {
+ $this->entry->put('action', $io->askQuestion((new Question('Change the route action ? ',$route->action))));
+ }while(not_def($this->entry->get('action')) || def(Web::by('action',$this->entry->get('action'))) && $this->entry->get('action') !== $route->action);
+ do
+ {
+ $this->entry->put('directory', $io->askQuestion((new Question('Change the route namespace ? ',$route->directory))));
+ }while(not_def($this->entry->get('directory')));
- $this->entry->put('created_at',$route->created_at);
- $this->entry->put('updated_at',now()->toDateTimeString());
+ $this->entry->put('created_at',$route->created_at);
+ $this->entry->put('updated_at',now()->toDateTimeString());
- if(Web::update(intval($route->id),$this->entry->all()))
- {
- $io->success('The route has been updated successfully');
- }else{
- $io->error('The route has not been updated');
- return 1;
- }
+ if(Web::update(intval($route->id),$this->entry->all()))
+ {
+ $io->success('The route has been updated successfully');
+ }else{
+ $io->error('The route has not been updated');
+ return 1;
+ }
- $this->entry->clear();
+ $this->entry->clear();
- }while($io->confirm('Continue to update routes ?',true));
+ }while($io->confirm('Continue to update routes ?',true));
+ return 0;
+ }
+ $io->warning('Cannot update a route no routes has been found');
return 0;
+
}
diff --git a/eywa/Console/Shell.php b/eywa/Console/Shell.php
index 0026c3e..89cb870 100644..100755
--- a/eywa/Console/Shell.php
+++ b/eywa/Console/Shell.php
@@ -10,11 +10,11 @@ use Symfony\Component\Process\Process;
class Shell
{
/**
- * @var array|string[]
+ * @var array<string>
*/
private array $commands;
/**
- * @var Process
+ * @var Process<mixed>
*/
private Process $process;
@@ -29,160 +29,10 @@ class Shell
/**
*
- * Get the command
- *
- * @return string
- *
- */
- public function command(): string
- {
- return $this->process->getCommandLine();
- }
-
- /**
- *
- * Get the env values
- *
- * @return array
- *
- */
- public function env(): array
- {
- return $this->process->getEnv();
- }
-
- /**
- *
- * Set env data
- *
- * @param mixed ...$env
- *
- * @return Shell
- *
- */
- public function set_env(...$env): Shell
- {
- $this->process->setEnv($env);
-
- return $this;
- }
-
- /**
- *
- * Set env data
- *
- * @param float $timeout
- *
- * @return Shell
- *
- */
- public function set_idle_timeout(float $timeout): Shell
- {
- $this->process->setIdleTimeout($timeout);
-
- return $this;
- }
-
- /**
- *
- * Set env data
- *
- * @param string|int|float|bool|resource|Traversable|null $input
- *
- * @return Shell
- *
- */
- public function set_input($input): Shell
- {
- $this->process->setInput($input);
-
- return $this;
- }
-
- /**
- *
- * Set env data
- *
- * @param bool $tty
- * @return Shell
- */
- public function set_tty(bool $tty): Shell
- {
- $this->process->setTty($tty);
-
- return $this;
- }
-
-
- /**
- *
- * Set env data
- *
- * @param float $timeout
- *
- * @return Shell
- *
- */
- public function set_timeout(float $timeout): Shell
- {
- $this->process->setTimeout($timeout);
-
- return $this;
- }
-
- /**
- *
- * Set env data
- *
- * @param bool $pty
- * @return Shell
- */
- public function set_pty(bool $pty): Shell
- {
- $this->process->setPty($pty);
-
- return $this;
- }
-
- /**
- *
- * Check if is tty mode
- *
- * @return bool
- *
- */
- public function is_tty():bool
- {
- return $this->process->isTty();
- }
-
- /**
- *
- * Check if is pty mode
- *
- * @return bool
- *
- */
- public function is_pty():bool
- {
- return $this->process->isPty();
- }
-
- /**
- *
- * @return bool
- *
- */
- public function success()
- {
- return $this->process->isSuccessful();
- }
- /**
- *
* Run the thell command
*
* @param callable|null $callback
- * @param array $env
+ * @param array<mixed> $env
*
* @return bool
*
@@ -190,6 +40,6 @@ class Shell
public function run(callable $callback = null, array $env = []): bool
{
$this->process->run($callback, $env);
- return $this->success();
+ return $this->process->isSuccessful();
}
} \ No newline at end of file
diff --git a/eywa/Database/Base/Base.php b/eywa/Database/Base/Base.php
index f5ab9ad..f5ab9ad 100644..100755
--- a/eywa/Database/Base/Base.php
+++ b/eywa/Database/Base/Base.php
diff --git a/eywa/Database/Connexion/Connect.php b/eywa/Database/Connexion/Connect.php
index ce94cbe..edd8345 100644..100755
--- a/eywa/Database/Connexion/Connect.php
+++ b/eywa/Database/Connexion/Connect.php
@@ -25,6 +25,7 @@ namespace Eywa\Database\Connexion {
*
* The queries to execute
*
+ * @var array<string>
*/
private array $queries = [];
@@ -47,7 +48,7 @@ namespace Eywa\Database\Connexion {
* The current base port
*
*/
- private ?int $port = null;
+ private int $port = 3306;
/**
@@ -55,21 +56,14 @@ namespace Eywa\Database\Connexion {
* The current base username
*
*/
- private ?string $username = null;
+ private string $username;
/**
*
* The current base password
*
*/
- private ?string $password = null;
-
- /**
- *
- * The connexion options
- *
- */
- private array $options = [];
+ private string $password;
/**
*
@@ -81,7 +75,7 @@ namespace Eywa\Database\Connexion {
/**
*
* The sql query args
- *
+ * @var array<mixed>
*/
private array $args = [];
@@ -100,16 +94,15 @@ namespace Eywa\Database\Connexion {
$this->port = $port;
$this->username = $username;
$this->password = $password;
- $this->options = config('connexion','options');
$this->host = $host;
}
/**
* @inheritDoc
*/
- public function set(string ...$queries): Connexion
+ public function set(string $query): Connexion
{
- $this->queries = array_merge($this->queries,$queries);
+ $this->queries = array_merge($this->queries,[$query]);
return $this;
}
@@ -169,7 +162,7 @@ namespace Eywa\Database\Connexion {
return [];
}
}
- return $x;
+ return is_array($x) ? $x : [$x];
}
/**
@@ -227,29 +220,24 @@ namespace Eywa\Database\Connexion {
}
/**
- * @param string[] $users
+ *
+ * @param string $user
+ *
* @return bool
+ *
* @throws Kedavra
+ *
*/
- public function remove_user(string ...$users): bool
+ public function remove_user(string $user): bool
{
$x = collect();
if (in_array($this->driver(),[MYSQL,POSTGRESQL]))
{
- foreach ($users as $user)
- $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();
}
- public function create_root()
- {
- if (collect($this->set('select rolname from pg_roles')->execute())->not_exist('root') && $this->postgresql())
- return $this->set("CREATE USER root WITH PASSWORD 'root' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN")->execute();
-
- return false;
- }
-
/**
* @param string $user
* @param string $password
@@ -264,13 +252,10 @@ namespace Eywa\Database\Connexion {
{
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();
- break;
case POSTGRESQL:
return $this->set("CREATE USER $user WITH PASSWORD '$password' LOGIN;")->set("GRANT ALL PRIVILEGES ON DATABASE $base TO $user")->execute();
- break;
default:
return false;
- break;
}
}
@@ -290,10 +275,17 @@ namespace Eywa\Database\Connexion {
return $this->pdo()->commit();
}
- public function info()
+ /**
+ *
+ * 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 collect(get_object_vars($this))->del(['connexion','queries','args','options'])->each(function ($k,$v){
return "\$$k=$v;";
})->join('');
@@ -471,8 +463,7 @@ namespace Eywa\Database\Connexion {
public function query(string $query)
{
$x = $this->pdo()->query($query);
-
- return $x->fetch(PDO::FETCH_COLUMN);
+ return is_bool($x) ? $x : $x->fetch(PDO::FETCH_COLUMN);
}
/**
@@ -480,7 +471,7 @@ namespace Eywa\Database\Connexion {
*/
public function development(): Connect
{
- return new static(env('DEVELOP_DB_DRIVER','mysql'),env('DEVELOP_DB_NAME','ikran'),env('DEVELOP_DB_USERNAME','ikran'),env('DEVELOP_DB_PASSWORD','ikran'),intval(env('DEVELOP_DB_PORT',3306)),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')),intval(env('DEVELOP_DB_PORT',3306)),strval(env('DEVELOP_DB_HOST','localhost')));
}
/**
@@ -491,7 +482,7 @@ namespace Eywa\Database\Connexion {
{
if (is_null($this->connexion))
{
- $this->connexion = equal($this->driver,SQL_SERVER) ? new PDO("{$this->driver}:Serve={$this->host};Database={$this->base}",$this->username,$this->password,config('connexion','options')) : (equal($this->driver,SQLITE) ? new PDO("sqlite:{$this->base}") : new PDO("{$this->driver}:host={$this->host};port={$this->port};dbname={$this->base}", $this->username, $this->password, config('connexion','options')));
+ $this->connexion = equal($this->driver,SQL_SERVER) ? new PDO("{$this->driver}:Serve={$this->host};Database={$this->base}",$this->username,$this->password,[]) : (equal($this->driver,SQLITE) ? new PDO("sqlite:{$this->base}") : new PDO("{$this->driver}:host={$this->host};port={$this->port};dbname={$this->base}", $this->username, $this->password, []));
$this->connexion->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
try {
diff --git a/eywa/Database/Connexion/Connexion.php b/eywa/Database/Connexion/Connexion.php
index 2bb28eb..0f18b15 100644..100755
--- a/eywa/Database/Connexion/Connexion.php
+++ b/eywa/Database/Connexion/Connexion.php
@@ -27,16 +27,17 @@ namespace Eywa\Database\Connexion {
* @throws Kedavra
*/
public function __construct(string $driver, string $base,string $username ='',string $password ='',int $port = 3306, string $host = LOCALHOST);
+
/**
*
* Set the sql queries to execute
*
- * @param string[] $queries
+ * @param string $query
*
* @return Connexion
*
*/
- public function set(string ...$queries): Connexion;
+ public function set(string $query): Connexion;
/**
*
@@ -90,9 +91,9 @@ namespace Eywa\Database\Connexion {
*
*
* @param string $class
- * @param array $args
+ * @param array<mixed> $args
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*
@@ -108,7 +109,7 @@ namespace Eywa\Database\Connexion {
*
* @param int $style
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*
diff --git a/eywa/Database/Export/Export.php b/eywa/Database/Export/Export.php
index c7bfb5f..078a73c 100644..100755
--- a/eywa/Database/Export/Export.php
+++ b/eywa/Database/Export/Export.php
@@ -6,16 +6,21 @@ namespace Eywa\Database\Export {
use Eywa\Console\Shell;
- use Eywa\Database\Connexion\Connexion;
+ use Eywa\Database\Connexion\Connect;
class Export
{
/**
*
*/
- private Connexion $connexion;
+ private Connect $connexion;
- public function __construct(Connexion $connexion)
+ /**
+ * Export constructor.
+ *
+ * @param Connect $connexion
+ */
+ public function __construct(Connect $connexion)
{
$this->connexion = $connexion;
}
@@ -32,16 +37,12 @@ namespace Eywa\Database\Export {
{
case MYSQL:
return (new Shell("mysqldump -u $username -p$password $base > $file"))->run();
- break;
case POSTGRESQL:
return (new Shell("pg_dump -h $host -U $username $base > $file"))->run();
- break;
case SQLITE:
return (new Shell("sqlite3 $base > $file"))->run();
- break;
default:
return false;
- break;
}
diff --git a/eywa/Database/Import/Import.php b/eywa/Database/Import/Import.php
index 4b221ee..f5bf3dd 100644..100755
--- a/eywa/Database/Import/Import.php
+++ b/eywa/Database/Import/Import.php
@@ -7,7 +7,7 @@ namespace Eywa\Database\Import {
use Eywa\Console\Shell;
- use Eywa\Database\Connexion\Connexion;
+ use Eywa\Database\Connexion\Connect;
class Import
{
@@ -17,14 +17,17 @@ namespace Eywa\Database\Import {
* The connection to the base
*
*/
- private Connexion $connect;
+ private Connect $connect;
/**
+ *
* Import constructor.
- * @param Connexion $connect
+ *
+ * @param Connect $connect
+ *
*/
- public function __construct(Connexion $connect)
+ public function __construct(Connect $connect)
{
$this->connect = $connect;
@@ -54,16 +57,12 @@ namespace Eywa\Database\Import {
{
case MYSQL:
return (new Shell("mysqldump -h $host -u $username -p$password $base < $file"))->run();
- break;
case POSTGRESQL:
return (new Shell("psql -h $host -U $username $base < $file"))->run();
- break;
case SQLITE:
return (new Shell("sqlite3 $base < $file"))->run();
- break;
default:
return false;
- break;
}
}
diff --git a/eywa/Database/Migration/CreateMigrationTable.php b/eywa/Database/Migration/CreateMigrationTable.php
index a673486..a673486 100644..100755
--- a/eywa/Database/Migration/CreateMigrationTable.php
+++ b/eywa/Database/Migration/CreateMigrationTable.php
diff --git a/eywa/Database/Migration/Migrate.php b/eywa/Database/Migration/Migrate.php
index 6126305..e1e403e 100644..100755
--- a/eywa/Database/Migration/Migrate.php
+++ b/eywa/Database/Migration/Migrate.php
@@ -16,12 +16,16 @@ namespace Eywa\Database\Migration {
* List all migrations class sorted by generated date
*
* @param string $mode
- * @return array
+ *
+ * @return array<string>
+ *
+ * @throws \ReflectionException
*/
public static function list(string $mode = 'up'): array
{
$x = [];
- foreach (glob(base('db','Migrations','*.php')) as $k => $v)
+
+ foreach (files(base('db','Migrations','*.php')) as $k => $v)
{
$item = collect(explode(DIRECTORY_SEPARATOR,$v))->last();
@@ -31,7 +35,7 @@ namespace Eywa\Database\Migration {
$class = '\Base\Migrations\\' .$item;
- $x[$class] = $class::$created_at;
+ $x[$class] = (new \ReflectionClass(new $class))->getStaticPropertyValue('created_at');
}
return $mode === 'up' ? collect($x)->asort()->all() : collect($x)->arsort()->all();
}
@@ -41,18 +45,29 @@ namespace Eywa\Database\Migration {
* Execute the migrations
*
* @param string $mode
- *
* @param SymfonyStyle $io
+ *
* @return int
*
* @throws Kedavra
+ * @throws \ReflectionException
+ *
*/
public static function run(string $mode,SymfonyStyle $io):int
{
return equal($mode,'up') ? static::migrate($io) : static::rollback($io);
}
- private static function file(string $class)
+ /**
+ *
+ * Get the class name
+ *
+ * @param string $class
+ *
+ * @return string
+ *
+ */
+ private static function file(string $class): string
{
return collect(explode('\\',$class))->last();
}
@@ -61,6 +76,7 @@ namespace Eywa\Database\Migration {
* @param SymfonyStyle $io
* @return int
* @throws Kedavra
+ * @throws \ReflectionException
*/
private static function migrate(SymfonyStyle $io): int
{
@@ -70,9 +86,15 @@ namespace Eywa\Database\Migration {
}
/**
+ *
+ * Rollback the database
+ *
* @param SymfonyStyle $io
+ *
* @return int
+ *
* @throws Kedavra
+ * @throws \ReflectionException
*/
private static function rollback(SymfonyStyle $io): int
{
@@ -82,8 +104,14 @@ namespace Eywa\Database\Migration {
}
/**
+ *
+ * Check if new migrations are available
+ *
* @return bool
+ *
* @throws Kedavra
+ * @throws \ReflectionException
+ *
*/
public static function check_migrate(): bool
{
@@ -99,10 +127,16 @@ namespace Eywa\Database\Migration {
/**
+ *
+ * Get an instance of the queri builder
+ *
* @param string $mode
* @param string $table
+ *
* @return Sql
+ *
* @throws Kedavra
+ *
*/
private static function sql(string $mode,string $table = 'migrations'): Sql
{
@@ -110,8 +144,13 @@ namespace Eywa\Database\Migration {
}
/**
+ *
+ * Check if migrations has been executed
+ *
* @return bool
+ *
* @throws Kedavra
+ *
*/
public static function check_rollback(): bool
{
@@ -120,13 +159,20 @@ namespace Eywa\Database\Migration {
}
/**
+ *
+ * Execute the command
+ *
* @param string $env
* @param string $mode
* @param SymfonyStyle $io
- * @return bool|int
+ *
+ * @return int
+ *
* @throws Kedavra
+ * @throws \ReflectionException
+ *
*/
- private static function do(string $env,string $mode,SymfonyStyle $io)
+ private static function do(string $env,string $mode,SymfonyStyle $io): int
{
not_in(['up','down'],$mode,true,"Mode must be up or down");
@@ -145,31 +191,33 @@ namespace Eywa\Database\Migration {
foreach ($all as $class => $date)
{
- $migration = static::file($class);
+ $x = new \ReflectionClass(new $class);
- $created_at = $class::$created_at;
+ $table = $x->getStaticPropertyValue('table');
- $down_success_message = str_replace('%s',$class::$table,$class::$down_success_message);
+ $migration = static::file($class);
- $down_error_message = str_replace('%s',$class::$table,$class::$down_error_message);
+ $created_at = $x->getStaticPropertyValue('created_at');
- $up_success_message = str_replace('%s',$class::$table,$class::$up_success_message);
+ $up_success_message = str_replace('%s',$table,$x->getStaticPropertyValue('up_success_message'));
- $up_error_message = str_replace('%s',$class::$table,$class::$up_error_message);
+ $up_error_message = str_replace('%s',$table,$x->getStaticPropertyValue('up_error_message'));
- $up_title = str_replace('%s',$class::$table,$class::$up_title);
+ $up_title = str_replace('%s',$table,$x->getStaticPropertyValue('up_title'));
- $down_title = str_replace('%s',$class::$table,$class::$down_title);
$exist = $sql->where('version',EQUAL,$date)->exist();
if (!$exist)
{
- $x = equal($env,'prod') ? new $class(production(),$mode,$env) : new $class(development(),$mode,$env);
+
+ $i = equal($env,'prod') ? $x->newInstance(production(),$mode,$env) : $x->newInstance(development(),$mode,$env);
$io->title("$up_title ($env)");
- $result->push(call_user_func_array([$x, $mode], []));
+
+ $result->push($x->getMethod('up')->getClosure($i));
+
if ($result->ok())
{
@@ -193,31 +241,27 @@ namespace Eywa\Database\Migration {
foreach ($all as $class => $date)
{
- $migration = static::file($class);
-
- $created_at = $class::$created_at;
-
- $down_success_message = str_replace('%s',$class::$table,$class::$down_success_message);
- $down_error_message = str_replace('%s',$class::$table,$class::$down_error_message);
+ $x = new \ReflectionClass(new $class);
- $up_success_message = str_replace('%s',$class::$table,$class::$up_success_message);
+ $table = $x->getStaticPropertyValue('table');
- $up_error_message = str_replace('%s',$class::$table,$class::$up_error_message);
+ $down_success_message = str_replace('%s',$table,$x->getStaticPropertyValue('down_success_message'));
- $up_title = str_replace('%s',$class::$table,$class::$up_title);
+ $down_error_message = str_replace('%s',$table,$x->getStaticPropertyValue('down_error_message'));
- $down_title = str_replace('%s',$class::$table,$class::$down_title);
+ $down_title = str_replace('%s',$table,$x->getStaticPropertyValue('down_title'));
$exist = $sql->where('version',EQUAL,$date)->exist();
+
if ($exist)
{
- $x = equal($env,'prod') ? new $class(production(),$mode,$env) : new $class(development(),$mode,$env);
+ $i = equal($env,'prod') ? $x->newInstance(production(),$mode,$env) : $x->newInstance(development(),$mode,$env);
$io->title("$down_title ($env)");
- $result->push(call_user_func_array([$x, $mode], []));
+ $result->push($x->getMethod('up')->getClosure($i));
if ($result->ok())
{
@@ -242,31 +286,29 @@ namespace Eywa\Database\Migration {
foreach ($all as $class => $date)
{
- $migration = static::file($class);
-
- $created_at = $class::$created_at;
+ $x = new \ReflectionClass(new $class);
- $down_success_message = str_replace('%s',$class::$table,$class::$down_success_message);
+ $table = $x->getStaticPropertyValue('table');
- $down_error_message = str_replace('%s',$class::$table,$class::$down_error_message);
+ $migration = static::file($class);
- $up_success_message = str_replace('%s',$class::$table,$class::$up_success_message);
+ $created_at = $x->getStaticPropertyValue('created_at');
- $up_error_message = str_replace('%s',$class::$table,$class::$up_error_message);
+ $up_success_message = str_replace('%s',$table,$x->getStaticPropertyValue('up_success_message'));
- $up_title = str_replace('%s',$class::$table,$class::$up_title);
+ $up_error_message = str_replace('%s',$table,$x->getStaticPropertyValue('up_error_message'));
- $down_title = str_replace('%s',$class::$table,$class::$down_title);
+ $up_title = str_replace('%s',$table,$x->getStaticPropertyValue('up_title'));
$exist = $sql->where('version',EQUAL,$date)->exist();
if (!$exist)
{
- $x = equal($env,'prod') ? new $class(production(),$mode,$env) : new $class(development(),$mode,$env);
+ $i= equal($env,'prod') ? $x->newInstance(production(),$mode,$env) : $x->newInstance(development(),$mode,$env);
$io->title("$up_title ($env)");
- $result->push(call_user_func_array([$x, $mode], []));
+ $result->push($x->getMethod('up')->getClosure($i));
if ($result->ok())
{
@@ -290,31 +332,26 @@ namespace Eywa\Database\Migration {
foreach ($all as $class => $date)
{
- $migration = static::file($class);
-
- $created_at = $class::$created_at;
-
- $down_success_message = str_replace('%s',$class::$table,$class::$down_success_message);
- $down_error_message = str_replace('%s',$class::$table,$class::$down_error_message);
+ $x = new \ReflectionClass(new $class);
- $up_success_message = str_replace('%s',$class::$table,$class::$up_success_message);
+ $table = $x->getStaticPropertyValue('table');
- $up_error_message = str_replace('%s',$class::$table,$class::$up_error_message);
+ $down_success_message = str_replace('%s',$table,$x->getStaticPropertyValue('down_success_message'));
- $up_title = str_replace('%s',$class::$table,$class::$up_title);
+ $down_error_message = str_replace('%s',$table,$x->getStaticPropertyValue('down_error_message'));
- $down_title = str_replace('%s',$class::$table,$class::$down_title);
+ $down_title = str_replace('%s',$table,$x->getStaticPropertyValue('down_title'));
$exist = $sql->where('version',EQUAL,$date)->exist();
if ($exist)
{
- $x = equal($env,'prod') ? new $class(production(),$mode,$env) : new $class(development(),$mode,$env);
+ $i = equal($env,'prod') ? $x->newInstance(production(),$mode,$env) : $x->newInstance(development(),$mode,$env);
$io->title("$down_title ($env)");
- $result->push(call_user_func_array([$x, $mode], []));
+ $result->push($x->getMethod('up')->getClosure($i));
if ($result->ok())
{
diff --git a/eywa/Database/Migration/Migration.php b/eywa/Database/Migration/Migration.php
index 3461060..e5e5a20 100644..100755
--- a/eywa/Database/Migration/Migration.php
+++ b/eywa/Database/Migration/Migration.php
@@ -80,6 +80,8 @@ namespace Eywa\Database\Migration {
*
* All constrait for a column
*
+ * @var array<string>
+ *
*/
protected static array $constraint = [];
@@ -111,6 +113,9 @@ namespace Eywa\Database\Migration {
* @var string
*/
private static string $mode;
+ /**
+ * @var string
+ */
private static string $env;
@@ -162,9 +167,11 @@ namespace Eywa\Database\Migration {
* @param string $column
* @param string $type
* @param int $size
- * @param string[] $constraints
+ * @param array<int,string> $constraints
+ *
* @return Migration
*
+ *
* @throws Kedavra
*/
public function add(string $column,string $type,int $size = 0,string ...$constraints): Migration
@@ -202,11 +209,103 @@ namespace Eywa\Database\Migration {
}
/**
- * @param string ...$names
+ * @param string $name
+ *
+ * @return bool
+ *
+ * @throws Kedavra
+ */
+ public function drop_foreign_key(string $name): bool
+ {
+ $table = static::$table;
+
+ switch ($this->driver())
+ {
+ case MYSQL:
+ return $this->connexion()->set(sprintf('ALTER TABLE %s DROP FOREIGN KEY %s',$table,$name))->execute();
+
+ case POSTGRESQL:
+ return $this->connexion()->set(sprintf('ALTER TABLE %s DROP CONSTRAINT %s',$table,$name))->execute();
+ default:
+ return false;
+ }
+ }
+
+ /**
+ *
+ * Rename the table
+ *
+ * @param string $new_name
+ *
+ * @return bool
+ *
+ * @throws Kedavra
+ *
+ */
+ public function rename(string $new_name):bool
+ {
+ $table = static::$table;
+ switch ($this->driver())
+ {
+ case MYSQL:
+ return $this->connexion()->set(sprintf('RENAME TABLE %s TO %s',$table,$new_name))->execute();
+ case POSTGRESQL:
+ return $this->connexion()->set(sprintf('ALTER TABLE %s RENAME TO %s',$table,$new_name))->execute();
+ default:
+ return false;
+ }
+ }
+
+ /**
+ *
+ * Rename the table
+ *
+ * @param string $column_name
+ * @param string $new_name
+ *
+ * @return bool
+ *
+ * @throws Kedavra
+ */
+ public function rename_column(string $column_name,string $new_name): bool
+ {
+ $table = static::$table;
+ switch ($this->driver())
+ {
+ case MYSQL:
+ case POSTGRESQL:
+ return $this->connexion()->set(sprintf('ALTER TABLE %s RENAME COLUMN %s TO %s',$table,$column_name,$new_name))->execute();
+ default:
+ return false;
+ }
+ }
+
+ /**
+ *
+ * Add a foreign key
+ *
+ * @param string $name
+ * @param string $reference
+ * @param string $column
+ * @param string $on
+ * @param string $do
+ *
* @return bool
+ *
+ * @throws Kedavra
+ *
*/
- public function drop_foreign(string ...$names): bool
+ public function add_foreign_key(string $name,string $reference,string $column,string $on,string $do): bool
{
+ $table = static::$table;
+ switch ($this->driver())
+ {
+ case MYSQL:
+ case POSTGRESQL:
+ return $this->connexion()->set(sprintf('ALTER TABLE %s ADD FOREIGN KEY (%s) REFERENCES %s(%s) ON %s %s;',$table,$name,$reference,$column,$on,$do))->execute();
+ default:
+ return false;
+ }
}
@@ -221,26 +320,25 @@ namespace Eywa\Database\Migration {
private function primary(string $column): Migration
{
static::$current_column = $column;
-
+ $size = 0;
switch ($this->driver())
{
case MYSQL:
$type = 'INT';
$constraints = ['PRIMARY KEY NOT NULL AUTO_INCREMENT'];
+ static::$columns->push(compact('column', 'type','size','constraints'));
break;
case POSTGRESQL:
$type = 'SERIAL';
$constraints = ['PRIMARY KEY'];
+ static::$columns->push(compact('column', 'type','size','constraints'));
break;
case SQLITE:
$type = 'INTEGER';
$constraints = ['PRIMARY KEY AUTOINCREMENT'];
+ static::$columns->push(compact('column', 'type','size','constraints'));
break;
}
- $size = 0;
-
- static::$columns->push(compact('column', 'type','size','constraints'));
-
return $this;
}
@@ -422,12 +520,12 @@ namespace Eywa\Database\Migration {
/**
*
- * @return array
+ * @return array<string>
*
* @throws Kedavra
*
*/
- public function columns()
+ public function columns():array
{
return static::$env === 'dev' ? (new Sql(development(),static::$table))->columns() : (new Sql(production(),static::$table))->columns();
}
@@ -442,16 +540,12 @@ namespace Eywa\Database\Migration {
{
case MYSQL:
return 'DATETIME';
- break;
case POSTGRESQL:
return 'TIMESTAMP';
- break;
case SQLITE:
return 'TEXT';
- break;
default:
return '';
- break;
}
}
@@ -466,15 +560,13 @@ namespace Eywa\Database\Migration {
{
case MYSQL:
return 'VARCHAR';
- break;
case POSTGRESQL:
return 'character varying';
- break;
case SQLITE:
- break;
+ return 'text';
default:
return '';
- break;
+
}
}
@@ -488,14 +580,11 @@ namespace Eywa\Database\Migration {
{
case MYSQL:
return 'LONGTEXT';
- break;
case POSTGRESQL:
case SQLITE:
return 'TEXT';
- break;
default:
return '';
- break;
}
}
diff --git a/eywa/Database/Model/Model.php b/eywa/Database/Model/Model.php
index 0106316..ffc6f80 100644..100755
--- a/eywa/Database/Model/Model.php
+++ b/eywa/Database/Model/Model.php
@@ -6,9 +6,12 @@ namespace Eywa\Database\Model {
use Exception;
use Eywa\Collection\Collect;
+ use Eywa\Database\Connexion\Connect;
use Eywa\Database\Connexion\Connexion;
use Eywa\Database\Query\Sql;
use Eywa\Exception\Kedavra;
+ use Eywa\Http\Request\Request;
+ use PDO;
abstract class Model
{
@@ -48,46 +51,161 @@ namespace Eywa\Database\Model {
*/
protected static string $create_todo = "CREATE TABLE IF NOT EXISTS todo ( id INTEGER PRIMARY KEY AUTOINCREMENT , task TEXT(255) NOT NULL UNIQUE , description TEXT(255) NOT NULL , priority TEXT(255) NOT NULL ,due TEXT(255) NOT NULL);";
+
/**
*
- * Web routes
+ * For router web routes
*
*/
protected static bool $web = false;
/**
*
- * Admin routes
+ * The columns
*
*/
- protected static bool $admin = false;
+ private Collect $column;
+
+ /**
+ * Model constructor.
+ */
+ public function __construct()
+ {
+ $this->column = collect();
+ }
/**
*
- * Task routes
+ * Function executed before the validator
+ *
+ * @param Request $request
+ *
+ * @return bool
*
*/
- protected static bool $task = false;
+ abstract public function before_validation(Request $request): bool;
/**
*
- * The project task
+ * Function executed after the validation
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
*/
- protected static bool $todo = false;
+ abstract public function after_validation(Request $request):bool ;
+
/**
*
- * The columns
+ * Function executed before save a new reoord
+ *
+ * @param Request $request
+ *
+ * @return bool
*
*/
- private Collect $column;
+ abstract public function before_save(Request $request): bool;
+
+ /**
+ *
+ * Function executed after data has been saved
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function after_save(Request $request): bool;
+ /**
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function after_commit(Request $request): bool;
+
+ /**
+ *
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function after_rollback(Request $request): bool;
+
+
+ /**
+ *
+ * Function executed executed before update a record
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function before_update(Request $request): bool;
+
+ /**
+ *
+ * Function executed after record has been updated
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function after_update(Request $request):bool;
+
+ /**
+ *
+ * Function executed before create a new record
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function before_create(Request $request): bool;
+
+ /**
+ *
+ * Function executed after create a new record
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function after_create(Request $request): bool;
+
+ /**
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function before_destroy(Request $request): bool;
+
+ /**
+ *
+ * @param Request $request
+ *
+ * @return bool
+ *
+ */
+ abstract public function after_destroy(Request $request): bool;
/**
*
* Display all columns
*
- * @return array
+ * @return array<string>
*
* @throws Kedavra
*
@@ -97,7 +215,6 @@ namespace Eywa\Database\Model {
return static::sql()->from(static::$table)->columns();
}
-
/**
*
* Generate a between clause
@@ -123,11 +240,12 @@ namespace Eywa\Database\Model {
* Get all records
*
* @param int $pdo_style
- * @return array
+ *
+ * @return array<mixed>
*
* @throws Kedavra
*/
- public static function all(int $pdo_style = \PDO::FETCH_OBJ) : array
+ public static function all(int $pdo_style = PDO::FETCH_OBJ) : array
{
return static::sql()->execute($pdo_style);
}
@@ -136,7 +254,7 @@ namespace Eywa\Database\Model {
*
* Create multiples records
*
- * @param array $records
+ * @param array<mixed> $records
*
* @return bool
*
@@ -200,7 +318,7 @@ namespace Eywa\Database\Model {
*
* @param mixed $expected
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*
@@ -219,7 +337,7 @@ namespace Eywa\Database\Model {
* @param string $column
* @param mixed $expected
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*
@@ -233,7 +351,7 @@ namespace Eywa\Database\Model {
*
* Get only column values
*
- * @param $columns
+ * @param array<int,string> $columns
*
* @return Sql
*
@@ -251,7 +369,7 @@ namespace Eywa\Database\Model {
*
* @param string $x
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*
@@ -328,24 +446,17 @@ namespace Eywa\Database\Model {
/**
*
* @param string $name
- * @param $value
+ * @param mixed $value
*
* @throws Kedavra
*
*/
- public function __set(string $name, $value)
+ public function __set(string $name, $value): void
{
$this->column->put($name, static::connection()->secure($value));
}
- /**
- * Model constructor.
- */
- public function __construct()
- {
- $this->column = collect();
- }
/**
@@ -353,7 +464,7 @@ namespace Eywa\Database\Model {
* Update a record
*
* @param int $id
- * @param array $values
+ * @param array<mixed> $values
*
* @return bool
*
@@ -394,7 +505,7 @@ namespace Eywa\Database\Model {
* @throws Kedavra
*
*/
- public static function paginate($callable, int $current_page) : Sql
+ public static function paginate(callable $callable, int $current_page) : Sql
{
return static::sql()->paginate($callable, $current_page, static::$limit);
}
@@ -452,15 +563,15 @@ namespace Eywa\Database\Model {
* Find a record by an id
*
* @param int $id
+ * @param int $pdo_fetch_mode
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
- *
*/
- public static function find(int $id): array
+ public static function find(int $id,int $pdo_fetch_mode = PDO::FETCH_OBJ): array
{
- return static::where(static::primary(),EQUAL,$id)->execute();
+ return static::where(static::primary(),EQUAL,$id)->execute($pdo_fetch_mode);
}
/**
@@ -497,23 +608,19 @@ namespace Eywa\Database\Model {
/**
- * @return Connexion
+ *
+ * @return Connect
+ *
* @throws Kedavra
*
* @throws Exception
+ *
*/
- public static function connection(): Connexion
+ public static function connection(): Connect
{
- if (static::$admin)
- return connect(SQLITE, base('routes','admin.sqlite3'));
-
- if (static::$task)
- return connect(SQLITE, base('routes','task.sqlite3'));
- if (static::$todo)
- return connect(SQLITE, base('todo','todo.sqlite3'));
if (static::$web)
- return connect(SQLITE, base('routes','web.sqlite3') );
+ return connect(SQLITE, base('routes','web.sqlite3'));
return app()->connexion();
}
diff --git a/eywa/Database/Query/Sql.php b/eywa/Database/Query/Sql.php
index 7b63309..0c1c74b 100644..100755
--- a/eywa/Database/Query/Sql.php
+++ b/eywa/Database/Query/Sql.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Eywa\Database\Query {
+ use Eywa\Database\Connexion\Connect;
use Eywa\Database\Connexion\Connexion;
use Eywa\Exception\Kedavra;
use Eywa\Html\Pagination\Pagination;
@@ -48,7 +49,7 @@ namespace Eywa\Database\Query {
* The connection to the base
*
*/
- private Connexion $connexion;
+ private Connect $connexion;
/**
*
@@ -104,7 +105,7 @@ namespace Eywa\Database\Query {
* The where expected value
*
*/
- private $where_expected = null;
+ private string $where_expected = '';
/**
*
@@ -182,13 +183,12 @@ namespace Eywa\Database\Query {
*
* The constructor
*
- * @method __construct
*
- * @param Connexion $connect
+ * @param Connect $connect
* @param string $table
*
*/
- public function __construct(Connexion $connect,string $table)
+ public function __construct(Connect $connect,string $table)
{
$this->connexion = $connect;
$this->from($table);
@@ -209,17 +209,23 @@ namespace Eywa\Database\Query {
}
/**
- * @param array $records
+ *
+ * Create a new record
+ *
+ * @param array<mixed> $records
+ *
* @return bool
+ *
* @throws Kedavra
+ *
*/
public function save(array $records): bool
{
- $x = collect(collect($this->columns())->del($this->primary())->all())->join();
+ $x = collect(collect($this->columns())->del([$this->primary()])->all())->join();
$sql = "INSERT INTO {$this->table} ($x) VALUES( ";
- foreach ($this->columns() as $column)
+ foreach ($this->columns() as $column) // modify it
{
if (array_key_exists($column,$records))
append($sql,$this->connexion()->secure($records[$column]),',');
@@ -233,12 +239,13 @@ namespace Eywa\Database\Query {
return $this->connexion()->set($sql)->execute();
}
+
/**
*
* Get once result
*
* @param int $offset
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*/
@@ -250,10 +257,10 @@ namespace Eywa\Database\Query {
/**
*
*
- * @return Connexion
+ * @return Connect
*
*/
- public function connexion() : Connexion
+ public function connexion() : Connect
{
return $this->connexion;
}
@@ -262,7 +269,7 @@ namespace Eywa\Database\Query {
*
* List all columns inside the table
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*/
@@ -274,17 +281,15 @@ namespace Eywa\Database\Query {
{
case MYSQL:
return $this->connexion()->set("SHOW FULL COLUMNS FROM {$this->table}")->get(COLUMNS);
- break;
case POSTGRESQL:
return $this->connexion()->set("SELECT column_name FROM information_schema.columns WHERE table_name ='{$this->table}'")->get(COLUMNS);
- break;
case SQLITE:
$x = function ($x){return $x->name ;};
return collect($this->connexion()->set("PRAGMA table_info({$this->table})")->get(OBJECTS))->for($x)->all();
- break;
+ default:
+ return $fields->all();
}
- return $fields->all();
}
@@ -307,19 +312,29 @@ namespace Eywa\Database\Query {
return $this;
}
- public function nullable(string $column)
+
+
+ /**
+ *
+ * Check if a column can be null
+ *
+ * @param string $column
+ *
+ * @return bool
+ *
+ * @throws Kedavra
+ *
+ */
+ public function nullable(string $column): bool
{
switch ($this->connexion->driver())
{
case MYSQL:
- return $this->connexion->set("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$this->table}' AND COLUMN_NAME = '$column' LIMIT 1;")->get(PDO::FETCH_COLUMN) === 'YES';
- break;
+ return $this->connexion->set("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$this->table}' AND COLUMN_NAME = '$column' LIMIT 1;")->get(PDO::FETCH_COLUMN)[0] === 'YES';
case POSTGRESQL:
- return $this->connexion->set("select is_nullable from information_schema.columns where table_name = '{$this->table}' and column_name = '$column' ")->get(PDO::FETCH_COLUMN) === 'YES';
- break;
+ return $this->connexion->set("select is_nullable from information_schema.columns where table_name = '{$this->table}' and column_name = '$column' ")->get(PDO::FETCH_COLUMN)[0] === 'YES';
default:
return false;
- break;
}
}
@@ -338,18 +353,19 @@ namespace Eywa\Database\Query {
{
case MYSQL:
return collect($this->connexion()->set("show columns from {$this->table} where `Key` = 'PRI';")->get(COLUMNS))->first();
- break;
case POSTGRESQL:
return 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();
- break;
case SQLITE:
foreach($this->connexion()->set("PRAGMA table_info({$this->table})")->get(OBJECTS) as $value)
- if ($value->pk)
- return $value->name;
- break;
+ {
+ if ($value->pk)
+ return $value->name;
+
+ }
+ break;
case SQL_SERVER:
return collect($this->connexion()->set("SELECT COLUMN_NAME , CONSTRAINT_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE WHERE TABLE_NAME = '{$this->table}';")->get(COLUMNS))->first();
- break;
+
}
throw new Kedavra('We have not found a primary key');
}
@@ -357,18 +373,38 @@ namespace Eywa\Database\Query {
/**
*
+ * Find a record
+ *
* @param int $id
+ * @param int $pdo_fetch_mode
*
+ * @return array<mixed>
*
+ * @throws Kedavra
*
- * @return array|object
+ */
+ public function find(int $id,int $pdo_fetch_mode= PDO::FETCH_OBJ): array
+ {
+ return $this->where($this->primary(), EQUAL, $id)->execute($pdo_fetch_mode);
+ }
+
+ /**
*
- * @throws Kedavra
+ * Throw excecption if not found
*
+ * @param int $id
+ * @param int $pdo_fetch_mode
+ *
+ * @return array<mixed>
+ *
+ * @throws Kedavra
*/
- public function find(int $id)
+ public function find_or_fail(int $id,int $pdo_fetch_mode = PDO::FETCH_OBJ): array
{
- return $this->where($this->primary(), EQUAL, $id)->execute();
+ $x = $this->find($id,$pdo_fetch_mode);
+ is_false(def($x),true,'The record has not been found');
+
+ return $x;
}
/**
@@ -376,7 +412,7 @@ namespace Eywa\Database\Query {
* Get values was different of expected
*
* @param string $column
- * @param $expected
+ * @param mixed $expected
*
* @throws Kedavra
*
@@ -406,10 +442,10 @@ namespace Eywa\Database\Query {
*
* Destroy a record by id
*
- *
* @return bool
*
* @throws Kedavra
+ *
*/
public function destroy() : bool
{
@@ -417,16 +453,13 @@ namespace Eywa\Database\Query {
$result = collect();
-
foreach ($this->execute() as $value)
{
$x = $value->$id;
-
$result->push(static::connexion()->set("DELETE {$this->from} WHERE {$this->primary()} = $x")->execute());
}
-
return $result->ok();
}
@@ -453,18 +486,23 @@ namespace Eywa\Database\Query {
$or = def($this->or) ? $this->or : '';
$and = def($this->and) ? $this->and : '';
+ $delete = def($this->delete) ? $this->delete : '';
$columns = def($this->columns) ? $this->columns : "*";
- return ((def($this->union) ? "$union $where $and $or $order $limit" : def($this->join)) ? "$join $and $or $order $limit" : def($this->delete)) ? $this->delete : "SELECT $columns {$this->from} $where $and $or $order $limit ";
+ if (def($union))
+ return "$union $where $and $or $order $limit";
+ elseif (def($join))
+ return "$join $and $or $order $limit";
+ elseif(def($delete))
+ return "$delete";
+ return "SELECT $columns {$this->from} $where $and $or $order $limit ";
}
/**
*
* Generate a where clause
*
- * @method where
- *
* @param string $column The column name
* @param string $condition The condition
* @param mixed $expected The expected value
@@ -510,7 +548,7 @@ namespace Eywa\Database\Query {
*
* Select only column
*
- * @param string ...$columns
+ * @param array<mixed> $columns
*
* @return Sql
*
@@ -526,8 +564,6 @@ namespace Eywa\Database\Query {
*
* Generate a between clause
*
- * @method between
- *
* @param string $column The column name
* @param mixed $begin The begin value
* @param mixed $last The last value
@@ -553,8 +589,6 @@ namespace Eywa\Database\Query {
*
* Generate an order by clause
*
- * @method by
- *
* @param string $column The column name
* @param string $order The order by option
*
@@ -580,8 +614,11 @@ namespace Eywa\Database\Query {
*
*
* @param int $pdo_mode
- * @return array
+ *
+ * @return array<mixed>
+ *
* @throws Kedavra
+ *
*/
public function execute(int $pdo_mode = PDO::FETCH_OBJ): array
{
@@ -593,22 +630,20 @@ namespace Eywa\Database\Query {
*
* Generate a join clause
*
- * @method join
- *
* @param string $type
* @param string $condition
* @param string $first_table The first table name
* @param string $second_table The second table name
* @param string $first_param The first parameter
* @param string $second_param The second parameter
- * @param string ...$columns
+ * @param array<string> $columns
*
* @return Sql
*
* @throws Kedavra
*
*/
- public function join(string $type,string $condition, string $first_table, string $second_table, string $first_param, string $second_param, string ...$columns) : Sql
+ public function join(string $type,string $condition, string $first_table, string $second_table, string $first_param, string $second_param, array $columns) : Sql
{
not_in([LEFT_JOIN,RIGHT_JOIN,CROSS_JOIN,NATURAL_JOIN,INNER_JOIN,FULL_JOIN],$type,true,"The type is invalid");
@@ -640,8 +675,6 @@ namespace Eywa\Database\Query {
*
* Generate an union clause
*
- * @method union
- *
* @param string $type
* @param string $first_table The first table name
* @param string $second_table The second table name
@@ -666,8 +699,6 @@ namespace Eywa\Database\Query {
*
* Generate a like clause
*
- * @method like
- *
* @param string $value [description]
*
* @throws Kedavra
@@ -677,7 +708,6 @@ namespace Eywa\Database\Query {
*/
public function like(string $value) : Sql
{
-
if($this->connexion()->mysql() || $this->connexion()->postgresql())
{
$columns = collect($this->columns())->join();
@@ -716,6 +746,7 @@ namespace Eywa\Database\Query {
* @return Sql
*
* @throws Kedavra
+ *
*/
public function and(string $column, string $condition, string $expected) : Sql
{
@@ -730,11 +761,12 @@ namespace Eywa\Database\Query {
*
* @param string $column
* @param string $condition
- * @param $expected
- *
+ * @param mixed $expected
*
* @return Sql
+ *
* @throws Kedavra
+ *
*/
public function or(string $column, string $condition, $expected) : Sql
{
@@ -750,15 +782,14 @@ namespace Eywa\Database\Query {
*
*
* @param string $column
- * @param mixed ...$values
- *
+ * @param array<mixed> $values
*
* @return Sql
*
- *
* @throws Kedavra
+ *
*/
- public function not(string $column, ...$values) : Sql
+ public function not(string $column, array $values) : Sql
{
$symbol = html_entity_decode(DIFFERENT);
@@ -785,7 +816,7 @@ namespace Eywa\Database\Query {
}
/**
- * @param $callable
+ * @param callable $callable
* @param int $page
* @param int $limit
*
@@ -794,7 +825,7 @@ namespace Eywa\Database\Query {
* @return Sql
*
*/
- public function paginate($callable, int $page, int $limit) : Sql
+ public function paginate(callable $callable, int $page, int $limit) : Sql
{
$this->pagination = (new Pagination($page, $limit, $this->sum()))->paginate();
@@ -812,7 +843,7 @@ namespace Eywa\Database\Query {
*/
public function pagination(): string
{
- return $this->pagination;
+ return def($this->pagination) ? strval($this->pagination) : '';
}
/**
*
@@ -823,12 +854,12 @@ namespace Eywa\Database\Query {
*/
public function content(): string
{
- return $this->content;
+ return def($this->content) ? strval($this->content) :'';
}
/**
*
- *
+ * Select the table
*
* @param string $table
*
@@ -837,7 +868,6 @@ namespace Eywa\Database\Query {
*/
public function from(string $table) : Sql
{
-
$this->from = "FROM $table";
$this->table = $table;
diff --git a/eywa/Database/Seed/Seeder.php b/eywa/Database/Seed/Seeder.php
index d99a4be..72042e1 100644..100755
--- a/eywa/Database/Seed/Seeder.php
+++ b/eywa/Database/Seed/Seeder.php
@@ -98,7 +98,7 @@ namespace Eywa\Database\Seed {
* Set a column value
*
* @param string $column
- * @param $value
+ * @param mixed $value
*
* @return Seeder
*
@@ -146,7 +146,7 @@ namespace Eywa\Database\Seed {
for ($i=0;$i<static::$generate;$i++)
{
- static::each(static::$faker,static::$table,new static());
+ static::each(static::$faker,static::$table,$this);
$tmp = collect();
diff --git a/eywa/Database/Seed/Seeding.php b/eywa/Database/Seed/Seeding.php
index d3bcbc5..8048f15 100644..100755
--- a/eywa/Database/Seed/Seeding.php
+++ b/eywa/Database/Seed/Seeding.php
@@ -5,24 +5,24 @@ declare(strict_types=1);
namespace Eywa\Database\Seed {
- use Symfony\Component\Console\Input\Input;
- use Symfony\Component\Console\Output\Output;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class Seeding
{
-
/**
*
* List all migrations class sorted by generated date
*
- * @return array
+ * @return array<string>
+ *
*/
- public static function list():array
+ public static function list(): array
{
$x = [];
- foreach (glob(base('db','Seeds','*.php')) as $seed)
+ foreach (files(base('db','Seeds','*.php')) as $seed)
{
$item = collect(explode(DIRECTORY_SEPARATOR,$seed))->last();
@@ -41,12 +41,15 @@ namespace Eywa\Database\Seed {
*
* Run the seeding
*
- * @param Input|null $input
- * @param Output|null $output
+ * @param InputInterface $input
+ * @param OutputInterface $output
*
* @return bool
+ *
+ * @throws \ReflectionException
+ *
*/
- public static function run(?Input $input = null,?Output $output = null): bool
+ public static function run(InputInterface $input,OutputInterface $output): bool
{
$bool = collect();
@@ -54,27 +57,29 @@ namespace Eywa\Database\Seed {
foreach (self::list() as $file => $class)
{
- if (!is_null($output))
- {
- $title = str_replace('%s',$class::$from,$class::$title);
+
+ $x = new \ReflectionClass(new $class);
+
+ $title = str_replace('%s',$x->getStaticPropertyValue('from'),$x->getStaticPropertyValue('title'));
$io->title($title);
- }
- $i = new $class;
- $bool->push(call_user_func_array([$i,'seed'],[]));
- if ($bool->ok() && ! is_null($output))
+ $bool->push($x->getMethod('seed')->getClosure($x->newInstance()));
+
+
+ if ($bool->ok())
{
- $success_message = $class::$success_message;
- $success_message = str_replace('%s',$class::$from,$success_message);
- $success_message = str_replace('%d',$class::$generate,$success_message);
+ $success_message = $x->getStaticPropertyValue('success_message');
+ $success_message = str_replace('%s',$x->getStaticPropertyValue('from'),$success_message);
+ $success_message = str_replace('%d',$x->getStaticPropertyValue('generate'),$success_message);
$io->success($success_message);
}else{
- $error_message = $class::$error_message;
- $error_message = str_replace('%s',$class::$from,$error_message);
- $error_message = str_replace('%d',$class::$generate,$error_message);
+ $error_message = $x->getStaticPropertyValue('error_message');
+ $error_message = str_replace('%s',$x->getStaticPropertyValue('from'),$error_message);
+ $error_message = str_replace('%d',$x->getStaticPropertyValue('generate'),$error_message);
+
$io->error($error_message);
return false;
}
diff --git a/eywa/Database/Table/Table.php b/eywa/Database/Table/Table.php
index bde4a63..bf516d6 100644..100755
--- a/eywa/Database/Table/Table.php
+++ b/eywa/Database/Table/Table.php
@@ -6,7 +6,6 @@ namespace Eywa\Database\Table {
use Eywa\Database\Connexion\Connect;
use Eywa\Exception\Kedavra;
- use wapmorgan\FileTypeDetector\Detector;
class Table
@@ -16,7 +15,7 @@ namespace Eywa\Database\Table {
* The table name
*
*/
- private ?string $table = null;
+ private string $table = '';
/**
*
@@ -30,12 +29,14 @@ namespace Eywa\Database\Table {
* The primary key of the table
*
*/
- private ?string $primary = null;
+ private string $primary = '';
/**
*
* The table columns
*
+ * @var array<string>
+ *
*/
private array $columns = [];
@@ -50,9 +51,7 @@ namespace Eywa\Database\Table {
*/
public function __construct(Connect $connect)
{
-
$this->connexion = $connect;
-
}
/**
@@ -127,6 +126,7 @@ namespace Eywa\Database\Table {
*
* @return string
*
+ * @throws Kedavra
*
*/
public function quote(string $x): string
@@ -138,14 +138,14 @@ namespace Eywa\Database\Table {
*
* Check if a column exist
*
- * @param string[] $columns
+ * @param array<string> $columns
*
* @return bool
*
* @throws Kedavra
*
*/
- public function has(string ...$columns): bool
+ public function has(array $columns): bool
{
$boolean = collect();
foreach ($columns as $column)
@@ -176,23 +176,21 @@ namespace Eywa\Database\Table {
assign($data, $this->table, $new_name);
return $data;
- break;
case POSTGRESQL :
case SQLITE :
$data = $this->connexion->set("ALTER TABLE {$this->table} RENAME TO ?")->with(compact('new_name'))->execute();
assign($data, $this->table, $new_name);
-
return $data;
- break;
case SQL_SERVER :
$data = $this->connexion->set("EXEC sp_rename '{$this->table}', '?'")->with(compact('new_name'))->execute();
assign($data, $this->table, $new_name);
return $data;
- break;
+ default:
+ return false;
}
- return false;
+
}
@@ -200,7 +198,7 @@ namespace Eywa\Database\Table {
*
* Display all tables
*
- * @return array
+ * @return array<mixed>
*
* @throws Kedavra
*/
@@ -209,21 +207,16 @@ namespace Eywa\Database\Table {
switch ($this->connexion->driver())
{
case MYSQL :
-
return $this->connexion->set('SHOW TABLES')->get(\PDO::FETCH_COLUMN);
-
- break;
case POSTGRESQL :
return $this->connexion->set("SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');")->get(COLUMNS);
- break;
case SQLITE :
return $this->connexion->set("SELECT tbl_name FROM sqlite_master")->get(COLUMNS);
- break;
case SQL_SERVER:
return $this->connexion->set("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'")->get(COLUMNS);
- break;
+ default:
+ return [];
}
- return [];
}
/**
@@ -239,7 +232,7 @@ namespace Eywa\Database\Table {
{
$this->check();
- return $this->exist($this->table) ? $this->connexion->set("DROP TABLE {$this->table}")->execute() : false;
+ return $this->connexion->set("DROP TABLE IF EXISTS {$this->table}")->execute();
}
/**
@@ -259,16 +252,12 @@ namespace Eywa\Database\Table {
{
case MYSQL :
return $this->connexion->set("TRUNCATE TABLE {$this->table}")->execute();
- break;
case POSTGRESQL :
return $this->connexion->set("TRUNCATE TABLE {$this->table} RESTART IDENTITY")->execute();
- break;
case SQLITE :
- return $this->connexion->set("DELETE FROM {$this->table}",'VACUUM')->execute();
- break;
+ return $this->connexion->set("DELETE FROM {$this->table}")->set('VACUUM')->execute();
default:
return false;
- break;
}
}
@@ -276,7 +265,7 @@ namespace Eywa\Database\Table {
*
* Get all columns inside the table
*
- * @return array
+ * @return array<string>
*
* @throws Kedavra
*
@@ -313,7 +302,7 @@ namespace Eywa\Database\Table {
break;
default:
return [];
- break;
+
}
return $this->columns;
}
@@ -334,6 +323,7 @@ namespace Eywa\Database\Table {
if (def($this->primary))
return $this->primary;
+
switch ($this->connexion->driver())
{
case MYSQL:
@@ -349,11 +339,10 @@ namespace Eywa\Database\Table {
break;
case SQL_SERVER:
- return collect($this->connexion->set("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME ='{$this->table}' AND CONSTRAINT_NAME LIKE 'PK%'")->get(COLUMNS))->first();
+ $this->primary = collect($this->connexion->set("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME ='{$this->table}' AND CONSTRAINT_NAME LIKE 'PK%'")->get(COLUMNS))->first();
break;
default:
return '';
- break;
}
return $this->primary;
}
@@ -361,7 +350,7 @@ namespace Eywa\Database\Table {
/**
* @throws Kedavra
*/
- private function check()
+ private function check():void
{
is_true(not_def($this->table),true,"Select a table");
}
diff --git a/eywa/Database/User/User.php b/eywa/Database/User/User.php
index 75406b5..fd8c65b 100644..100755
--- a/eywa/Database/User/User.php
+++ b/eywa/Database/User/User.php
@@ -5,7 +5,7 @@ namespace Eywa\Database\User {
use Eywa\Collection\Collect;
- use Eywa\Database\Connexion\Connexion;
+ use Eywa\Database\Connexion\Connect;
use Eywa\Exception\Kedavra;
class User
@@ -16,9 +16,9 @@ namespace Eywa\Database\User {
* The connection to the base
*
*/
- private Connexion $connexion;
+ private Connect $connexion;
- public function __construct(Connexion $connexion)
+ public function __construct(Connect $connexion)
{
$this->connexion = $connexion;
}
@@ -38,13 +38,10 @@ namespace Eywa\Database\User {
{
case MYSQL:
return collect($this->connexion->set('SELECT User from mysql.user')->get(COLUMNS));
- break;
case POSTGRESQL:
return collect($this->connexion->set('SELECT rolname FROM pg_roles;')->get(COLUMNS));
- break;
default:
return collect();
- break;
}
}
}
diff --git a/eywa/Debug/Dumper.php b/eywa/Debug/Dumper.php
index 7a15cff..7a15cff 100644..100755
--- a/eywa/Debug/Dumper.php
+++ b/eywa/Debug/Dumper.php
diff --git a/eywa/Debug/HtmlDumper.php b/eywa/Debug/HtmlDumper.php
index be2056d..167b265 100644..100755
--- a/eywa/Debug/HtmlDumper.php
+++ b/eywa/Debug/HtmlDumper.php
@@ -6,6 +6,9 @@ namespace Eywa\Debug {
class HtmlDumper extends \Symfony\Component\VarDumper\Dumper\HtmlDumper
{
+ /**
+ * @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', ], ];
diff --git a/eywa/Detection/Detect.php b/eywa/Detection/Detect.php
index 0caa1f2..0caa1f2 100644..100755
--- a/eywa/Detection/Detect.php
+++ b/eywa/Detection/Detect.php
diff --git a/eywa/Exception/Kedavra.php b/eywa/Exception/Kedavra.php
index eeb26c0..eeb26c0 100644..100755
--- a/eywa/Exception/Kedavra.php
+++ b/eywa/Exception/Kedavra.php
diff --git a/eywa/File/File.php b/eywa/File/File.php
index 17bf405..42b7673 100644..100755
--- a/eywa/File/File.php
+++ b/eywa/File/File.php
@@ -76,12 +76,12 @@ namespace Eywa\File {
*
* Check if a file exist
*
- * @param string[] $files
+ * @param array<string> $files
*
* @return bool
*
*/
- public static function exist(string ...$files): bool
+ public static function exist(array $files): bool
{
$data = collect();
@@ -111,12 +111,12 @@ namespace Eywa\File {
*
* @param string $pattern
*
- * @return array
+ * @return array<string>
*
*/
public static function search(string $pattern): array
{
- return glob($pattern);
+ return files($pattern);
}
/**
@@ -130,22 +130,19 @@ namespace Eywa\File {
*/
public static function delete(string $filename): bool
{
- return self::exist($filename) ? unlink($filename) : false;
+ return self::exist([$filename]) ? unlink($filename) : false;
}
/***
*
- *
- * @param array $data
+ * @param array<mixed> $data
*
* @return bool
*
- * @throws Kedavra
- *
*/
public function to_json(array $data): bool
{
- return is_not_false(file_put_contents($this->absolute_path(), json_encode($data, JSON_FORCE_OBJECT)));
+ return file_put_contents($this->absolute_path(), json_encode($data, JSON_FORCE_OBJECT)) !== false;
}
/**
@@ -159,14 +156,14 @@ namespace Eywa\File {
*/
public static function remove_if_exist(string $filename): bool
{
- return self::exist($filename) ? self::delete($filename) : false;
+ return self::exist([$filename]) ? self::delete($filename) : false;
}
/**
*
* Get all lines
*
- * @return array
+ * @return array<string>
*
*/
public function lines(): array
@@ -278,7 +275,8 @@ namespace Eywa\File {
*/
public function tell(): int
{
- return $this->filename->ftell();
+ $x = $this->filename->ftell();
+ return is_bool($x) ? 1 : $x;
}
/**
@@ -319,7 +317,12 @@ namespace Eywa\File {
*/
public function read(): string
{
- return superior($this->size(), 0) ? $this->instance()->fread($this->size()) : '';
+ if (superior($this->size(),0))
+ {
+ $x = $this->instance()->fread($this->size());
+ return is_bool($x) ? '' : $x;
+ }
+ return '';
}
/**
@@ -593,12 +596,14 @@ namespace Eywa\File {
*
* Gets absolute path to file
*
- * @return false|string
+ * @return string
*
*/
- public function absolute_path()
+ public function absolute_path():string
{
- return $this->instance()->getRealPath();
+ $x = $this->instance()->getRealPath();
+
+ return is_bool($x) ? '' : $x;
}
/**
diff --git a/eywa/Html/Form/Form.php b/eywa/Html/Form/Form.php
index 0fcfb0a..947c619 100644..100755
--- a/eywa/Html/Form/Form.php
+++ b/eywa/Html/Form/Form.php
@@ -7,6 +7,7 @@ namespace Eywa\Html\Form {
use Exception;
use Eywa\Collection\Collect;
use Eywa\Exception\Kedavra;
+ use Eywa\Http\Request\FormRequest;
class Form
{
@@ -26,35 +27,61 @@ namespace Eywa\Html\Form {
private Collect $inputs;
/**
- * @var string
+ *
+ * The form url
+ *
*/
private string $url;
+
/**
- * @var string
+ *
+ * The form method
+ *
*/
private string $method;
+
+ /**
+ *
+ * The form request
+ *
+ */
+ private FormRequest $request;
+
/**
* Form constructor.
*
- * @param string $url
- * @param string $method
- * @param array $options
+ * @param FormRequest $request
*
+ * @throws Kedavra
* @throws Exception
*
*/
- public function __construct(string $url,string $method = POST,array $options = [])
+ public function __construct(FormRequest $request)
{
- $this->form = '<form action="'.$url.'" method="POST" '. collect($options)->each(function ($k,$v){
+ $this->form = '<form action="'.$request->url().'" method="POST" '. collect($request->options())->each(function ($k,$v){
return $k.'='.'"'.$v.'"';
})->join('').'>';
$this->inputs = collect();
- $this->url = $url;
- $this->method = $method;
+ $this->url = $request->url();
+ $this->method = $request->method();
$this->append(csrf_field());
- $this->add('_method','hidden','','',['value'=> $method]);
+
+ $this->add('_method','hidden','','',['value'=> $request->method()]);
+ $this->request = $request;
+ }
+
+ /**
+ *
+ * Get all errors
+ *
+ * @return Collect
+ *
+ */
+ public function errors(): Collect
+ {
+ return $this->request->errors();
}
/**
@@ -65,7 +92,7 @@ namespace Eywa\Html\Form {
* @param string $type
* @param string $label_text
* @param string $help_text
- * @param array $options
+ * @param array<string> $options
*
* @return Form
*
diff --git a/eywa/Html/Pagination/Pagination.php b/eywa/Html/Pagination/Pagination.php
index d09ded1..d09ded1 100644..100755
--- a/eywa/Html/Pagination/Pagination.php
+++ b/eywa/Html/Pagination/Pagination.php
diff --git a/eywa/Http/Controller/Controller.php b/eywa/Http/Controller/Controller.php
index 3cbef45..8a14eb1 100644..100755
--- a/eywa/Http/Controller/Controller.php
+++ b/eywa/Http/Controller/Controller.php
@@ -16,79 +16,6 @@ namespace Eywa\Http\Controller {
*/
abstract class Controller extends App
{
-
- /**
- *
- * Function executed before the validator
- *
- * @param Request $request
- *
- */
- abstract public function before_validation(Request $request);
-
- /**
- *
- * Function executed after the validation
- *
- * @param Request $request
- *
- */
- abstract public function after_validation(Request $request);
-
-
- /**
- *
- * Function executed before save a new reoord
- *
- * @param Request $request
- *
- */
- abstract public function before_save(Request $request);
-
- /**
- *
- * Function executed after data has been saved
- *
- * @param Request $request
- *
- */
- abstract public function after_save(Request $request);
-
- /**
- *
- * @param Request $request
- *
- */
- abstract public function after_commit(Request $request);
-
- /**
- *
- *
- * @param Request $request
- *
- */
- abstract public function after_rollback(Request $request);
-
-
- /**
- *
- * Function executed executed before update a record
- *
- * @param Request $request
- *
- */
- abstract public function before_update(Request $request);
-
- /**
- *
- * Function executed after record has been updated
- *
- * @param Request $request
- *
- */
- abstract public function after_update(Request $request);
-
-
/**
*
* Function executed before an action
@@ -96,7 +23,7 @@ namespace Eywa\Http\Controller {
* @param Request $request
*
*/
- abstract public function before_action(Request $request);
+ abstract public function before_action(Request $request): void;
/**
*
@@ -105,39 +32,6 @@ namespace Eywa\Http\Controller {
* @param Request $request
*
*/
- abstract public function after_action(Request $request);
-
-
- /**
- *
- * Function executed before create a new record
- *
- * @param Request $request
- *
- */
- abstract public function before_create(Request $request);
-
- /**
- *
- * Function executed after create a new record
- *
- * @param Request $request
- *
- */
- abstract public function after_create(Request $request);
-
- /**
- *
- * @param Request $request
- *
- */
- abstract public function before_destroy(Request $request);
-
- /**
- *
- * @param Request $request
- *
- */
- abstract public function after_destroy(Request $request);
+ abstract public function after_action(Request $request):void;
}
} \ No newline at end of file
diff --git a/eywa/Http/Curl/Curl.php b/eywa/Http/Curl/Curl.php
index 86d7b78..86d7b78 100644..100755
--- a/eywa/Http/Curl/Curl.php
+++ b/eywa/Http/Curl/Curl.php
diff --git a/eywa/Http/Middleware/Middleware.php b/eywa/Http/Middleware/Middleware.php
index 43b3acd..43b3acd 100644..100755
--- a/eywa/Http/Middleware/Middleware.php
+++ b/eywa/Http/Middleware/Middleware.php
diff --git a/eywa/Http/Parameter/Bag.php b/eywa/Http/Parameter/Bag.php
index 85180d5..59687e5 100644..100755
--- a/eywa/Http/Parameter/Bag.php
+++ b/eywa/Http/Parameter/Bag.php
@@ -19,7 +19,7 @@ namespace Eywa\Http\Parameter {
*
* Bag constructor.
*
- * @param array $data
+ * @param array<mixed> $data
*
*/
public function __construct(array $data)
@@ -31,7 +31,7 @@ namespace Eywa\Http\Parameter {
*
* Get all results
*
- * @return array
+ * @return array<mixed>
*
*/
public function all(): array
@@ -44,12 +44,13 @@ namespace Eywa\Http\Parameter {
* Get a value by a key
*
* @param string $key
- * @param null $default
+ * @param mixed $default
*
* @return mixed|string|null
*
+ *
*/
- public function get(string $key,$default = null)
+ public function get(string $key,$default = '')
{
return $this->has($key) ? $this->data->get($key) : $default;
}
diff --git a/eywa/Http/Parameter/Uploaded/UploadedFile.php b/eywa/Http/Parameter/Uploaded/UploadedFile.php
index a6007ab..55624ff 100644..100755
--- a/eywa/Http/Parameter/Uploaded/UploadedFile.php
+++ b/eywa/Http/Parameter/Uploaded/UploadedFile.php
@@ -6,37 +6,71 @@ namespace Eywa\Http\Parameter\Uploaded {
use Exception;
use Eywa\Collection\Collect;
+ use Eywa\Exception\Kedavra;
use SplFileInfo;
use wapmorgan\FileTypeDetector\Detector;
class UploadedFile implements UploadedFileInterface
{
+
+
/**
+ * All files uploaded
*
- * All uploaded files
+ * @var array<string>
*/
private array $files;
-
/**
*
+ * All valid files
+ *
*/
private Collect $filename;
+
/**
- * @var Collect
+ *
+ * All valid types
+ *
*/
private Collect $types;
-
+ /**
+ *
+ * All valid file errors
+ *
+ */
private Collect $errors;
+ /**
+ *
+ * All valid files size
+ *
+ */
private Collect $size;
+ /**
+ *
+ * Tempory filename
+ *
+ */
private Collect $temporary;
+
+ /**
+ *
+ * The sum of all uploaded files
+ *
+ */
private int $sum = 0;
/**
- * @inheritDoc
+ *
+ * constructor.
+ *
+ * @param array<mixed> $files
+ *
+ * @throws Kedavra
+ *
*/
public function __construct(array $files = [])
{
@@ -97,11 +131,11 @@ namespace Eywa\Http\Parameter\Uploaded {
/**
* @inheritDoc
*/
- public function move(string ...$dirs): bool
+ public function move(string $path): bool
{
$path = base('web');
- foreach ($dirs as $dir)
+ foreach (explode(DIRECTORY_SEPARATOR,$path) as $dir)
{
append($path,DIRECTORY_SEPARATOR. $dir);
@@ -109,11 +143,10 @@ namespace Eywa\Http\Parameter\Uploaded {
mkdir($path);
}
- is_true(! is_dir($path) ,true,"The directory has been not found");
+ is_false(is_dir($path) ,true,"The directory has been not found");
$result = collect();
-
$countfiles = $this->filename->sum();
// Looping all files
@@ -134,7 +167,7 @@ namespace Eywa\Http\Parameter\Uploaded {
public function valid(): bool
{
foreach ($this->errors() as $error)
- if ($error !== UPLOAD_ERR_OK)
+ if ($error != UPLOAD_ERR_OK)
return false;
diff --git a/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php b/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php
index e2453d3..8037b04 100644..100755
--- a/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php
+++ b/eywa/Http/Parameter/Uploaded/UploadedFileInterface.php
@@ -9,10 +9,13 @@ namespace Eywa\Http\Parameter\Uploaded {
interface UploadedFileInterface
{
+
/**
- * UploadedInterface constructor.
+ * UploadedFileInterface constructor.
+ *
+ * @param array<mixed> $file
*
- * @param array $file
+ * @throws Kedavra
*
*/
public function __construct(array $file = []);
@@ -21,7 +24,7 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* Get all uploaded file
*
- * @return array
+ * @return array<string>
*
*/
public function all(): array;
@@ -30,22 +33,21 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* Move files to dirs
*
- * @param string ...$dirs
+ * @param string $path
*
* @return bool
*
* @throws Kedavra
*
- *
*/
- public function move(string ...$dirs): bool;
+ public function move(string $path): bool;
/**
*
* Get all uploaded filename
*
- * @return array
+ * @return array<string>
*
*/
public function files():array;
@@ -54,7 +56,7 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* Get all uploaded files types
*
- * @return array
+ * @return array<string>
*
*/
public function types():array;
@@ -63,7 +65,7 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* Get all uploaded files size
*
- * @return array
+ * @return array<int>
*
*/
public function size():array;
@@ -72,7 +74,7 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* Get all uploaded files errors
*
- * @return array
+ * @return array<int>
*/
public function errors():array;
@@ -80,7 +82,7 @@ namespace Eywa\Http\Parameter\Uploaded {
*
* Get all uploaded files tmp name
*
- * @return array
+ * @return array<string>
*
*/
public function temporary():array;
diff --git a/eywa/Http/Request/FormRequest.php b/eywa/Http/Request/FormRequest.php
new file mode 100755
index 0000000..1730b78
--- /dev/null
+++ b/eywa/Http/Request/FormRequest.php
@@ -0,0 +1,117 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Eywa\Http\Request {
+
+
+ use Eywa\Collection\Collect;
+ use Eywa\Exception\Kedavra;
+
+
+ class FormRequest
+ {
+ /**
+ *
+ * The form action
+ *
+ */
+ private string $url;
+
+ /**
+ *
+ * The form method
+ *
+ */
+ private string $method;
+
+ /**
+ *
+ * The form tag options
+ *
+ * @var array<string>
+ *
+ */
+ private array $options;
+
+
+ /**
+ *
+ * All form errors
+ *
+ * @var array<string>
+ *
+ */
+ private array $errors;
+
+
+ /**
+ *
+ * FormRequest constructor.
+ *
+ * @param string $url
+ * @param string $method
+ * @param array<string> $errors
+ * @param array<string> $options
+ *
+ * @throws Kedavra
+ *
+ */
+ public function __construct(string $url,string $method,array $errors = [],array $options =[])
+ {
+ $this->url = $url;
+ $this->method = strtoupper($method);
+ $this->options = $options;
+ $this->errors = $errors;
+ not_in(METHOD_SUPPORTED,$this->method,true,sprintf('The %s method is not supported',$this->method));
+ }
+
+ /**
+ *
+ * Get the url
+ *
+ * @return string
+ *
+ */
+ public function url(): string
+ {
+ return $this->url;
+ }
+
+ /**
+ *
+ * Get the url
+ *
+ * @return string
+ *
+ */
+ public function method(): string
+ {
+ return $this->method;
+ }
+
+ /**
+ *
+ * Get the form tag options
+ *
+ * @return array<string>
+ *
+ */
+ public function options(): array
+ {
+ return $this->options;
+ }
+
+ /**
+ *
+ * Get the form errors
+ *
+ * @return Collect
+ *
+ */
+ public function errors(): Collect
+ {
+ return collect($this->options);
+ }
+ }
+} \ No newline at end of file
diff --git a/eywa/Http/Request/Request.php b/eywa/Http/Request/Request.php
index 9087d56..c4115c2 100644..100755
--- a/eywa/Http/Request/Request.php
+++ b/eywa/Http/Request/Request.php
@@ -67,41 +67,37 @@ namespace Eywa\Http\Request {
/**
* Request constructor.
*
- * @param array $request
- * @param array $query
- * @param array $attributes
- * @param array $cookies
- * @param array $files
- * @param array $server
- * @param array $router_args
- * @param null $content
-
- */
- public function __construct(array $request = [], array $query = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], array $router_args = [],$content = null)
- {
- $this->initialize($query, $request, $attributes, $cookies, $files, $server, $router_args,$content);;
- }
-
- /**
+ * @param array<mixed> $request
+ * @param array<mixed> $query
+ * @param array<mixed> $attributes
+ * @param array<mixed> $cookies
+ * @param array<mixed> $files
+ * @param array<mixed> $server
+ * @param array<mixed> $router_args
*
- * The request content
+ * @throws Kedavra
*
*/
- private $content = null;
+ public function __construct(array $request = [], array $query = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], array $router_args = [])
+ {
+ $this->initialize($query, $request, $attributes, $cookies, $files, $server, $router_args);
+ }
/**
*
* Creates a new request with values from PHP's super globals.
*
- * @param array $args
+ * @param array<mixed> $args
*
* @return Request
*
+ * @throws Kedavra
+ *
*/
- public static function generate(array $args = []): Request
+ public static function make(array $args = []): Request
{
- return new static($_POST,$_GET,[],$_COOKIE,$_FILES,$_SERVER,$args);
+ return new self($_POST,$_GET,[],$_COOKIE,$_FILES,$_SERVER,$args);
}
/**
@@ -120,22 +116,14 @@ namespace Eywa\Http\Request {
*
* Check if the request match the validator rules
*
- * @param string<Validator> $validator
+ * @param Validator $validator
*
* @return Response
*
- * @throws Kedavra
- *
*/
- public function validate(string $validator): Response
+ public function validate(Validator $validator): Response
{
- is_false(class_exists($validator),true,"The validator was not found");
-
- is_false(new $validator instanceof Validator,true,"The class was not a validator");
-
- is_false(method_exists($validator,'validate'),true,"The class has not a validate method");
-
- return $validator::validate($this);
+ return call_user_func_array([$validator,'validate'],[$this]);
}
/**
@@ -211,37 +199,60 @@ namespace Eywa\Http\Request {
}
-
- /**
- * @return null
- */
- public function content()
- {
- return $this->content;
- }
-
-
/**
- * @param array $query
- * @param array $request
- * @param array $attributes
- * @param array $cookies
- * @param array $files
- * @param array $server
- * @param array $router_args
- * @param $content
+ * @param array<mixed> $query
+ * @param array<mixed> $request
+ * @param array<mixed> $attributes
+ * @param array<mixed> $cookies
+ * @param array<mixed> $files
+ * @param array<mixed> $server
+ * @param array<mixed> $router_args
*
+ * @throws Kedavra
*/
- private function initialize(array $query, array $request, array $attributes, array $cookies, array $files, array $server, array $router_args, $content)
+ private function initialize(array $query, array $request, array $attributes, array $cookies, array $files, array $server, array $router_args):void
{
$this->query = new Bag($query);
$this->request = new Bag($request);
- $this->attribute = collect($attributes)->for([$this,'secure']);
+ $this->attribute = collect($attributes);
$this->cookie = new Bag($cookies);
$this->file = new UploadedFile($files);
$this->server = new Bag($server);
- $this->content = $content;
$this->args = new Bag($router_args);
}
+
+ /**
+ * @return mixed
+ */
+ public function ip()
+ {
+ if (cli())
+ return LOCALHOST_IP;
+ $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))
+ {
+ 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']))
+ $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']))
+ $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']))
+ $ip = $_SERVER['HTTP_X_REAL_IP'];
+
+ return $ip;
+ }
+
+ public function local():bool
+ {
+ return $this->ip() === LOCALHOST_IP;
+ }
}
} \ No newline at end of file
diff --git a/eywa/Http/Request/ServerRequest.php b/eywa/Http/Request/ServerRequest.php
index 2f564a3..d28c7be 100644..100755
--- a/eywa/Http/Request/ServerRequest.php
+++ b/eywa/Http/Request/ServerRequest.php
@@ -6,6 +6,7 @@ namespace Eywa\Http\Request {
use Eywa\Exception\Kedavra;
use Eywa\Http\Parameter\Bag;
+ use Eywa\Http\Parameter\Uploaded\UploadedFile;
class ServerRequest
{
@@ -49,7 +50,7 @@ namespace Eywa\Http\Request {
if (not_cli())
{
- $this->request = Request::generate();
+ $this->request = Request::make();
$this->method = different($method,GET) ? $this->request->request()->get('_method',POST) : $method;
@@ -74,7 +75,7 @@ namespace Eywa\Http\Request {
*/
public static function generate(): ServerRequest
{
- return new static($_SERVER['REQUEST_URI'],$_SERVER['REQUEST_METHOD']);
+ return new self($_SERVER['REQUEST_URI'],$_SERVER['REQUEST_METHOD']);
}
/***
@@ -137,6 +138,7 @@ namespace Eywa\Http\Request {
return $this->request->server()->get('SERVER_ADDR') === '127.0.0.1';
}
+
/**
*
* $_GET
@@ -177,10 +179,10 @@ namespace Eywa\Http\Request {
*
* $_FILES
*
- * @return Bag
+ * @return UploadedFile
*
*/
- public function file(): Bag
+ public function file(): UploadedFile
{
return $this->request->file();
}
diff --git a/eywa/Http/Response/JsonResponse.php b/eywa/Http/Response/JsonResponse.php
index 1421988..1421988 100644..100755
--- a/eywa/Http/Response/JsonResponse.php
+++ b/eywa/Http/Response/JsonResponse.php
diff --git a/eywa/Http/Response/RedirectResponse.php b/eywa/Http/Response/RedirectResponse.php
index b8340ed..b8340ed 100644..100755
--- a/eywa/Http/Response/RedirectResponse.php
+++ b/eywa/Http/Response/RedirectResponse.php
diff --git a/eywa/Http/Response/Response.php b/eywa/Http/Response/Response.php
index 5cc7f4f..5cc7f4f 100644..100755
--- a/eywa/Http/Response/Response.php
+++ b/eywa/Http/Response/Response.php
diff --git a/eywa/Http/Routing/RouteResult.php b/eywa/Http/Routing/RouteResult.php
index a16e45f..fad58a4 100644..100755
--- a/eywa/Http/Routing/RouteResult.php
+++ b/eywa/Http/Routing/RouteResult.php
@@ -103,44 +103,11 @@ namespace Eywa\Http\Routing {
is_false(method_exists($class, $this->action()), true, "The action {$this->action()} not exist inside the {$this->controller()} controller");
+ cli() ? call_user_func_array([ $instance, 'before_action' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_action' ], [Request::make($this->args())]);
+ cli() ? call_user_func_array([ $instance, 'after_action' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_action' ], [Request::make($this->args())]);
- if (equal($this->method,'POST'))
- {
- cli() ? call_user_func_array([ $instance, 'before_validation' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_validation' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_validation' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_validation' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'before_save' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_save' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'before_create' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_create' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_create' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_create' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_save' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_save' ], [Request::generate($this->args())]);
- }
-
- if (equal($this->method,'PUT'))
- {
- cli() ? call_user_func_array([ $instance, 'before_validation' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_validation' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_validation' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_validation' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'before_save' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_save' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'before_update' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_update' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_update' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_update' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_save' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_save' ], [Request::generate($this->args())]);
-
- }
-
- if (equal($this->method,'DELETE'))
- {
- cli() ? call_user_func_array([ $instance, 'before_destroy' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_destroy' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_destroy' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_destroy' ], [Request::generate($this->args())]);
-
- }
-
- if (equal($this->method,'GET'))
- {
- cli() ? call_user_func_array([ $instance, 'before_action' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'before_action' ], [Request::generate($this->args())]);
- cli() ? call_user_func_array([ $instance, 'after_action' ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, 'after_action' ], [Request::generate($this->args())]);
-
- }
-
- return cli() ? call_user_func_array([ $instance, $this->action() ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, $this->action() ], [Request::generate($this->args())]);
+ return cli() ? call_user_func_array([ $instance, $this->action() ], [new Request([],[],[],[],[],[],$this->args())]) : call_user_func_array([ $instance, $this->action() ], [Request::make($this->args())]);
}
/**
diff --git a/eywa/Http/Routing/Router.php b/eywa/Http/Routing/Router.php
index 4afdccf..4afdccf 100644..100755
--- a/eywa/Http/Routing/Router.php
+++ b/eywa/Http/Routing/Router.php
diff --git a/eywa/Http/Routing/Task.php b/eywa/Http/Routing/Task.php
deleted file mode 100644
index 9f4e6e9..0000000
--- a/eywa/Http/Routing/Task.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-
-namespace Eywa\Http\Routing {
-
- use DI\DependencyException;
- use DI\NotFoundException;
- use Eywa\Database\Model\Model;
- use Eywa\Exception\Kedavra;
-
- class Task extends Model
- {
- protected static string $table = "routes";
-
- protected static bool $task = true;
-
-
- /**
- *
- * Create the base
- *
- * @return bool
- *
- * @throws Kedavra
- * @throws DependencyException
- * @throws NotFoundException
- */
- public static function generate(): bool
- {
- return static::connection()->set(static::$create_route_table_query)->execute();
- }
- }
-} \ No newline at end of file
diff --git a/eywa/Http/Routing/Web.php b/eywa/Http/Routing/Web.php
index 76a96b1..a670c6f 100644..100755
--- a/eywa/Http/Routing/Web.php
+++ b/eywa/Http/Routing/Web.php
@@ -7,6 +7,7 @@ namespace Eywa\Http\Routing {
use Eywa\Database\Model\Model;
use Eywa\Exception\Kedavra;
+ use Eywa\Http\Request\Request;
class Web extends Model
{
@@ -28,6 +29,112 @@ namespace Eywa\Http\Routing {
return static::connection()->set(static::$create_route_table_query)->execute();
}
+ /**
+ * @param $search
+ * @param int $pdo_mode
+ * @return array
+ * @throws Kedavra
+ */
+ public static function like($search,int $pdo_mode = \PDO::FETCH_OBJ)
+ {
+ return static::sql()->like($search)->execute($pdo_mode);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_validation(Request $request): bool
+ {
+ // TODO: Implement before_validation() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_validation(Request $request): bool
+ {
+ // TODO: Implement after_validation() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_save(Request $request): bool
+ {
+ // TODO: Implement before_save() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_save(Request $request): bool
+ {
+ // TODO: Implement after_save() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_commit(Request $request): bool
+ {
+ // TODO: Implement after_commit() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_rollback(Request $request): bool
+ {
+ // TODO: Implement after_rollback() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_update(Request $request): bool
+ {
+ // TODO: Implement before_update() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_update(Request $request): bool
+ {
+ // TODO: Implement after_update() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_create(Request $request): bool
+ {
+ // TODO: Implement before_create() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_create(Request $request): bool
+ {
+ // TODO: Implement after_create() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function before_destroy(Request $request): bool
+ {
+ // TODO: Implement before_destroy() method.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function after_destroy(Request $request): bool
+ {
+ // TODO: Implement after_destroy() method.
+ }
}
} \ No newline at end of file
diff --git a/eywa/Http/View/View.php b/eywa/Http/View/View.php
index 94d8708..94d8708 100644..100755
--- a/eywa/Http/View/View.php
+++ b/eywa/Http/View/View.php
diff --git a/eywa/Ioc/Container.php b/eywa/Ioc/Container.php
index 563866e..8242f7a 100644..100755
--- a/eywa/Ioc/Container.php
+++ b/eywa/Ioc/Container.php
@@ -1,161 +1,17 @@
<?php
-declare(strict_types=1);
namespace Eywa\Ioc {
-
- use DI\ContainerBuilder;
- use DI\Definition\Exception\InvalidDefinition;
- use DI\DependencyException;
- use DI\NotFoundException;
- use Eywa\Application\Environment\Env;
- use Eywa\Database\Connexion\Connect;
- use Eywa\Database\Table\Table;
- use Eywa\Exception\Kedavra;
- use Eywa\Message\Flash\Flash;
-
- class Container
+ /**
+ *
+ * Class Container
+ *
+ * @package Eywa\Ioc
+ *
+ */
+ abstract class Container extends Ioc
{
-
- private static ?\DI\Container $ioc = null;
-
- /**
- * @return Container
- * @throws DependencyException
- * @throws Kedavra
- * @throws NotFoundException
- */
- public static function ioc(): Container
- {
-
-
- if (is_null(static::$ioc))
- {
- $env = new Env();
-
- $c = new ContainerBuilder();
- $c->useAnnotations(true);
- $c->useAutowiring(true);
- $c->addDefinitions(base('ioc','admin.php'),base('ioc','web.php'));
- $c = $c->build();
-
- $c->set('db.driver',$env->get('DB_DRIVER'));
- $c->set('db.name', $env->get('DB_NAME'));
- $c->set('db.username', $env->get('DB_USERNAME'));
- $c->set('db.password',$env->get('DB_PASSWORD'));
- $c->set('db.host',$env->get('DB_HOST'));
- $c->set('db.port',intval($env->get('DB_PORT')));
- $c->set('db.options',[]);
- $c->set('db.dump',base('db','dump'));
- $c->set("views.path",base('app','Views')) ;
- $c->set("flash",new Flash()) ;
- $c->set('faker',faker(config('i18n','locale'))) ;
- $c->set('table',new Table($c->get(Connect::class))) ;
- self::$ioc = $c;
-
- }
- return new static();
- }
-
-
- /**
- *
- * Get the value
- *
- * @param string $key
- * @return mixed
- *
- * @throws DependencyException
- * @throws NotFoundException
- */
- public function get(string $key)
- {
- return self::container()->get($key);
- }
-
-
- /**
- *
- * Check if key is define
- *
- * @param string $key
- * @return bool
- */
- public function has(string $key): bool
- {
- return self::container()->has($key);
- }
-
- /**
- *
- * Set a new value
- *
- * @param string $key
- * @param $value
- *
- * @return Container
- */
- public function set(string $key,$value): Container
- {
- self::container()->set($key,$value);
-
- return $this;
- }
-
- /**
- *
- * Call the callback
- *
- * @param string $key
- * @param string $method
- * @param array $args
- *
- * @return mixed
- */
- public function call(string $key,string $method,array $args =[])
- {
- return self::container()->call([$key,$method],$args);
- }
-
- /**
- *
- * Debug an entry
- *
- * @param string $key
- * @return string
- *
- * @throws InvalidDefinition
- * @throws NotFoundException
- */
- public function debug(string $key)
- {
- return self::container()->debugEntry($key);
- }
-
- /**
- *
- * Build an entry of the container by its name
- *
- * @param string $key
- * @param array $args
- *
- * @return mixed
- *
- * @throws DependencyException
- * @throws NotFoundException
- */
- public function make(string $key,array $args = [])
- {
- return self::container()->make($key,$args);
- }
-
- /**
- * @return \DI\Container|null
- */
- private static function container()
- {
- return self::$ioc;
- }
+ abstract public function build(): Ioc;
}
} \ No newline at end of file
diff --git a/eywa/Ioc/Ioc.php b/eywa/Ioc/Ioc.php
new file mode 100755
index 0000000..9dd271d
--- /dev/null
+++ b/eywa/Ioc/Ioc.php
@@ -0,0 +1,247 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Eywa\Ioc {
+
+
+ use Eywa\Collection\Collect;
+ use Eywa\Database\Connexion\Connect;
+ use Eywa\Exception\Kedavra;
+ use Eywa\Message\Flash\Flash;
+
+ class Ioc
+ {
+
+ /**
+ *
+ * All instances
+ *
+ */
+ private Collect $instances;
+
+ /**
+ * @var Collect
+ */
+ private Collect $variables;
+ /**
+ * @var Collect
+ */
+ private $temp_variables;
+ /**
+ * @var Collect
+ */
+ private $temp_instances;
+
+
+ /**
+ * Ioc constructor.
+ */
+ public function __construct()
+ {
+ $this->instances = collect();
+ $this->variables = collect();
+ $this->temp_instances = collect();
+ $this->temp_variables = collect();
+ }
+
+ /**
+ *
+ * Add instances in the container
+ *
+ * @param string $class
+ * @param callable $callback
+ *
+ * @return Ioc
+ *
+ */
+ public function init(string $class,callable $callback):Ioc
+ {
+ if ($this->instances->has($class))
+ return $this;
+ $this->temp_instances->put($class, call_user_func($callback));
+ $this->instances = $this->instances->merge($this->temp_instances->all());
+ $this->temp_instances->clear();
+
+
+ return $this;
+
+ }
+
+
+
+ /**
+ *
+ * Add variable in the container
+ *
+ * @param string $key
+ * @param mixed $value
+ *
+ * @return Ioc
+ *
+ */
+ public function set(string $key,$value): Ioc
+ {
+ $this->temp_variables->put($key,$value);
+ $this->variables = $this->variables->merge($this->temp_variables->all());
+ $this->temp_variables->clear();
+
+ return $this;
+ }
+
+
+ /**
+ *
+ * Check if a key exist in the container
+ *
+ * @param string $key
+ * @return bool
+ *
+ * @throws Kedavra
+ * @throws \ReflectionException
+ *
+ */
+ public function has(string $key):bool
+ {
+ return $this->container()->instances->has($key) || $this->container()->variables->has($key);
+ }
+ /**
+ *
+ * Get an instance of a class
+ *
+ * @param string $class
+ *
+ * @return object
+ *
+ * @throws Kedavra
+ *
+ * @throws \ReflectionException
+ *
+ *
+ */
+ public function get(string $class): object
+ {
+
+ $instances = collect($this->container()->instances());
+ $variables = collect($this->container()->variables());
+
+ if ($instances->has($class))
+ return $instances->get($class);
+ elseif($variables->has($class))
+ return $variables->get($class);
+
+
+
+ $reflect = new \ReflectionClass($class);
+
+ if (!is_null($reflect->getConstructor()))
+ {
+ if ($reflect->getConstructor()->getNumberOfRequiredParameters() === 0)
+ {
+ $this->instances->put($class, $reflect->newInstance());
+
+ }else
+ {
+ $args = collect();
+
+ foreach ($reflect->getConstructor()->getParameters() as $parameter)
+ {
+ if (!is_null($parameter->getClass()))
+ {
+ $arg = $parameter->getClass()->getName();
+
+ is_false($this->container()->instances->has($arg),true,sprintf('Cannot create an instance for %s class because the %s value has not been found inside the container',$class,$arg));
+
+
+ $args->push($this->container()->instances->get($arg));
+
+ }
+
+ if (is_null($parameter->getClass()))
+ {
+ $arg = $parameter->getName();
+
+ is_false($this->container()->variables->has($arg),true,sprintf('Cannot create an instance for %s class because the %s value has not been found inside the container',$class,$arg));
+
+ $args->push($this->container()->variables->get($arg));
+
+ }
+ }
+ if (def($args->all()))
+ $this->instances->put($class,$reflect->newInstanceArgs($args->all()));
+
+ }
+ }else
+ {
+
+ $this->instances->put($class, $reflect->newInstance());
+ }
+
+ return $this->container()->get($class);
+ }
+
+ /**
+ *
+ * Get the container
+ *
+ * @return Ioc
+ *
+ * @throws Kedavra
+ * @throws \ReflectionException
+ *
+ */
+ private function container(): Ioc
+ {
+ if ($this->instances->empty())
+ {
+ foreach (glob(base('ioc','*.php')) as $container)
+ {
+ $namespace = '\Ioc\\';
+
+ $container = \collect(explode('.',collect(explode(DIRECTORY_SEPARATOR,$container))->last()))->first();
+
+ $x = new \ReflectionClass("$namespace$container");
+
+ $extern_container = call_user_func($x->getMethod('build')->getClosure($x->newInstance()));
+
+ $this->instances->merge(call_user_func([$extern_container,'instances']));
+
+ $this->variables->merge(call_user_func([$extern_container,'variables']));
+
+ }
+
+ $this->init(Connect::class,function (){
+ return equal(config('mode','connexion'),'prod') ? production() : development();
+ });
+ $this->set('faker',faker(strval(config('i18n','locale'))));
+ $this->set('flash',new Flash());
+
+ }
+ return $this;
+ }
+
+ /**
+ *
+ * Get all instances
+ *
+ * @return array
+ *
+ */
+ public function instances(): array
+ {
+ return $this->instances->all();
+ }
+
+ /**
+ *
+ * Get all instances
+ *
+ * @return array
+ *
+ */
+ public function variables(): array
+ {
+ return $this->variables->all();
+ }
+ }
+} \ No newline at end of file
diff --git a/eywa/Message/Email/Write.php b/eywa/Message/Email/Write.php
index 7f67451..7f67451 100644..100755
--- a/eywa/Message/Email/Write.php
+++ b/eywa/Message/Email/Write.php
diff --git a/eywa/Message/Flash/Flash.php b/eywa/Message/Flash/Flash.php
index b51342e..b51342e 100644..100755
--- a/eywa/Message/Flash/Flash.php
+++ b/eywa/Message/Flash/Flash.php
diff --git a/eywa/Security/Authentication/Auth.php b/eywa/Security/Authentication/Auth.php
index 099b896..099b896 100644..100755
--- a/eywa/Security/Authentication/Auth.php
+++ b/eywa/Security/Authentication/Auth.php
diff --git a/eywa/Security/Crypt/Crypter.php b/eywa/Security/Crypt/Crypter.php
index 0cc8b59..0cc8b59 100644..100755
--- a/eywa/Security/Crypt/Crypter.php
+++ b/eywa/Security/Crypt/Crypter.php
diff --git a/eywa/Security/Csrf/Csrf.php b/eywa/Security/Csrf/Csrf.php
index 6f7811f..9369c8e 100644..100755
--- a/eywa/Security/Csrf/Csrf.php
+++ b/eywa/Security/Csrf/Csrf.php
@@ -17,6 +17,12 @@ namespace Eywa\Security\Csrf {
*/
private SessionInterface $session;
+ /**
+ * Csrf constructor.
+ *
+ * @param SessionInterface $session
+ *
+ */
public function __construct(SessionInterface $session)
{
$this->session = $session;
@@ -34,9 +40,9 @@ 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::generate()->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->session->destroy(CSRF_TOKEN);
+ $this->remove_token();
return true;
}
@@ -64,7 +70,7 @@ namespace Eywa\Security\Csrf {
if ($this->session->has(CSRF_TOKEN))
return '<input type="hidden" name="' . CSRF_TOKEN . '" value="' . $this->session->get(CSRF_TOKEN) . '">';
- $server = $this->session->has('server') ? $this->session->get('server') : $this->session->set('server', (new Crypter())->encrypt(Request::generate()->server()->get('SERVER_NAME', 'eywa')))->get('server'); $x = bin2hex(random_bytes(16));
+ $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 07371c1..07371c1 100644..100755
--- a/eywa/Security/Hashing/Hash.php
+++ b/eywa/Security/Hashing/Hash.php
diff --git a/eywa/Security/Middleware/CsrfMiddleware.php b/eywa/Security/Middleware/CsrfMiddleware.php
index 932fcd5..932fcd5 100644..100755
--- a/eywa/Security/Middleware/CsrfMiddleware.php
+++ b/eywa/Security/Middleware/CsrfMiddleware.php
diff --git a/eywa/Session/ArraySession.php b/eywa/Session/ArraySession.php
index a96113a..a96113a 100644..100755
--- a/eywa/Session/ArraySession.php
+++ b/eywa/Session/ArraySession.php
diff --git a/eywa/Session/Session.php b/eywa/Session/Session.php
index 4de1955..4de1955 100644..100755
--- a/eywa/Session/Session.php
+++ b/eywa/Session/Session.php
diff --git a/eywa/Session/SessionInterface.php b/eywa/Session/SessionInterface.php
index fa37c70..fa37c70 100644..100755
--- a/eywa/Session/SessionInterface.php
+++ b/eywa/Session/SessionInterface.php
diff --git a/eywa/Testing/Unit.php b/eywa/Testing/Unit.php
index 6a3793d..6a3793d 100644..100755
--- a/eywa/Testing/Unit.php
+++ b/eywa/Testing/Unit.php
diff --git a/eywa/Time/Timing.php b/eywa/Time/Timing.php
index d165440..d165440 100644..100755
--- a/eywa/Time/Timing.php
+++ b/eywa/Time/Timing.php
diff --git a/eywa/Validate/Validator.php b/eywa/Validate/Validator.php
index 1a50105..7fd9b41 100644..100755
--- a/eywa/Validate/Validator.php
+++ b/eywa/Validate/Validator.php
@@ -150,6 +150,7 @@ namespace Eywa\Validate {
return (new RedirectResponse(static::$redirect_url))->send();
}
+
/**
*
* Get the error message for a key
@@ -158,6 +159,8 @@ namespace Eywa\Validate {
*
* @return string
*
+ * @throws Kedavra
+ *
*/
public static function message(string $key): string
{
diff --git a/grumphp.yml b/grumphp.yml
new file mode 100755
index 0000000..0d6c4fc
--- /dev/null
+++ b/grumphp.yml
@@ -0,0 +1,29 @@
+parameters:
+ tasks:
+ make: ~
+ git_commit_message:
+ allow_empty_message: false
+ enforce_capitalized_subject: true
+ enforce_no_subject_punctuations: false
+ enforce_no_subject_trailing_period: true
+ enforce_single_lined_subject: true
+ max_body_width: 72
+ max_subject_width: 60
+ matchers:
+ Must contain JIRA issue number: /JIRA-\d+/
+ case_insensitive: true
+ multiline: true
+ additional_modifiers: ''
+ type_scope_conventions:
+ - types:
+ - build
+ - ci
+ - chore
+ - docs
+ - feat
+ - fix
+ - perf
+ - refactor
+ - revert
+ - style
+ - test
diff --git a/helpers/admin.php b/helpers/admin.php
index 429ac8d..b650e04 100644..100755
--- a/helpers/admin.php
+++ b/helpers/admin.php
@@ -11,7 +11,7 @@ use Eywa\Debug\Dumper;
use Eywa\Exception\Kedavra;
use Eywa\File\File;
use Eywa\Http\Request\Request;
-use Eywa\Ioc\Container;
+use Eywa\Ioc\Ioc;
use Eywa\Security\Authentication\Auth;
use Eywa\Security\Crypt\Crypter;
use Eywa\Security\Hashing\Hash;
@@ -80,6 +80,20 @@ if (!function_exists('form_invalid'))
}
+if (!function_exists('files'))
+{
+
+ /**
+ * @param string $pattern
+ * @return array
+ */
+ function files(string $pattern):array
+ {
+ $files = glob($pattern);
+
+ return is_bool($files) ? [] : $files;
+ }
+}
if (!function_exists('base'))
{
/**
@@ -229,7 +243,7 @@ if (!function_exists('ioc'))
*/
function ioc(string $key)
{
- return Container::ioc()->get($key);
+ return (new Ioc())->get($key);
}
}
@@ -535,7 +549,6 @@ if (!function_exists('is_true'))
*/
function is_true($data, bool $run_exception = false, string $message = ''): bool
{
-
$x = $data === true;
if ($run_exception && $x)
@@ -846,6 +859,7 @@ if (!function_exists('commands'))
return $commands->all();
}
}
+
if (!function_exists('controllers'))
{
/**
@@ -861,9 +875,9 @@ if (!function_exists('controllers'))
{
if ($directory !== 'Controllers')
- $controllers =glob(base('app', 'Controllers',$directory,'*.php'));
+ $controllers =files(base('app', 'Controllers',$directory,'*.php'));
else
- $controllers = glob(base('app', 'Controllers','*.php'));
+ $controllers = files(base('app', 'Controllers','*.php'));
$data = collect();
if ($controllers)
{
diff --git a/helpers/const.php b/helpers/const.php
index 61fe912..300942c 100644..100755
--- a/helpers/const.php
+++ b/helpers/const.php
@@ -131,6 +131,7 @@ define('VIEW_PHP_CLOSE', '}}');
define('OBJECTS', PDO::FETCH_OBJ);
define('COLUMNS', PDO::FETCH_COLUMN);
+define('ARRAY', PDO::FETCH_ASSOC);
define('HTTP_REDIRECTION', 301);
@@ -465,4 +466,6 @@ define('STATUS', [
]);
-define('CACHE_DEFAULT_TTL',7200); // 120m | 2h | 7200s \ No newline at end of file
+define('CACHE_DEFAULT_TTL',7200); // 120m | 2h | 7200s
+
+define('LOCALHOST_IP','127.0.0.1'); \ No newline at end of file
diff --git a/helpers/web.php b/helpers/web.php
index 93fe224..b261886 100644..100755
--- a/helpers/web.php
+++ b/helpers/web.php
@@ -122,9 +122,10 @@ if (!function_exists('env'))
/**
*
* @param $variable
+ * @param mixed $default
*
- * @param string $default
* @return array|false|string
+ *
* @throws Exception
*/
function env($variable,$default = '')
diff --git a/ioc/Admin.php b/ioc/Admin.php
new file mode 100755
index 0000000..593f65f
--- /dev/null
+++ b/ioc/Admin.php
@@ -0,0 +1,22 @@
+<?php
+
+
+namespace Ioc;
+
+
+use Eywa\Http\Request\Request;
+use Eywa\Http\View\View;
+use Eywa\Ioc\Container;
+use Eywa\Ioc\Ioc;
+
+class Admin extends Container
+{
+
+ public function build(): Ioc
+ {
+ return
+ $this->init(Request::class,function (){
+ return Request::make();
+ })->set('aladin','rice');
+ }
+} \ No newline at end of file
diff --git a/ioc/Web.php b/ioc/Web.php
new file mode 100755
index 0000000..bd92153
--- /dev/null
+++ b/ioc/Web.php
@@ -0,0 +1,25 @@
+<?php
+
+
+namespace Ioc;
+
+
+use Eywa\Html\Form\Form;
+use Eywa\Http\Request\FormRequest;
+use Eywa\Ioc\Container;
+use Eywa\Ioc\Ioc;
+
+class Web extends Container
+{
+
+ /**
+ * @inheritDoc
+ */
+ public function build(): Ioc
+ {
+ return
+ $this->init(Form::class,function (){
+
+ });
+ }
+} \ No newline at end of file
diff --git a/ioc/admin.php b/ioc/admin.php
deleted file mode 100644
index a1b26e6..0000000
--- a/ioc/admin.php
+++ /dev/null
@@ -1,2 +0,0 @@
-<?php
-return []; \ No newline at end of file
diff --git a/ioc/web.php b/ioc/web.php
deleted file mode 100644
index a1b26e6..0000000
--- a/ioc/web.php
+++ /dev/null
@@ -1,2 +0,0 @@
-<?php
-return []; \ No newline at end of file
diff --git a/logs/.gitignore b/logs/.gitignore
index d6b7ef3..d6b7ef3 100644..100755
--- a/logs/.gitignore
+++ b/logs/.gitignore
diff --git a/phpunit-printer.yml b/phpunit-printer.yml
index 5e0d3b9..5e0d3b9 100644..100755
--- a/phpunit-printer.yml
+++ b/phpunit-printer.yml
diff --git a/phpunit.xml b/phpunit.xml
index 5160420..5160420 100644..100755
--- a/phpunit.xml
+++ b/phpunit.xml
diff --git a/po/en_US/LC_MESSAGES/messages.po b/po/en_US/LC_MESSAGES/messages.po
deleted file mode 100644
index 23e7b09..0000000
--- a/po/en_US/LC_MESSAGES/messages.po
+++ /dev/null
@@ -1,22 +0,0 @@
-# English translations for eywa package.
-# Copyright (C) 2020 THE eywa'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the eywa package.
-# Willy Micieli <willy@underworld>, 2020.
-#
-msgid ""
-msgstr ""
-"Project-Id-Version: eywa 1.0\n"
-"Report-Msgid-Bugs-To: micieli@laposte.net\n"
-"POT-Creation-Date: 2020-02-13 17:49+0000\n"
-"PO-Revision-Date: 2020-02-13 17:49+0000\n"
-"Last-Translator: Willy Micieli <willy@underworld>\n"
-"Language-Team: English\n"
-"Language: en_US\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=ASCII\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-
-#: /home/willy/dev/web/eywa/app/Views/home/welcome.php:1
-msgid "welcome"
-msgstr "welcome"
diff --git a/po/eywa.pot b/po/eywa.pot
deleted file mode 100644
index be3ec28..0000000
--- a/po/eywa.pot
+++ /dev/null
@@ -1,22 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the eywa package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: eywa 1.0\n"
-"Report-Msgid-Bugs-To: micieli@laposte.net\n"
-"POT-Creation-Date: 2020-02-13 17:58+0000\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"Language: \n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=CHARSET\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: /home/willy/dev/web/eywa/app/Views/home/welcome.php:1
-msgid "welcome"
-msgstr ""
diff --git a/po/fr_FR/LC_MESSAGES/messages.po b/po/fr_FR/LC_MESSAGES/messages.po
deleted file mode 100644
index 0f1d386..0000000
--- a/po/fr_FR/LC_MESSAGES/messages.po
+++ /dev/null
@@ -1,22 +0,0 @@
-# French translations for eywa package.
-# Copyright (C) 2020 THE eywa'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the eywa package.
-# Willy Micieli <willy@underworld>, 2020.
-#
-msgid ""
-msgstr ""
-"Project-Id-Version: eywa 1.0\n"
-"Report-Msgid-Bugs-To: micieli@laposte.net\n"
-"POT-Creation-Date: 2020-02-13 17:49+0000\n"
-"PO-Revision-Date: 2020-02-13 17:49+0000\n"
-"Last-Translator: Willy Micieli <willy@underworld>\n"
-"Language-Team: French <traduc@traduc.org>\n"
-"Language: fr\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=ASCII\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-
-#: /home/willy/dev/web/eywa/app/Views/home/welcome.php:1
-msgid "welcome"
-msgstr ""
diff --git a/sql/mysql/achats.sql b/sql/mysql/achats.sql
index 36a3398..36a3398 100644..100755
--- a/sql/mysql/achats.sql
+++ b/sql/mysql/achats.sql
diff --git a/sql/mysql/auth.sql b/sql/mysql/auth.sql
index 0fd8c24..0fd8c24 100644..100755
--- a/sql/mysql/auth.sql
+++ b/sql/mysql/auth.sql
diff --git a/sql/mysql/users.sql b/sql/mysql/users.sql
index 8948796..8948796 100644..100755
--- a/sql/mysql/users.sql
+++ b/sql/mysql/users.sql
diff --git a/sql/oracle/achats.sql b/sql/oracle/achats.sql
index ee265f0..ee265f0 100644..100755
--- a/sql/oracle/achats.sql
+++ b/sql/oracle/achats.sql
diff --git a/sql/oracle/users.sql b/sql/oracle/users.sql
index e316a22..e316a22 100644..100755
--- a/sql/oracle/users.sql
+++ b/sql/oracle/users.sql
diff --git a/sql/pgsql/achats.sql b/sql/pgsql/achats.sql
index e8d7a27..e8d7a27 100644..100755
--- a/sql/pgsql/achats.sql
+++ b/sql/pgsql/achats.sql
diff --git a/sql/pgsql/users.sql b/sql/pgsql/users.sql
index 9593db7..9593db7 100644..100755
--- a/sql/pgsql/users.sql
+++ b/sql/pgsql/users.sql
diff --git a/sql/sqlite/achats.sql b/sql/sqlite/achats.sql
index 0a2d4f7..0a2d4f7 100644..100755
--- a/sql/sqlite/achats.sql
+++ b/sql/sqlite/achats.sql
diff --git a/sql/sqlite/users.sql b/sql/sqlite/users.sql
index bb80f72..bb80f72 100644..100755
--- a/sql/sqlite/users.sql
+++ b/sql/sqlite/users.sql
diff --git a/sql/sqlsrv/achats.sql b/sql/sqlsrv/achats.sql
index 71e63eb..71e63eb 100644..100755
--- a/sql/sqlsrv/achats.sql
+++ b/sql/sqlsrv/achats.sql
diff --git a/sql/sqlsrv/users.sql b/sql/sqlsrv/users.sql
index eb187ba..eb187ba 100644..100755
--- a/sql/sqlsrv/users.sql
+++ b/sql/sqlsrv/users.sql
diff --git a/tests/App/ApplicationTest.php b/tests/App/ApplicationTest.php
index 4a1383e..4a1383e 100644..100755
--- a/tests/App/ApplicationTest.php
+++ b/tests/App/ApplicationTest.php
diff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.php
index 5c9abe5..5c9abe5 100644..100755
--- a/tests/Auth/AuthTest.php
+++ b/tests/Auth/AuthTest.php
diff --git a/tests/Cache/ApcuCacheTest.php b/tests/Cache/ApcuCacheTest.php
index 94db716..94db716 100644..100755
--- a/tests/Cache/ApcuCacheTest.php
+++ b/tests/Cache/ApcuCacheTest.php
diff --git a/tests/Cache/MemCacheTest.php b/tests/Cache/MemCacheTest.php
index 84908ed..84908ed 100644..100755
--- a/tests/Cache/MemCacheTest.php
+++ b/tests/Cache/MemCacheTest.php
diff --git a/tests/Cache/RedisCacheTest.php b/tests/Cache/RedisCacheTest.php
index aaf680e..aaf680e 100644..100755
--- a/tests/Cache/RedisCacheTest.php
+++ b/tests/Cache/RedisCacheTest.php
diff --git a/tests/Collection/CollectionTest.php b/tests/Collection/CollectionTest.php
index b11ea1b..b11ea1b 100644..100755
--- a/tests/Collection/CollectionTest.php
+++ b/tests/Collection/CollectionTest.php
diff --git a/tests/Crypt/CryptTest.php b/tests/Crypt/CryptTest.php
index 1106f71..1106f71 100644..100755
--- a/tests/Crypt/CryptTest.php
+++ b/tests/Crypt/CryptTest.php
diff --git a/tests/Database/ConnectTest.php b/tests/Database/ConnectTest.php
index 3743049..3743049 100644..100755
--- a/tests/Database/ConnectTest.php
+++ b/tests/Database/ConnectTest.php
diff --git a/tests/Database/ModelTest.php b/tests/Database/ModelTest.php
index e10d1ca..e10d1ca 100644..100755
--- a/tests/Database/ModelTest.php
+++ b/tests/Database/ModelTest.php
diff --git a/tests/Database/SeedTest.php b/tests/Database/SeedTest.php
index 34328dd..34328dd 100644..100755
--- a/tests/Database/SeedTest.php
+++ b/tests/Database/SeedTest.php
diff --git a/tests/Database/SqlTest.php b/tests/Database/SqlTest.php
index 85dd4c5..85dd4c5 100644..100755
--- a/tests/Database/SqlTest.php
+++ b/tests/Database/SqlTest.php
diff --git a/tests/Database/TableTest.php b/tests/Database/TableTest.php
index c29d351..c29d351 100644..100755
--- a/tests/Database/TableTest.php
+++ b/tests/Database/TableTest.php
diff --git a/tests/File/FileTest.php b/tests/File/FileTest.php
index d042a8d..d042a8d 100644..100755
--- a/tests/File/FileTest.php
+++ b/tests/File/FileTest.php
diff --git a/tests/Form/FormTest.php b/tests/Form/FormTest.php
index a0393d7..a0393d7 100644..100755
--- a/tests/Form/FormTest.php
+++ b/tests/Form/FormTest.php
diff --git a/tests/Helpers/AdminHelperTest.php b/tests/Helpers/AdminHelperTest.php
index b750728..b750728 100644..100755
--- a/tests/Helpers/AdminHelperTest.php
+++ b/tests/Helpers/AdminHelperTest.php
diff --git a/tests/Html/PaginationTest.php b/tests/Html/PaginationTest.php
index 085f3c5..085f3c5 100644..100755
--- a/tests/Html/PaginationTest.php
+++ b/tests/Html/PaginationTest.php
diff --git a/tests/Http/JsonReponseTest.php b/tests/Http/JsonReponseTest.php
index f1486e7..f1486e7 100644..100755
--- a/tests/Http/JsonReponseTest.php
+++ b/tests/Http/JsonReponseTest.php
diff --git a/tests/Http/ReponseTest.php b/tests/Http/ReponseTest.php
index 61bd712..61bd712 100644..100755
--- a/tests/Http/ReponseTest.php
+++ b/tests/Http/ReponseTest.php
diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php
index c681064..442a981 100644..100755
--- a/tests/Http/RequestTest.php
+++ b/tests/Http/RequestTest.php
@@ -4,6 +4,7 @@
namespace Testing\Http {
+ use Eywa\Exception\Kedavra;
use Eywa\Http\Request\Request;
use PHPUnit\Framework\TestCase;
@@ -20,15 +21,21 @@ namespace Testing\Http {
$this->request = new Request();
}
+ /**
+ * @throws Kedavra
+ */
public function test_request()
{
- $this->assertNull($this->request->query()->get('a'));
- $this->assertNull($this->request->request()->get('a'));
- $this->assertEmpty($this->request->attribute()->get('a'));
- $this->assertNull($this->request->cookie()->get('a'));
- $this->assertNull($this->request->server()->get('a'));
- $this->assertEmpty($this->request->file()->files());
- $this->assertEmpty($this->request->content());
+ $this->expectException(Kedavra::class);
+ $this->request->query()->get('a');
+ $this->request->request()->get('a');
+ $this->request->attribute()->get('a');
+ $this->request->cookie()->get('a');
+ $this->request->server()->get('a');
+ }
+ public function test_ip()
+ {
+ $this->assertEquals(LOCALHOST_IP,$this->request->ip());
}
}
} \ No newline at end of file
diff --git a/tests/Ioc/ContainerTest.php b/tests/Ioc/ContainerTest.php
index e3f1e94..a4d572e 100644..100755
--- a/tests/Ioc/ContainerTest.php
+++ b/tests/Ioc/ContainerTest.php
@@ -5,42 +5,56 @@ namespace Testing\Ioc {
use Eywa\Database\Connexion\Connect;
+ use Eywa\Database\Table\Table;
+ use Eywa\Exception\Kedavra;
use Eywa\Http\Routing\Router;
use Eywa\Http\View\View;
- use Eywa\Ioc\Container;
+ use Eywa\Ioc\Ioc;
+ use Eywa\Message\Flash\Flash;
use PHPUnit\Framework\TestCase;
+ use ReflectionException;
class ContainerTest extends TestCase
{
- public function test_has()
- {
- $this->assertTrue(Container::ioc()->has(Connect::class));
- $this->assertTrue(Container::ioc()->has(Router::class));
- }
+ /**
+ * @var Ioc
+ */
+ private Ioc $ioc;
- public function test_get()
+ public function setUp(): void
{
- $this->assertInstanceOf(Connect::class,Container::ioc()->get(Connect::class));
+ $this->ioc = new Ioc();
}
- public function test_make()
- {
- $this->assertInstanceOf(View::class,Container::ioc()->make(View::class,['view' => 'a','title'=>'a','description'=>'a']));
- }
- public function test_set()
+ /**
+ * @throws Kedavra
+ * @throws ReflectionException
+ */
+ public function test_has()
{
- $this->assertInstanceOf(View::class,Container::ioc()->set(View::class,new View('a','a','description'))->get(View::class));
+
+ $this->assertTrue($this->ioc->has(Connect::class));
+ $this->assertFalse($this->ioc->has(Table::class));
+ $this->assertFalse($this->ioc->has(Router::class));
+
}
- public function test_debug()
+ /**
+ * @throws Kedavra
+ * @throws ReflectionException
+ */
+ public function test_get()
{
- $this->assertNotEmpty(Container::ioc()->debug(Connect::class));
+ $this->assertInstanceOf(Connect::class,$this->ioc->get(Connect::class));
+ $this->assertInstanceOf(Table::class,$this->ioc->get(Table::class));
+
}
- public function test_call()
+ public function test_get_variable()
{
- $this->assertEquals(3306,Container::ioc()->call(Connect::class,'port'));
+ $this->assertInstanceOf(Flash::class,$this->ioc->get('flash'));
}
+
}
} \ No newline at end of file
diff --git a/tests/Message/WriteTest.php b/tests/Message/WriteTest.php
index 8641bb5..8641bb5 100644..100755
--- a/tests/Message/WriteTest.php
+++ b/tests/Message/WriteTest.php
diff --git a/tests/Routing/RouterTest.php b/tests/Routing/RouterTest.php
index e86e17e..e86e17e 100644..100755
--- a/tests/Routing/RouterTest.php
+++ b/tests/Routing/RouterTest.php
diff --git a/tests/Validator/ValidatorTest.php b/tests/Validator/ValidatorTest.php
index 111cac6..111cac6 100644..100755
--- a/tests/Validator/ValidatorTest.php
+++ b/tests/Validator/ValidatorTest.php
diff --git a/tests/View/EywaTest.php b/tests/View/EywaTest.php
index d3a92ff..d3a92ff 100644..100755
--- a/tests/View/EywaTest.php
+++ b/tests/View/EywaTest.php
diff --git a/tests/View/ViewTest.php b/tests/View/ViewTest.php
index d33efdd..d33efdd 100644..100755
--- a/tests/View/ViewTest.php
+++ b/tests/View/ViewTest.php
diff --git a/web/.gitignore b/web/.gitignore
index 95a48fb..95a48fb 100644..100755
--- a/web/.gitignore
+++ b/web/.gitignore
diff --git a/web/.htaccess b/web/.htaccess
index 93b066c..93b066c 100644..100755
--- a/web/.htaccess
+++ b/web/.htaccess
diff --git a/web/css/app.css b/web/css/app.css
index 3168fdf..3168fdf 100644..100755
--- a/web/css/app.css
+++ b/web/css/app.css
diff --git a/web/favicon.ico b/web/favicon.ico
index 145b4b0..145b4b0 100644..100755
--- a/web/favicon.ico
+++ b/web/favicon.ico
Binary files differ
diff --git a/web/index.php b/web/index.php
index 50a8eed..f07bfa1 100644..100755
--- a/web/index.php
+++ b/web/index.php
@@ -1,5 +1,6 @@
<?php
+
require '../vendor/autoload.php';
-app()->run(); \ No newline at end of file
+ app()->run(); \ No newline at end of file
diff --git a/web/js/app.js b/web/js/app.js
index 3710888..3710888 100644..100755
--- a/web/js/app.js
+++ b/web/js/app.js
diff --git a/web/robots.txt b/web/robots.txt
index eb05362..eb05362 100644..100755
--- a/web/robots.txt
+++ b/web/robots.txt