From b782d31456085846496d749ade639d00d83ed993 Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Sun, 3 Mar 2019 12:05:10 +0100 Subject: [PATCH 1/7] added start of application test --- .gitattributes | 2 - .gitignore | 1 + .idea/Romano.iml | 43 +- .idea/workspace.xml | 581 +++-- .phpunit.result.cache | 1 + README.md | 2 +- {pub => _old}/.htaccess | 0 .../Container.php => _old/ContaineroLD.php | 12 +- {pub => _old}/index.php | 2 +- app/controllers/.DS_Store | Bin 6148 -> 0 bytes app/libs/.DS_Store | Bin 6148 -> 0 bytes app/libs/DB.php | 122 - app/models/.DS_Store | Bin 6148 -> 0 bytes bootstrap.php | 136 -- composer.json | 13 +- composer.lock | 2050 ++++++++++++++++- config.php | 29 - docker-compose.yml | 2 +- modules/thijzer/Blog/Controllers/Blog.php | 67 - modules/thijzer/Blog/Models/Post.php | 131 -- .../Blog/Resources/Views/RecentPost.twig | 8 - .../Blog/Resources/views/Archived.twig | 8 - .../Blog/Resources/views/RecentPost.twig | 8 - modules/thijzer/Files/Controllers/Files.php | 17 - phpunit.xml | 22 + pub/.DS_Store | Bin 6148 -> 0 bytes pub/css/.DS_Store | Bin 6148 -> 0 bytes src/Framework/Application.php | 116 + src/Framework/ArrayFunctions.php | 216 ++ src/{Romano => Framework}/Auth.php | 0 src/{Romano => Framework}/Cache.php | 0 src/{Romano => Framework}/ClassFunctions.php | 0 src/Framework/ConfigurationManager.php | 33 + src/Framework/ContainerInterface.php | 38 + .../Ctrlr.php => Framework/Controller.php} | 21 +- src/{Romano => Framework}/Cookie.php | 0 src/{Romano => Framework}/Crypt.php | 4 +- src/{Romano => Framework}/DB.php | 0 src/{Romano => Framework}/Elastic.php | 0 src/{Romano => Framework}/File.php | 0 src/{Romano => Framework}/FileManager.php | 0 src/{Romano => Framework}/FileOutput.php | 0 src/{Romano => Framework}/Filter.php | 0 src/{Romano => Framework}/Form.php | 0 src/{Romano => Framework}/Html.php | 0 src/{Romano => Framework}/IndexFile.php | 0 src/{Romano => Framework}/Input.php | 0 src/{Romano => Framework}/Lang.php | 0 src/Framework/LanguageSelector.php | 45 + src/Framework/Matroska.php | 50 + src/{Romano => Framework}/Output.php | 0 src/{Romano => Framework}/Parse.php | 0 src/{Romano => Framework}/Query.php | 0 src/Framework/Request.php | 60 + src/Framework/RequestParameterBuilder.php | 26 + src/{Romano => Framework}/ResizeImage.php | 0 src/{Romano => Framework}/Resource.php | 0 src/{Romano => Framework}/Route.php | 1 + src/{Romano => Framework}/Send.php | 14 +- src/{Romano => Framework}/Session.php | 0 src/{Romano => Framework}/SimpleDB.php | 2 +- src/{Romano => Framework}/Singleton.php | 0 src/{Romano => Framework}/Token.php | 4 +- src/{Romano => Framework}/Track.php | 0 src/{Romano => Framework}/TwitterBS.php | 0 src/{Romano => Framework}/Validate.php | 0 src/Framework/libs/DB.php | 135 ++ {app => src/Framework}/libs/Validate.php | 6 +- src/Romano/Application.php | 156 -- src/Romano/Arrays.php | 88 - src/Romano/Config.php | 29 - src/Romano/Request.php | 69 - tests/Framework/ApplicationTest.php | 48 + tests/Framework/MatroskaTest.php | 179 ++ web/admin | 1 - web/default | 1 - dev.php => web/dev.php | 0 web/index.php | 18 +- web/timer | 1 - 79 files changed, 3534 insertions(+), 1084 deletions(-) delete mode 100755 .gitattributes create mode 100644 .phpunit.result.cache rename {pub => _old}/.htaccess (100%) rename src/Romano/Container.php => _old/ContaineroLD.php (82%) rename {pub => _old}/index.php (96%) delete mode 100755 app/controllers/.DS_Store delete mode 100755 app/libs/.DS_Store delete mode 100644 app/libs/DB.php delete mode 100755 app/models/.DS_Store delete mode 100755 bootstrap.php delete mode 100755 config.php delete mode 100755 modules/thijzer/Blog/Controllers/Blog.php delete mode 100755 modules/thijzer/Blog/Models/Post.php delete mode 100755 modules/thijzer/Blog/Resources/Views/RecentPost.twig delete mode 100755 modules/thijzer/Blog/Resources/views/Archived.twig delete mode 100755 modules/thijzer/Blog/Resources/views/RecentPost.twig delete mode 100644 modules/thijzer/Files/Controllers/Files.php create mode 100644 phpunit.xml delete mode 100755 pub/.DS_Store delete mode 100644 pub/css/.DS_Store create mode 100644 src/Framework/Application.php create mode 100755 src/Framework/ArrayFunctions.php rename src/{Romano => Framework}/Auth.php (100%) rename src/{Romano => Framework}/Cache.php (100%) rename src/{Romano => Framework}/ClassFunctions.php (100%) create mode 100644 src/Framework/ConfigurationManager.php create mode 100644 src/Framework/ContainerInterface.php rename src/{Romano/Ctrlr.php => Framework/Controller.php} (72%) rename src/{Romano => Framework}/Cookie.php (100%) rename src/{Romano => Framework}/Crypt.php (84%) rename src/{Romano => Framework}/DB.php (100%) rename src/{Romano => Framework}/Elastic.php (100%) rename src/{Romano => Framework}/File.php (100%) rename src/{Romano => Framework}/FileManager.php (100%) rename src/{Romano => Framework}/FileOutput.php (100%) rename src/{Romano => Framework}/Filter.php (100%) rename src/{Romano => Framework}/Form.php (100%) rename src/{Romano => Framework}/Html.php (100%) rename src/{Romano => Framework}/IndexFile.php (100%) rename src/{Romano => Framework}/Input.php (100%) rename src/{Romano => Framework}/Lang.php (100%) create mode 100644 src/Framework/LanguageSelector.php create mode 100644 src/Framework/Matroska.php rename src/{Romano => Framework}/Output.php (100%) rename src/{Romano => Framework}/Parse.php (100%) rename src/{Romano => Framework}/Query.php (100%) create mode 100644 src/Framework/Request.php create mode 100644 src/Framework/RequestParameterBuilder.php rename src/{Romano => Framework}/ResizeImage.php (100%) rename src/{Romano => Framework}/Resource.php (100%) rename src/{Romano => Framework}/Route.php (99%) rename src/{Romano => Framework}/Send.php (62%) rename src/{Romano => Framework}/Session.php (100%) rename src/{Romano => Framework}/SimpleDB.php (99%) rename src/{Romano => Framework}/Singleton.php (100%) rename src/{Romano => Framework}/Token.php (64%) rename src/{Romano => Framework}/Track.php (100%) rename src/{Romano => Framework}/TwitterBS.php (100%) rename src/{Romano => Framework}/Validate.php (100%) create mode 100644 src/Framework/libs/DB.php rename {app => src/Framework}/libs/Validate.php (98%) delete mode 100644 src/Romano/Application.php delete mode 100755 src/Romano/Arrays.php delete mode 100644 src/Romano/Config.php delete mode 100644 src/Romano/Request.php create mode 100644 tests/Framework/ApplicationTest.php create mode 100644 tests/Framework/MatroskaTest.php delete mode 120000 web/admin delete mode 120000 web/default rename dev.php => web/dev.php (100%) delete mode 120000 web/timer diff --git a/.gitattributes b/.gitattributes deleted file mode 100755 index 6f75f5e..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -.git/ export-ignore -package/ export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index 814174e..d8e3a1e 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ pub/img views/home/about.php views/home/contact.php +.data/* \ No newline at end of file diff --git a/.idea/Romano.iml b/.idea/Romano.iml index c956989..2373288 100644 --- a/.idea/Romano.iml +++ b/.idea/Romano.iml @@ -1,7 +1,48 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5946e9c..78f0f69 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,163 +2,237 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $PROJECT_DIR$/composer.json + - - - + + + - - - + + - - - - - - - - - + + + + + + + + + + + setRootConfiguration + " + + + ' + + - - - - true - DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - \ No newline at end of file diff --git a/composer.json b/composer.json index 4ba394d..fccd918 100755 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": ">=7.3", + "php": ">=7.2.0", "twig/twig": "^2.6" }, "autoload": { diff --git a/src/Framework/ClassNameReference.php b/src/Framework/ClassNameReference.php new file mode 100644 index 0000000..13a56bc --- /dev/null +++ b/src/Framework/ClassNameReference.php @@ -0,0 +1,52 @@ +className = \get_class($object); + } + + /** @return string */ + public function getClassName(): string + { + return $this->className; + } + + /** @return bool|string */ + public function getShortName() + { + return substr(strrchr($this->getClassName(), '\\'), 1); + } + + /** + * @param $object + * + * @return bool + */ + public function equals($object): bool + { + return $this->is((new self($object))->getClassName()); + } + + /** + * @param string $className + * + * @return bool + */ + public function is(string $className): bool + { + return $this->getClassName() === $className; + } + + /** @return string */ + public function __toString(): string + { + return $this->getClassName(); + } +} diff --git a/src/Framework/Exception/UnknownObjectException.php b/src/Framework/Exception/UnknownObjectException.php new file mode 100644 index 0000000..4f1f528 --- /dev/null +++ b/src/Framework/Exception/UnknownObjectException.php @@ -0,0 +1,17 @@ + Date: Mon, 4 Mar 2019 21:38:37 +0100 Subject: [PATCH 3/7] fixed ClassnameReference object added spec tests --- bin/phpspec | 1 + bin/phpunit | 1 + composer.json | 3 ++ phpspec.yml.dist | 8 ++++ phpunit.xml | 2 +- src/Framework/ClassNameReference.php | 4 +- .../spec/Framework/ClassNameReferenceSpec.php | 41 +++++++++++++++++++ .../{ => unit}/Framework/ApplicationTest.php | 0 tests/{ => unit}/Framework/MatroskaTest.php | 0 9 files changed, 57 insertions(+), 3 deletions(-) create mode 120000 bin/phpspec create mode 120000 bin/phpunit create mode 100644 phpspec.yml.dist create mode 100644 tests/spec/Framework/ClassNameReferenceSpec.php rename tests/{ => unit}/Framework/ApplicationTest.php (100%) rename tests/{ => unit}/Framework/MatroskaTest.php (100%) diff --git a/bin/phpspec b/bin/phpspec new file mode 120000 index 0000000..22e0618 --- /dev/null +++ b/bin/phpspec @@ -0,0 +1 @@ +../vendor/phpspec/phpspec/bin/phpspec \ No newline at end of file diff --git a/bin/phpunit b/bin/phpunit new file mode 120000 index 0000000..4ba3256 --- /dev/null +++ b/bin/phpunit @@ -0,0 +1 @@ +../vendor/phpunit/phpunit/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index fccd918..41b1dae 100755 --- a/composer.json +++ b/composer.json @@ -23,5 +23,8 @@ "require-dev": { "phpspec/phpspec": "^5.1", "phpunit/phpunit": "^8.0" + }, + "config": { + "bin-dir": "bin" } } diff --git a/phpspec.yml.dist b/phpspec.yml.dist new file mode 100644 index 0000000..16e7f9d --- /dev/null +++ b/phpspec.yml.dist @@ -0,0 +1,8 @@ +suites: + Main: + namespace: Romano + psr4_prefix: Romano + src_path: "%paths.config%/src" + spec_path: "%paths.config%/tests" + +formatter.name: pretty \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 8a3adbb..ac72ff0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,7 +16,7 @@ - tests/ + tests/unit/ \ No newline at end of file diff --git a/src/Framework/ClassNameReference.php b/src/Framework/ClassNameReference.php index 13a56bc..3fa7c6c 100644 --- a/src/Framework/ClassNameReference.php +++ b/src/Framework/ClassNameReference.php @@ -25,11 +25,11 @@ public function getShortName() } /** - * @param $object + * @param object $object * * @return bool */ - public function equals($object): bool + public function equals(object $object): bool { return $this->is((new self($object))->getClassName()); } diff --git a/tests/spec/Framework/ClassNameReferenceSpec.php b/tests/spec/Framework/ClassNameReferenceSpec.php new file mode 100644 index 0000000..6e7d1c2 --- /dev/null +++ b/tests/spec/Framework/ClassNameReferenceSpec.php @@ -0,0 +1,41 @@ +beConstructedWith(new TestObject); + } + + public function it_should_return_tooString(): void + { + $this->__toString()->shouldReturn(TestObject::class); + } + + public function it_should_return_GetShortName(): void + { + $this->getShortName()->shouldReturn('TestObject'); + } + + public function it_should_compare_to_string() + { + $this->is(TestObject::class)->shouldBe(true); + } + + public function it_should_compare_to_className(): void + { + $this->getClassName()->shouldBe(TestObject::class); + } + + public function it_should_compare_to_equals(): void + { + $this->equals(new TestObject())->shouldBe(true); + } +} + + +class TestObject{} \ No newline at end of file diff --git a/tests/Framework/ApplicationTest.php b/tests/unit/Framework/ApplicationTest.php similarity index 100% rename from tests/Framework/ApplicationTest.php rename to tests/unit/Framework/ApplicationTest.php diff --git a/tests/Framework/MatroskaTest.php b/tests/unit/Framework/MatroskaTest.php similarity index 100% rename from tests/Framework/MatroskaTest.php rename to tests/unit/Framework/MatroskaTest.php From bd64c35d1d54a8526ab5626136935766f55f6612 Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Thu, 7 Mar 2019 22:46:46 +0100 Subject: [PATCH 4/7] added more tests and filehash --- .phpunit.result.cache | 2 +- {src/Framework => _old}/ClassFunctions.php | 0 {app/template => _old}/default/base.php | 0 {app/template => _old}/default/theme.php | 0 {app => _old}/views/home/example.txt | 0 app/template/default/.DS_Store | Bin 6148 -> 0 bytes app/views/.DS_Store | Bin 6148 -> 0 bytes app/views/home/.DS_Store | Bin 6148 -> 0 bytes src/Framework/Application.php | 28 +--- src/Framework/Controller.php | 50 ++----- .../Exception/UnknownObjectException.php | 4 +- .../UnknownTemplateEngineException.php | 17 +++ src/Framework/{ => File}/File.php | 16 ++- src/Framework/File/FileHash.php | 41 ++++++ src/Framework/{ => File}/FileManager.php | 0 src/Framework/{ => File}/FileOutput.php | 0 src/Framework/{ => File}/IndexFile.php | 0 src/Framework/{ => HTTP}/Request.php | 12 +- src/Framework/HTTP/Response.php | 32 +++++ src/Framework/{ => Html}/Html.php | 0 src/Framework/Lang.php | 8 +- src/Framework/PaginationAdapter.php | 45 ++++++ src/Framework/Resource.php | 134 ------------------ src/Framework/Resource/Resource.php | 78 ++++++++++ src/Framework/Resource/ResourceManager.php | 86 +++++++++++ src/Framework/Route.php | 97 +++---------- src/Framework/RouteFactory.php | 39 +++++ src/Framework/Router.php | 111 +++++++++++++++ src/Framework/TemplateBuilder.php | 75 ++++++++++ tests/spec/Framework/File/FileHashSpec.php | 45 ++++++ tests/unit/Framework/ApplicationTest.php | 6 +- web/index.php | 32 ++--- 32 files changed, 649 insertions(+), 309 deletions(-) rename {src/Framework => _old}/ClassFunctions.php (100%) rename {app/template => _old}/default/base.php (100%) rename {app/template => _old}/default/theme.php (100%) rename {app => _old}/views/home/example.txt (100%) delete mode 100755 app/template/default/.DS_Store delete mode 100755 app/views/.DS_Store delete mode 100644 app/views/home/.DS_Store create mode 100644 src/Framework/Exception/UnknownTemplateEngineException.php rename src/Framework/{ => File}/File.php (88%) create mode 100644 src/Framework/File/FileHash.php rename src/Framework/{ => File}/FileManager.php (100%) rename src/Framework/{ => File}/FileOutput.php (100%) rename src/Framework/{ => File}/IndexFile.php (100%) rename src/Framework/{ => HTTP}/Request.php (85%) create mode 100644 src/Framework/HTTP/Response.php rename src/Framework/{ => Html}/Html.php (100%) create mode 100644 src/Framework/PaginationAdapter.php delete mode 100644 src/Framework/Resource.php create mode 100644 src/Framework/Resource/Resource.php create mode 100644 src/Framework/Resource/ResourceManager.php create mode 100644 src/Framework/RouteFactory.php create mode 100644 src/Framework/Router.php create mode 100644 src/Framework/TemplateBuilder.php create mode 100644 tests/spec/Framework/File/FileHashSpec.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache index b3ef3bf..30ce453 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:30:"PHPUnit\Runner\TestResultCache":1778:{a:2:{s:7:"defects";a:7:{s:76:"Tests\Romano\Framework\Utils\MatroskaTest::test_it_should_unflatten_an_array";i:3;s:74:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_get_the_correct_value";i:3;s:67:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_remove_a_value";i:3;s:71:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_unflatten_an_array";i:3;s:88:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_start_from_a_multidimensional_array";i:3;s:65:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_check_values";i:3;s:74:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_unflatten_an_array";i:5;}s:5:"times";a:13:{s:76:"Tests\Romano\Framework\Utils\MatroskaTest::test_it_should_unflatten_an_array";d:0.002;s:71:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_unflatten_an_array";d:0;s:74:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_get_the_correct_value";d:0;s:67:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_remove_a_value";d:0;s:65:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_have_a_value";d:0;s:65:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_check_values";d:0;s:88:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_start_from_a_multidimensional_array";d:0;s:74:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_unflatten_an_array";d:0.002;s:77:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_get_the_correct_value";d:0.001;s:70:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_remove_a_value";d:0;s:68:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_check_values";d:0;s:91:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_start_from_a_multidimensional_array";d:0;s:76:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_build_the_path_array";d:0.003;}}} \ No newline at end of file +C:30:"PHPUnit\Runner\TestResultCache":1866:{a:2:{s:7:"defects";a:8:{s:76:"Tests\Romano\Framework\Utils\MatroskaTest::test_it_should_unflatten_an_array";i:3;s:74:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_get_the_correct_value";i:3;s:67:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_remove_a_value";i:3;s:71:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_unflatten_an_array";i:3;s:88:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_start_from_a_multidimensional_array";i:3;s:65:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_check_values";i:3;s:74:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_unflatten_an_array";i:5;s:76:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_build_the_path_array";i:3;}s:5:"times";a:13:{s:76:"Tests\Romano\Framework\Utils\MatroskaTest::test_it_should_unflatten_an_array";d:0.002;s:71:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_unflatten_an_array";d:0;s:74:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_get_the_correct_value";d:0;s:67:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_remove_a_value";d:0;s:65:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_have_a_value";d:0;s:65:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_check_values";d:0;s:88:"Tests\Romano\Framework\Utils\MatroskaTest::it_should_start_from_a_multidimensional_array";d:0;s:74:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_unflatten_an_array";d:0.002;s:77:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_get_the_correct_value";d:0.001;s:70:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_remove_a_value";d:0;s:68:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_check_values";d:0;s:91:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_start_from_a_multidimensional_array";d:0;s:76:"Tests\Romano\Framework\Utils\ApplicationTest::it_should_build_the_path_array";d:0.003;}}} \ No newline at end of file diff --git a/src/Framework/ClassFunctions.php b/_old/ClassFunctions.php similarity index 100% rename from src/Framework/ClassFunctions.php rename to _old/ClassFunctions.php diff --git a/app/template/default/base.php b/_old/default/base.php similarity index 100% rename from app/template/default/base.php rename to _old/default/base.php diff --git a/app/template/default/theme.php b/_old/default/theme.php similarity index 100% rename from app/template/default/theme.php rename to _old/default/theme.php diff --git a/app/views/home/example.txt b/_old/views/home/example.txt similarity index 100% rename from app/views/home/example.txt rename to _old/views/home/example.txt diff --git a/app/template/default/.DS_Store b/app/template/default/.DS_Store deleted file mode 100755 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0%<|@KOI~$XbvBmch;Ox)bEb-ih&vs~9|6;aMg@LDfp50C BCzk*K diff --git a/app/views/home/.DS_Store b/app/views/home/.DS_Store deleted file mode 100644 index 29315cb716d0b3a18e5212f370053cf533c6f0ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJx>Bb5Pho@Bs7$k`wP5S+Fb~C#>QAH3JI7)2^>PK?x*|aL&L?>(hxI4cHivm z%Dt@i&#_Rf_@?#`AY6=E|fnXpQI2s0cXN&X)hS3KD!9XzZ#ekd- znN6^CYz+12V5d(2VvlAO>hhM5nCw_OHin#`Bnu^4X!0jUvT)k7`<0H3p@k#q%FN>{ ze?DH4u1&SNzL#KJwckF$xBPfq%w8>Wy#5BW}v?)^FRB xyEd~uu!)FYBMOCj>mz^zIY-WP(&n@1^eY`3L&+j`4JXEjfD#g2Fz^Qqd;p^$H$eaZ diff --git a/src/Framework/Application.php b/src/Framework/Application.php index 27c6b3d..8fe8ca6 100644 --- a/src/Framework/Application.php +++ b/src/Framework/Application.php @@ -81,36 +81,18 @@ public function buildEnvironmentFromRequest(Request $request): void //$this->setLanguage(); } - private function buildURL($urlList) + public function buildRouter(): router { - $app = '/'; - $app .= ($this->defApp !== 'default') ? $this->defApp.'/' : ''; - $app .= ($this->currentLanguage) ? $this->currentLanguage.'/' : ''; - - $tmp = []; - foreach ($urlList as $key => $route) { - if (isset($route['params'])) { - preg_match_all('~{(.*?)}~', $key, $output); - $glu = implode('_', $output[1]); - $tmp[$route['resource']]['dynamic'][$glu] = $app.$key; - continue; - } - - $tmp[$route['resource']]['static'][] = $app.$key; - } - - $this->config->setParameter('url', $tmp); + return RouteFactory::buildRouter($this->getProvisionedConfig()); } - public function getConfig(): ConfigurationManager + public function getProvisionedConfig(): ConfigurationManager { return $this->config; } - public function getRoutes() + public function getConfig(): ConfigurationManager { - $routes = require path('routes'); - $this->buildURL($routes['routes']); - return $routes['routes']; + return $this->config; } } diff --git a/src/Framework/Controller.php b/src/Framework/Controller.php index 5f9ab99..bc14e9a 100644 --- a/src/Framework/Controller.php +++ b/src/Framework/Controller.php @@ -4,10 +4,11 @@ abstract class Controller { - public function __construct() + private $params; + + public function __construct(array $params) { - $this->route = Matroska::getAll('route'); - $this->params = $this->route['parameter']; + $this->params = $params; } public function param($name) @@ -15,38 +16,13 @@ public function param($name) return $this->params[$name]; } - public function pagination($rowCount, $offset, $limit, $page = '?page=') - { - $requestedPage = 1; - if (!isset($this->params['page'])) { - $this->params['page'] = 1; - } - $options['offset'] = $offset; - $options['limit'] = $limit; - - $options['num_items'] = $rowCount; - $requestedPage = (int) $this->params['page']; - $options['num_pages'] = (int) ceil($options['num_items'] / $options['limit']); - - if (0 === $options['num_pages']) { - $options['num_pages'] = 1; - } - if ($requestedPage > $options['num_pages'] || $requestedPage < 1) { - Output::page(404); - } - - $options['requested_page'] = $requestedPage; - $options['prev'] = $requestedPage - 1; - $options['next'] = $requestedPage + 1; - $options['url'] = '/'; - if (false !== strpos($page, '?')) { - $options['url'] .= $this->route['url']; - } - $options['page'] = $page; - $options['next_lbl'] = Lang::get('lbl.next'); - $options['prev_lbl'] = Lang::get('lbl.prev'); - $options['offset'] = ($options['requested_page'] * $options['limit']) - $options['limit']; - - return $options; - } +// public function getTemplateResponse(): Response +// { +// return new Response($this->template); +// } +// +// public function getResourceResponse(): Response +// { +// return new Response($this->resource->render(), $this->resource->getScope()); +// } } diff --git a/src/Framework/Exception/UnknownObjectException.php b/src/Framework/Exception/UnknownObjectException.php index 4f1f528..f4447a2 100644 --- a/src/Framework/Exception/UnknownObjectException.php +++ b/src/Framework/Exception/UnknownObjectException.php @@ -6,10 +6,10 @@ class UnknownObjectException extends \Exception { - public function __construct(string $object, int $code = 0, Throwable $previous = null) + public function __construct(string $engine, int $code = 0, Throwable $previous = null) { parent::__construct( - sprintf('Cannot instantiate a unknown object of class %s', $object), + sprintf('Cannot instantiate a unknown object of class %s', $engine), $code, $previous ); diff --git a/src/Framework/Exception/UnknownTemplateEngineException.php b/src/Framework/Exception/UnknownTemplateEngineException.php new file mode 100644 index 0000000..a6bb15a --- /dev/null +++ b/src/Framework/Exception/UnknownTemplateEngineException.php @@ -0,0 +1,17 @@ + $value) { $this->{$key} = $value; } @@ -36,7 +38,7 @@ public function getFullPath() public function getFullPathHash() { - return crc32b($this->fullPath); + return \crc32($this->fullPath); } public function getContent() @@ -50,14 +52,14 @@ public function setContent($content) return $this; } - public function getHash() + public function getHash(): FileHash { - return crc32b($this->getContent()); + return FileHash::generate($this->getContent()); } public function getMimeType() { - if (!$this->mimetype && $this->exsists()) { + if (!$this->mimetype && $this->exists()) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $this->mimetype = finfo_file($finfo, $this->fullPath); finfo_close($finfo); @@ -108,7 +110,7 @@ public function save() $localFile = fopen($this->fullPath, 'w+'); fwrite($localFile, $this->getContent()); fclose($localFile); - } catch (Exception $e) { + } catch (\Exception $e) { die($e); } } diff --git a/src/Framework/File/FileHash.php b/src/Framework/File/FileHash.php new file mode 100644 index 0000000..6889fad --- /dev/null +++ b/src/Framework/File/FileHash.php @@ -0,0 +1,41 @@ +hash = hash('crc32b', $content); + + return $fileHash; + } + + public function getHash() + { + return $this->hash; + } + + public function __toString(): string + { + return $this->getHash(); + } + + public function is(string $hash): bool + { + return $this->hash === $hash; + } + + public function isGeneratedFrom(string $content): bool + { + return self::generate($content)->is($this->hash); + } + + public function equal(FileHash $fileHash): bool + { + return $fileHash->is($this->hash); + } +} \ No newline at end of file diff --git a/src/Framework/FileManager.php b/src/Framework/File/FileManager.php similarity index 100% rename from src/Framework/FileManager.php rename to src/Framework/File/FileManager.php diff --git a/src/Framework/FileOutput.php b/src/Framework/File/FileOutput.php similarity index 100% rename from src/Framework/FileOutput.php rename to src/Framework/File/FileOutput.php diff --git a/src/Framework/IndexFile.php b/src/Framework/File/IndexFile.php similarity index 100% rename from src/Framework/IndexFile.php rename to src/Framework/File/IndexFile.php diff --git a/src/Framework/Request.php b/src/Framework/HTTP/Request.php similarity index 85% rename from src/Framework/Request.php rename to src/Framework/HTTP/Request.php index 78454e7..bd8d371 100644 --- a/src/Framework/Request.php +++ b/src/Framework/HTTP/Request.php @@ -22,12 +22,22 @@ public function get(string $key) return $this->parameters->get($key); } + public function has(string $key): bool + { + return $this->parameters->has($key); + } + public function set(string $key, $value): void { $this->parameters->add($key, $value); } - public function getURLSection(string $section) + public function getURLSections(): array + { + return $this->parameters->get('SECTIONS'); + } + + public function getURLSection(int $section) { return $this->parameters->get('SECTIONS', $section); } diff --git a/src/Framework/HTTP/Response.php b/src/Framework/HTTP/Response.php new file mode 100644 index 0000000..88bbe96 --- /dev/null +++ b/src/Framework/HTTP/Response.php @@ -0,0 +1,32 @@ +path = $path; + $this->data = $data; + } + + /** + * @return array + */ + public function getArrayData(): array + { + return [ + 'path' => $this->path, + 'data' => $this->data, + ]; + } +} \ No newline at end of file diff --git a/src/Framework/Html.php b/src/Framework/Html/Html.php similarity index 100% rename from src/Framework/Html.php rename to src/Framework/Html/Html.php diff --git a/src/Framework/Lang.php b/src/Framework/Lang.php index 662abe2..573f07f 100644 --- a/src/Framework/Lang.php +++ b/src/Framework/Lang.php @@ -12,11 +12,13 @@ public static function get($route, $replacers = array()) if (!isset(self::$array[$type][$slug])) { return '!!! missing locale !!! : '.$route; } - $respons = self::$array[$type][$slug]; + + $response = self::$array[$type][$slug]; if (!empty($replacers)) { - return str_replace(array_flip($replacers), $replacers, $respons); + return str_replace(array_flip($replacers), $replacers, $response); } - return $respons; + + return $response; } public static function set(array $locale) diff --git a/src/Framework/PaginationAdapter.php b/src/Framework/PaginationAdapter.php new file mode 100644 index 0000000..db41c8c --- /dev/null +++ b/src/Framework/PaginationAdapter.php @@ -0,0 +1,45 @@ +params['page'])) { + $this->params['page'] = 1; + } + $options['offset'] = $offset; + $options['limit'] = $limit; + + $options['num_items'] = $rowCount; + $requestedPage = (int) $this->params['page']; + $options['num_pages'] = (int) ceil($options['num_items'] / $options['limit']); + + if (0 === $options['num_pages']) { + $options['num_pages'] = 1; + } + if ($requestedPage > $options['num_pages'] || $requestedPage < 1) { + Output::page(404); + } + + $options['requested_page'] = $requestedPage; + $options['prev'] = $requestedPage - 1; + $options['next'] = $requestedPage + 1; + $options['url'] = '/'; + if (false !== strpos($page, '?')) { + $options['url'] .= $this->route['url']; + } + $options['page'] = $page; + $options['next_lbl'] = Lang::get('lbl.next'); + $options['prev_lbl'] = Lang::get('lbl.prev'); + $options['offset'] = ($options['requested_page'] * $options['limit']) - $options['limit']; + + return $options; + } +} \ No newline at end of file diff --git a/src/Framework/Resource.php b/src/Framework/Resource.php deleted file mode 100644 index 8b9d3c3..0000000 --- a/src/Framework/Resource.php +++ /dev/null @@ -1,134 +0,0 @@ - array( - 'extends' => '{% extends "$1" %}', - 'block' => "{% block $1 %}\n$2{% endblock %}", - 'include' => '{% include "$1" %}', - 'comment' => "{# $1 #}\n\n", - ) - ); - - public function __construct($pathView, $engine) - { - if (!isset($this->options[$engine])) { - leave('select a proper render engine like twig'); - } - $this->isDev = (DEV_ENV !== true); - $this->storePath = $pathView; - $this->options = $this->options[$engine]; - $comment = "Generated file from Resource"; - $comment .= ' :: '.date('F Y'); - $this->render = str_replace('$1', $comment, $this->options['comment']); - } - - public function block($name) - { - $this->name = $name; - return $this; - } - - public function setBaseFile($baseFile) - { - $this->baseFile = $baseFile; - return $this; - } - - public function scope($controller) - { - if (isset($this->scope[$controller])) { - return $this->scope[$controller]; - } - - list($ctrl, $method) = explode('@', $controller); - if (is_callable($class = ucfirst($ctrl), $method)) { - $class = new $class(); - $this->index[$ctrl] = $class; - $this->scope[$controller] = (array) $class->$method(); - $this->caviar = array_merge($this->caviar, $this->scope[$controller]); - return $this; - } - leave('undefined scope '.$controller.' passed'); - } - - public function addToScope($name, $scope) - { - $this->caviar = array_merge($this->caviar, array($name => $scope)); - } - - public function html($path) - { - $blockPart = new File(path('view').$path.'.twig'); - $this->blocks[$this->name][] = $blockPart; - return $this; - } - - public function store($path) - { - $this->storePath = $path; - } - - public function render() - { - $baseCacheFile = new File(path('view_cache'). $this->storePath); - if ($this->isDev && $baseCacheFile->exists()) { - return $this->storePath; - } - - if (!$this->blocks) { - leave('no html blocks defined'); - } - - $this->render .= str_replace('$1', $this->baseFile, $this->options['extends']); - - if ($this->lock === true) { - $this->render .= str_replace('$1', 'locked', $this->options['comment']); - } - - foreach ($this->blocks as $key => $block) { - $tmp = ''; - foreach ($block as $blockPart) { - if (!$blockPart->exists()) { - leave($blockPart->filename.' is not a real block'); - } - $tmp .= $blockPart->getContent(); - } - $this->render .= str_replace( - ['$1', '$2'], - [$key, $tmp], - $this->options['block'] - ) . "\n"; - } - - if (!$baseCacheFile->exists()) { - if (!is_dir($baseCacheFile->getDirectory())) { - mkdir($baseCacheFile->getDirectory()); - } - $baseCacheFile->setContent($this->render)->save(); - } elseif ($baseCacheFile->getHash() !== crc32b($this->render)) { - $baseCacheFile->setContent($this->render)->save(); - } - - return $this->storePath; - } - - public function getScope() - { - return $this->caviar; - } - - public function lock() - { - $this->lock = true; - } -} diff --git a/src/Framework/Resource/Resource.php b/src/Framework/Resource/Resource.php new file mode 100644 index 0000000..7ec0d65 --- /dev/null +++ b/src/Framework/Resource/Resource.php @@ -0,0 +1,78 @@ +blockName = $name; + + return $this; + } + + public function getBlocks(): array + { + return $this->blocks; + } + + public function hasBlocks(): bool + { + return \count($this->blocks) > 0; + } + + public function setBaseFile(string $baseFile): self + { + $this->baseFile = $baseFile; + + return $this; + } + + public function getBaseFile(): string + { + return $this->baseFile; + } + + public function scope(string $controller): void + { + $this->scopes[$this->blockName][] = $controller; + } + + public function getScopes(): array + { + return $this->scopes; + } + + public function html($path): self + { + $this->blocks[$this->blockName][] = $path; + + return $this; + } + + public function getHtmlBlocks(): array + { + return $this->blocks; + } + + public function lock(): void + { + $this->lock = true; + } + + public function unlock(): void + { + $this->lock = false; + } + + public function isLocked(): bool + { + return $this->lock; + } +} diff --git a/src/Framework/Resource/ResourceManager.php b/src/Framework/Resource/ResourceManager.php new file mode 100644 index 0000000..da203fd --- /dev/null +++ b/src/Framework/Resource/ResourceManager.php @@ -0,0 +1,86 @@ +templateBuilder = $templateBuilder; + } + + public function renderScopeData($controller) + { + if (isset($this->scopeCollection[$controller])) { + return $this->scopeCollection[$controller]; + } + + list($ctrl, $method) = explode('@', $controller); + + if (\is_callable($class = ucfirst($ctrl), $method)) { + $class = new $class(); + $this->scopeCollection[$controller] = $class->$method(); + } + } + + public function render(Resource $resource, string $storePath) + { + if (!$resource->hasBlocks()) { + leave('no html blocks defined'); + } + + $baseCacheFile = new File(path('view_cache'). $storePath); + + $this->templateBuilder->addComment('Generated file from Resource :: '.date('F Y')); + + $this->templateBuilder->extends($resource->getBaseFile()); + + if ($resource->isLocked()) { + $this->templateBuilder->addComment('locked'); + } + + foreach ($resource->getBlocks() as $blockName => $blockParts) { + $content = ''; + foreach ($blockParts as $blockPart) { + if (!$blockPart->exists()) { + leave($blockPart->filename.' is not a real block'); + } + $content .= $blockPart->getContent(); + } + $this->templateBuilder->addBlock([$blockName, $content]); + } + + $render = $this->templateBuilder->render(); + +// if (!$baseCacheFile->exists()) { +// if (!is_dir($baseCacheFile->getDirectory())) { +// mkdir($baseCacheFile->getDirectory()); +// } +// $baseCacheFile->setContent($render)->save(); +// } elseif ($baseCacheFile->getHash()->isGeneratedFrom($render)) { +// $baseCacheFile->setContent($render)->save(); +// } + + return $render; + } + + public function getCollectedData(Resource $resource): array + { + return array_merge(...array_map(function ($controller) { + return $this->renderScopeData($controller); + }, array_merge(...$resource->getScopes()))); + } +} + + +// public function addToScope($name, $scope): void +// { +// $this->collectedData = array_merge($this->collectedData, array($name => $scope)); +// } \ No newline at end of file diff --git a/src/Framework/Route.php b/src/Framework/Route.php index e40835a..654e675 100644 --- a/src/Framework/Route.php +++ b/src/Framework/Route.php @@ -4,94 +4,33 @@ class Route { - private $request; - private $r = array(); - - public function __construct(Request $request) + /** @var string */ + private $url; + /** @var Resource */ + private $resource; + /** @var string */ + private $templatePath; + + public function __construct(string $url, Resource $resource, string $templatePath) { - $this->request = $request; - $this->r['parameter'] = array(); - $this->r['path_view'] = ''; + $this->url = $url; + $this->resource = $resource; + $this->templatePath = $templatePath; } - private function findRoute(array $routes) + /** @return string */ + public function getUrl(): string { - // home - if ($this->request->get('URI') == '' && isset($routes[''])) { - return $routes['']; - } - unset($routes['']); - - // reduce the list based on the first section - $foundRoutes = (array) preg_grep("/{$this->request->getURLSection(0)}/i", array_keys($routes)); - - foreach ($foundRoutes as $route) { - if (count($param = explode('/', $route)) === $this->request->count('SECTIONS')) { - - // string manipulation - preg_match_all("/\{(.*?)\}/i", $route, $matches); - - $value = str_replace($matches[0], '(.*)', $route); - - // now we know we have the count and the first part is ok - if (preg_match('/' . str_replace('/', '\/', $value) . '$/', $this->request->get('URI'))) { - $resource = $routes[$route]; - if ($matches[0]) $this->r['parameter'] = (array) $this->params($matches, $param); - $this->r['parameter'] = array_merge($this->request->get('PARAMS'), $this->r['parameter']); - return $resource; - } - } - } - return array(); + return $this->url; } - private function params($matches, $param) + public function getTemplatePath(): string { - foreach ($matches[0] as $key => $match) { - $par[$matches[1][$key]] = urlencode($this->request->getURLSection(array_search($match, $param))); - } - return $par; - } - - public function search(array $routes) - { - $route = $this->findRoute($routes); - if (!isset($route['resource'])) { - return false; - } - list($route['controller'], $route['method']) = explode('@', $route['resource']); - - $route['template'] = (isset($route['template'])) ?: $route['controller'].'_'.$route['method']; - $route['path_view'] = $route['template'].'.twig'; - $route['url'] = $this->request->get('URI'); - $route['path_resource'] = $route['template'].'.php'; - $this->r = array_merge($this->r, $route); - - Container::set('route', $this->r); - return true; - } - - public function getTemplate() - { - if (is_file(path('view_cache').$this->r['path_view']) || is_file(path('view').$this->r['path_view'])) { - return array( - 'path' => $this->r['path_view'], - 'data' => array() - ); - } + return $this->templatePath; } public function getResource() { - $resource = path('resource').$this->r['path_resource']; - - if (is_file($resource)) { - $res = new Resource($this->r['path_view'], 'twig'); - require $resource; - return array( - 'path' => $res->render(), - 'data' => (array) $res->getScope() - ); - } + return $this->resource; } -} +} \ No newline at end of file diff --git a/src/Framework/RouteFactory.php b/src/Framework/RouteFactory.php new file mode 100644 index 0000000..8a40971 --- /dev/null +++ b/src/Framework/RouteFactory.php @@ -0,0 +1,39 @@ +buildURL($routes['routes']); + return $routes['routes']; + } + + private function buildURL($urlList) + { + $app = '/'; + $app .= ($this->defApp !== 'default') ? $this->defApp.'/' : ''; + $app .= ($this->currentLanguage) ? $this->currentLanguage.'/' : ''; + + $tmp = []; + foreach ($urlList as $key => $route) { + if (isset($route['params'])) { + preg_match_all('~{(.*?)}~', $key, $output); + $glu = implode('_', $output[1]); + $tmp[$route['resource']]['dynamic'][$glu] = $app.$key; + continue; + } + + $tmp[$route['resource']]['static'][] = $app.$key; + } + + $this->config->setParameter('url', $tmp); + } + + public static function buildRouter(ConfigurationManager $config) + { + return new Router(); + } +} \ No newline at end of file diff --git a/src/Framework/Router.php b/src/Framework/Router.php new file mode 100644 index 0000000..8500838 --- /dev/null +++ b/src/Framework/Router.php @@ -0,0 +1,111 @@ + [], + 'path_view' => '', + ]; + + public function __construct(array $routes) + { + $this->routes = $routes; + } + + private function findRoute(Request $request) + { + $routes = $this->routes; + + // home + if (isset($routes['']) && $request->get('URI') === '') { + return $routes['']; + } + unset($routes['']); + + // reduce the list based on the first section + $foundRoutes = preg_grep("/{$request->getURLSection(0)}/i", array_keys($routes)); + + foreach ($foundRoutes as $route) { + if (\count($param = \explode('/', $route)) === \count($request->getURLSections())) { + + // string manipulation + preg_match_all("/\{(.*?)\}/", $route, $matches); + + $value = str_replace($matches[0], '(.*)', $route); + + // now we know we have the count and the first part is ok + if (preg_match('/' . str_replace('/', '\/', $value) . '$/', $request->get('URI'))) { + $resource = $routes[$route]; + if ($matches[0]) { + $this->r['parameter'] = (array) $this->params($request, $matches, $param); + } + $this->r['parameter'] = array_merge($request->get('PARAMS'), $this->r['parameter']); + return $resource; + } + } + } + + return []; + } + + private function params(Request $request, $matches, $param) + { + foreach ($matches[0] as $key => $match) { + $par[$matches[1][$key]] = urlencode($request->getURLSection(\array_search($match, $param))); + } + return $par; + } + + public function search(Request $request) + { + $route = $this->findRoute($request); + if (!isset($route['resource'])) { + return false; + } + + // controller Action + list($route['controller'], $route['method']) = explode('@', $route['resource']); + + // template Action + $route['template'] = isset($route['template']) ?: $route['controller'].'_'.$route['method']; + + $route['path_view'] = $route['template'].'.twig'; + $route['url'] = $request->get('URI'); + $route['path_resource'] = $route['template'].'.php'; + + // we need to validate & generate the route + +// return $this->r['path_view']; +// +// if (is_file(path('view_cache').$this->r['path_view']) || is_file(path('view').$this->r['path_view'])) { +// return array( +// 'path' => $this->r['path_view'], +// 'data' => array() +// ); +// } +// +// $resource = path('resource').$this->r['path_resource']; +// +// if (is_file($resource)) { +// $res = new Resource($this->r['path_view'], 'twig'); +// require $resource; +// return array( +// 'path' => $res->render(), +// 'data' => (array) $res->getScope() +// ); +// } + + $route = array_merge($this->r, $route); + + $url = $route['url']; + $resource = new Resource(new TemplateBuilder(), $route['path_resource']); + $viewPath = $route['path_view']; + + return new Route($url, $resource, $viewPath); + } +} diff --git a/src/Framework/TemplateBuilder.php b/src/Framework/TemplateBuilder.php new file mode 100644 index 0000000..f837fa5 --- /dev/null +++ b/src/Framework/TemplateBuilder.php @@ -0,0 +1,75 @@ + [ + 'extends' => '{% extends "$1" %}', + 'block' => "{% block $1 %}\n$2{% endblock %}", + 'include' => '{% include "$1" %}', + 'comment' => "{# $1 #}\n\n", + ] + ]; + + /** + * TemplateBuilder constructor. + * + * @param string $engine + * + * @throws UnknownTemplateEngineException + */ + public function __construct(string $engine = 'twig') + { + if (!isset($this->options[$engine])) { + throw new UnknownTemplateEngineException($engine); + } + + $this->options = $this->options[$engine]; + } + + public function render(): string + { + $render = ''; + + foreach ($this->renderBlocks as $renderBlock) { + $blockType = key($renderBlock); + $blockValue = $renderBlock[$blockType]; + + switch ($blockType) { + case 'comment': + $render .= str_replace('$1', $blockValue, $this->options['comment']); + break; + case 'extends': + $render .= str_replace('$1', $blockValue, $this->options['extends']); + break; + case 'block': + $render .= str_replace(['$1', '$2'], $blockValue, $this->options['block']). "\n"; + break; + } + } + + return $render; + } + + public function addComment(string $comment): void + { + $this->renderBlocks[]['comment'] = $comment; + } + + public function addBlock(array $block): void + { + $this->renderBlocks[]['block'] = $block; + } + + # only one extend is allowed + public function extends(string $extend): void + { + $this->renderBlocks[]['extends'] = $extend; + } +} \ No newline at end of file diff --git a/tests/spec/Framework/File/FileHashSpec.php b/tests/spec/Framework/File/FileHashSpec.php new file mode 100644 index 0000000..2940aeb --- /dev/null +++ b/tests/spec/Framework/File/FileHashSpec.php @@ -0,0 +1,45 @@ +beConstructedThrough('generate', [ + $content = 'content' + ]); + } + + public function it_should_generate_a_hash() + { + $this->beConstructedThrough('generate', [ + $content = 'content' + ]); + + $this->getHash()->shouldBe($this->getHash()); + } + + public function it_should_compare_tooString() + { + $this->is($this->getHash())->shouldBe(true); + } + + public function it_should_compare_as_equal() + { + $this->equal(FileHash::generate('content'))->shouldBe(true); + } + + public function it_should_compare_as_is() + { + $this->is($this->getHash())->shouldBe(true); + } + + public function it_should_IsGeneratedFrom() + { + $this->isGeneratedFrom('content')->shouldBe(true); + } +} diff --git a/tests/unit/Framework/ApplicationTest.php b/tests/unit/Framework/ApplicationTest.php index 4206fbc..8387183 100644 --- a/tests/unit/Framework/ApplicationTest.php +++ b/tests/unit/Framework/ApplicationTest.php @@ -20,18 +20,18 @@ class ApplicationTest extends TestCase /** * @test */ - public function it_should_build_the_path_array() + public function it_should_build_the_path_array(): void { $data = [ 'app_name' => 'blog', ]; - $result = new Application(dirname(__DIR__), $data); + $result = new Application(\dirname(__DIR__, 3), $data); $result->buildProject(); $expected = [ - 'root' => '/home/thijzer/Sync/Projects/Romano/tests/', + 'root' => '/home/thijzer/Sync/Projects/Romano/', 'app' => 'app/blog/', 'src'=> 'src/', 'app_config' => 'app/blog/config/', diff --git a/web/index.php b/web/index.php index 892d058..2cb4d61 100644 --- a/web/index.php +++ b/web/index.php @@ -5,32 +5,26 @@ use \Romano\Framework\Request; use \Romano\Framework\Application; -use \Romano\Framework\Route; - $request = new Request(); $application = new Application(dirname(__DIR__), $configuration); $application->buildEnvironmentFromRequest($request); +$router = $application->buildRouter(); -// start Routes -$route = new Route($request); - - -exit; - -if (($route->search($application->getRoutes())) && ($result = $route->getResource())) { +if ($route = $router->search($request)) { $view = $request->get('VIEW'); //$track = Track::get()->fromClient(); - - // route view - if ($route->getTemplate() && $view === config('view')) { - view($result); - } elseif (config('kernel_debug') === true && $view === 'dev') { - stamp('View'); - massdump($result); - } -} else { - Output::page(404); + $response = $route->getResponse(); + +// // route view +// if ($route->getTemplate() && $view === config('view')) { +// view($result); +// } elseif (config('kernel_debug') === true && $view === 'dev') { +// stamp('View'); +// massdump($result); +// } +//} else { +// Output::page(404); } From 0d36a5e835340e1adb3778501c22561825c6c399 Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Thu, 7 Mar 2019 22:57:13 +0100 Subject: [PATCH 5/7] added conf manager test --- .../Framework/ConfigurationManagerSpec.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/spec/Framework/ConfigurationManagerSpec.php diff --git a/tests/spec/Framework/ConfigurationManagerSpec.php b/tests/spec/Framework/ConfigurationManagerSpec.php new file mode 100644 index 0000000..8a7eec6 --- /dev/null +++ b/tests/spec/Framework/ConfigurationManagerSpec.php @@ -0,0 +1,43 @@ +beConstructedWith($container); + } + + public function it_should_SetConfiguration(ContainerInterface $container) + { + $this->setConfiguration($parameters = ['test']); + + $container->addAll($parameters)->shouldBeCalled(); + } + + public function it_should_SetParameter(ContainerInterface $container) + { + $this->setParameter($key = 'key', $value = 'value'); + + $container->add($key, $value)->shouldBeCalled(); + } + + public function it_should_GetParameter(ContainerInterface $container) + { + $this->getParameter($key = 'key'); + + $container->get($key)->shouldBeCalled(); + } + + public function testGetAll(ContainerInterface $container) + { + $this->getAll(); + + $container->getAll()->shouldBeCalled(); + } +} From d01e8c17426dcaf4c4c02552e92edb8c7257c735 Mon Sep 17 00:00:00 2001 From: Thijs De Paepe Date: Thu, 7 Mar 2019 23:05:50 +0100 Subject: [PATCH 6/7] Fixed Cookie class --- src/Framework/Controller.php | 2 +- src/Framework/Cookie.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Framework/Controller.php b/src/Framework/Controller.php index bc14e9a..cf66479 100644 --- a/src/Framework/Controller.php +++ b/src/Framework/Controller.php @@ -1,6 +1,6 @@ Date: Thu, 14 Mar 2019 22:27:58 +0100 Subject: [PATCH 7/7] setup directory structure --- _old/index.php | 3 + {src/Framework => _old/src/_todo}/Auth.php | 2 + {src/Framework => _old/src/_todo}/Cache.php | 0 {src/Framework => _old/src/_todo}/Crypt.php | 0 {src/Framework => _old/src/_todo}/Elastic.php | 0 {src/Framework => _old/src/_todo}/Filter.php | 8 --- {src/Framework => _old/src/_todo}/Output.php | 0 {src/Framework => _old/src/_todo}/Parse.php | 0 {src/Framework => _old/src/_todo}/Send.php | 0 .../Framework => _old/src/_todo}/SimpleDB.php | 0 .../src/_todo}/Singleton.php | 0 {src/Framework => _old/src/_todo}/Track.php | 0 .../src/_todo}/TwitterBS.php | 0 {src/Framework => _old/src/_todo}/libs/DB.php | 14 ++-- .../src/_todo}/libs/Validate.php | 0 composer.json | 3 + .../Common}/ClassNameReference.php | 2 +- .../Common}/ContainerInterface.php | 2 +- .../Common/Locale}/Lang.php | 6 +- .../Common/Locale}/LanguageSelector.php | 9 ++- .../Common}/Matroska.php | 5 +- src/Component/Common/Model/Collection.php | 65 +++++++++++++++++++ src/Framework/Application.php | 6 +- src/Framework/ConfigurationManager.php | 2 + src/Framework/{ => Controller}/Controller.php | 2 +- .../{ => File/Image}/ResizeImage.php | 9 +-- src/Framework/{ => Form}/Form.php | 0 src/Framework/Form/Input.php | 23 +++++++ src/Framework/{ => Form}/Validate.php | 24 ++++--- .../{ => Functions}/ArrayFunctions.php | 62 +++++------------- src/Framework/Functions/Characters.php | 23 +++++++ src/Framework/{ => HTTP}/Cookie.php | 2 +- src/Framework/HTTP/Request.php | 5 +- .../{ => HTTP}/RequestParameterBuilder.php | 7 +- src/Framework/HTTP/Response.php | 2 +- src/Framework/{ => HTTP}/Session.php | 17 +++-- src/Framework/HTTP/Token.php | 32 +++++++++ src/Framework/Input.php | 26 -------- src/Framework/Resource/ResourceManager.php | 2 +- src/Framework/{ => Router}/Route.php | 2 +- src/Framework/{ => Router}/RouteFactory.php | 4 +- src/Framework/{ => Router}/Router.php | 6 +- .../{ => Template}/TemplateBuilder.php | 2 +- src/Framework/Token.php | 24 ------- src/{Framework => Infrastructure}/DB.php | 19 ++++-- .../PaginationAdapter.php | 5 +- src/{Framework => Infrastructure}/Query.php | 43 ++++++------ .../Framework/ConfigurationManagerSpec.php | 2 +- tests/unit/Framework/ApplicationTest.php | 4 +- tests/unit/Framework/MatroskaTest.php | 2 +- web/index.php | 2 +- 51 files changed, 287 insertions(+), 191 deletions(-) rename {src/Framework => _old/src/_todo}/Auth.php (98%) rename {src/Framework => _old/src/_todo}/Cache.php (100%) rename {src/Framework => _old/src/_todo}/Crypt.php (100%) rename {src/Framework => _old/src/_todo}/Elastic.php (100%) rename {src/Framework => _old/src/_todo}/Filter.php (91%) rename {src/Framework => _old/src/_todo}/Output.php (100%) rename {src/Framework => _old/src/_todo}/Parse.php (100%) rename {src/Framework => _old/src/_todo}/Send.php (100%) rename {src/Framework => _old/src/_todo}/SimpleDB.php (100%) rename {src/Framework => _old/src/_todo}/Singleton.php (100%) rename {src/Framework => _old/src/_todo}/Track.php (100%) rename {src/Framework => _old/src/_todo}/TwitterBS.php (100%) rename {src/Framework => _old/src/_todo}/libs/DB.php (89%) rename {src/Framework => _old/src/_todo}/libs/Validate.php (100%) rename src/{Framework => Component/Common}/ClassNameReference.php (96%) rename src/{Framework => Component/Common}/ContainerInterface.php (95%) rename src/{Framework => Component/Common/Locale}/Lang.php (79%) rename src/{Framework => Component/Common/Locale}/LanguageSelector.php (78%) rename src/{Framework => Component/Common}/Matroska.php (87%) create mode 100755 src/Component/Common/Model/Collection.php rename src/Framework/{ => Controller}/Controller.php (92%) rename src/Framework/{ => File/Image}/ResizeImage.php (96%) rename src/Framework/{ => Form}/Form.php (100%) create mode 100644 src/Framework/Form/Input.php rename src/Framework/{ => Form}/Validate.php (88%) rename src/Framework/{ => Functions}/ArrayFunctions.php (73%) create mode 100644 src/Framework/Functions/Characters.php rename src/Framework/{ => HTTP}/Cookie.php (94%) rename src/Framework/{ => HTTP}/RequestParameterBuilder.php (80%) rename src/Framework/{ => HTTP}/Session.php (76%) create mode 100755 src/Framework/HTTP/Token.php delete mode 100644 src/Framework/Input.php rename src/Framework/{ => Router}/Route.php (94%) rename src/Framework/{ => Router}/RouteFactory.php (92%) rename src/Framework/{ => Router}/Router.php (95%) rename src/Framework/{ => Template}/TemplateBuilder.php (98%) delete mode 100755 src/Framework/Token.php rename src/{Framework => Infrastructure}/DB.php (85%) rename src/{Framework => Infrastructure}/PaginationAdapter.php (93%) rename src/{Framework => Infrastructure}/Query.php (86%) diff --git a/_old/index.php b/_old/index.php index 3a64db9..710bd80 100755 --- a/_old/index.php +++ b/_old/index.php @@ -1,4 +1,7 @@ action($table, $where, $arg = $this->arguments($arg + ['split' => ' AND '])); - $sql = "SELECT {$arg['field']} FROM {$table} WHERE {$action['query']}"; + $sql = "SELECT {$arg['field']} FROM {$table} WHERE {$action['Framework\Infrastructure\Query']}"; if (!$this->exec($sql, $action['values'])) { return $this; } @@ -61,7 +61,7 @@ public function get($table, $where, $arg = []) public function delete($table, $where, $arg = []) { $action = $this->action($table, $where, $arg = $this->arguments($arg + ['split' => ' AND '])); - $sql = "DELETE {$arg['field']} FROM {$table} WHERE {$action['query']}"; + $sql = "DELETE {$arg['field']} FROM {$table} WHERE {$action['Framework\Infrastructure\Query']}"; if (!$this->exec($sql, $action['values'])) { return $this; } @@ -79,7 +79,7 @@ public function insert($table, $fields, $arg = []) public function update($table, $fields, $id, $arg = []) { $action = $this->action($table, $fields, $arg = $this->arguments($arg + ['split' => '`, `'])); - $sql = "UPDATE {$table} SET {$action['query']} WHERE `uid` = {$id}"; + $sql = "UPDATE {$table} SET {$action['Framework\Infrastructure\Query']} WHERE `uid` = {$id}"; if ($this->exec($sql, $action['values'])) { return true; } @@ -127,7 +127,7 @@ private function action($table, $array, $arg) $values[$key] = $value; } - return ['query' => $query, 'values' => $values]; + return ['Framework\Infrastructure\Query' => $query, 'values' => $values]; } return false; diff --git a/src/Framework/libs/Validate.php b/_old/src/_todo/libs/Validate.php similarity index 100% rename from src/Framework/libs/Validate.php rename to _old/src/_todo/libs/Validate.php diff --git a/composer.json b/composer.json index 41b1dae..6e35509 100755 --- a/composer.json +++ b/composer.json @@ -13,6 +13,9 @@ ], "require": { "php": ">=7.2.0", + "ext-json": "*", + "ext-fileinfo": "*", + "ext-gd": "*", "twig/twig": "^2.6" }, "autoload": { diff --git a/src/Framework/ClassNameReference.php b/src/Component/Common/ClassNameReference.php similarity index 96% rename from src/Framework/ClassNameReference.php rename to src/Component/Common/ClassNameReference.php index 3fa7c6c..6d1a073 100644 --- a/src/Framework/ClassNameReference.php +++ b/src/Component/Common/ClassNameReference.php @@ -1,6 +1,6 @@ getLanguage() . '.php')); - Container::setParam(array('path', 'lang', path('lang') . $this->getLanguage() . '.php')); + Container::setParam(array('path', 'Romano\Component\Common\Locale\Lang', path('Romano\Component\Common\Locale\Lang') . $this->getLanguage() . '.php')); Container::setParam(array('path', 'routes', path('url'))); // setup locale language - Lang::set(require path('lang')); + Lang::set(require path('Romano\Component\Common\Locale\Lang')); } public function hasLanguage($language, $languages) diff --git a/src/Framework/Matroska.php b/src/Component/Common/Matroska.php similarity index 87% rename from src/Framework/Matroska.php rename to src/Component/Common/Matroska.php index f06c421..fba22c9 100644 --- a/src/Framework/Matroska.php +++ b/src/Component/Common/Matroska.php @@ -1,8 +1,9 @@ items = $items; + } + + public function add($item) + { + $this->items[] = $item; + } + + public function each(callable $callback): void + { + foreach ($this->items as $key => $item) { + if (false === $callback($item, $key)) { + break; + } + } + } + + public function filter(callable $callback): self + { + return new self(array_filter($this->items, $callback)); + } + + public function map(callable $callback): self + { + $keys = array_keys($this->items); + $items = array_map($callback, $this->items, $keys); + + return new self(array_combine($keys, $items)); + } + + public function getIterator() + { + return new \ArrayIterator($this->items); + } + + public function hasItems(): bool + { + return $this->count() > 0; + } + + public function count(): int + { + return \count($this->items); + } + + public function current() + { + return current($this->items); + } + + public function end() + { + return end($this->items); + } +} diff --git a/src/Framework/Application.php b/src/Framework/Application.php index 8fe8ca6..8b1f19c 100644 --- a/src/Framework/Application.php +++ b/src/Framework/Application.php @@ -2,6 +2,10 @@ namespace Romano\Framework; +use Romano\Component\Common\Matroska; +use Romano\Framework\Router\RouteFactory; +use Romano\Framework\Router\Router; + class Application { private $request; @@ -23,7 +27,7 @@ public function buildProject(): void $path['app'] = 'app/'.$config['app_name'].'/'; $path['src'] = 'src/'; $path['app_config'] = $path['app'].'config/'; - $path['lang'] = $path['app_config'].'Language/'; + $path['Romano\Component\Common\Locale\Lang'] = $path['app_config'].'Language/'; $path['url'] = $path['app_config'].'Url/'; $path['resource'] = $path['src'].'Resources/'; $path['cache'] = $path['src'].'Cache/'; diff --git a/src/Framework/ConfigurationManager.php b/src/Framework/ConfigurationManager.php index ff695d6..d2e741e 100644 --- a/src/Framework/ConfigurationManager.php +++ b/src/Framework/ConfigurationManager.php @@ -2,6 +2,8 @@ namespace Romano\Framework; +use Romano\Component\Common\ContainerInterface; + class ConfigurationManager { private $configuration; diff --git a/src/Framework/Controller.php b/src/Framework/Controller/Controller.php similarity index 92% rename from src/Framework/Controller.php rename to src/Framework/Controller/Controller.php index cf66479..c380e9a 100644 --- a/src/Framework/Controller.php +++ b/src/Framework/Controller/Controller.php @@ -1,6 +1,6 @@ submissions = $_REQUEST; + } + + public function isSubmitted(string $fieldName): bool + { + return $this->get($fieldName) !== null; + } + + public function get($fieldName = '', $default = null) + { + return $this->submissions[$fieldName] ?? $default; + } +} diff --git a/src/Framework/Validate.php b/src/Framework/Form/Validate.php similarity index 88% rename from src/Framework/Validate.php rename to src/Framework/Form/Validate.php index dba0690..d950b0e 100755 --- a/src/Framework/Validate.php +++ b/src/Framework/Form/Validate.php @@ -11,13 +11,18 @@ * dependencies : needs DB layer/wrapper for "checkDB" */ - + +namespace Romano\Framework\Form; + +use Romano\Infrastructure\DB; +use Framework\Infrastructure\Query; +use Romano\Component\Common\Locale\Lang; class Validate { private $gate; private $errors = array(); - private $source = array(); + private $source = array(); private $data = array(); function __construct($data) @@ -25,7 +30,7 @@ function __construct($data) $this->source = $data; } - public function check($item ,$rules = array() ) + public function check($item, $rules = array()) { $this->data[$item] = ''; $this->gate = true; @@ -34,8 +39,8 @@ public function check($item ,$rules = array() ) if ($this->gate === true) { switch ($rule) { case 'required': - if (empty($value) AND $rule_value === true ) { - $this->addError($item ,Lang::get('error.valid.required', array('{{item}}' => $item))); + if (empty($value) AND $rule_value === true) { + $this->addError($item, Lang::get('error.valid.required', array('{{item}}' => $item))); } break; case 'min': @@ -54,11 +59,11 @@ public function check($item ,$rules = array() ) } break; case 'regex': - if (!preg_match($rule_value, $value) ) { + if (!preg_match($rule_value, $value)) { $this->addError($item, Lang::get('error.valid.nomatch', array('{{item}}' => $item))); } break; - case 'db': + case 'Romano\Infrastructure\DB': if (is_array($rule_value)) $this->checkDB($rule_value, strtolower($item), strtolower($value)); break; default: @@ -82,7 +87,7 @@ public function checkDB($array, $where_key, $where_val) { $result = DB::run( Query::table($array['table']) - ->where(array($where_key => $where_val))->build() + ->where(array($where_key => $where_val))->build() )->fetch(); if ($result) { @@ -96,8 +101,7 @@ public function checkDB($array, $where_key, $where_val) case 'active': if ($result['active'] === 1 AND $value === false) { $this->addError($where_key, Lang::get('error.valid.db.active', array('{{item}}' => $where_key))); - } - elseif (empty($result['active']) AND $value === true) { + } elseif (empty($result['active']) AND $value === true) { $this->addError($where_key, Lang::get('error.valid.db.notactive', array('{{item}}' => $where_key))); } break; diff --git a/src/Framework/ArrayFunctions.php b/src/Framework/Functions/ArrayFunctions.php similarity index 73% rename from src/Framework/ArrayFunctions.php rename to src/Framework/Functions/ArrayFunctions.php index 96e92f5..513907d 100755 --- a/src/Framework/ArrayFunctions.php +++ b/src/Framework/Functions/ArrayFunctions.php @@ -1,47 +1,11 @@ array ('ç','æ','œ','á','é','í','ó','ú','à','è','ì','ò','ù','ä','ë','ï','ö','ü','ÿ','â','ê','î','ô','û','å','e','i','ø','u'), - 'to' => array ('c','ae','oe','a','e','i','o','u','a','e','i','o','u','a','e','i','o','u','y','a','e','i','o','u','a','e','i','o','u') - ); - - private static function getChars() - { - return array( - 'specials' => array ("'",'’'), - 'markUp' => array ('(',')','[',']','"','«','»',':','.','?','!',',',';','{','}','`'), - 'html' => array ('<','>','/'), - 'extras' => array ('~','@','$','%','^','&','|','+','='), - 'markDown' => array ('#','-','*'), - 'alfabet' => range('a', 'z'), - 'alfabetCap' => range('A', 'Z'), - 'numbers' => range(0, 9) - ); - } - - /** - * return a glued array from arrays with a mutual key - */ - static public function mergeOnKey($key, $array1, $array2) - { - $r = array(); - // foreach(array_slice(func_get_args(), 1) as &$a) { - // if(array_key_exists($key, $a)) { - // $r[] = $a[$key]; - // continue; - // } - // } - return $r; - } - public static function indexBy($newIndex, array $files) { if (!isset($files[0][$newIndex])) { @@ -77,15 +41,25 @@ private function checkLastKey($rr, $key) return ($key === self::getLastKey($rr)); } - public static function getLastKey($rr) + /** + * @param array $array + * + * @return mixed + */ + public static function getLastKey(array $array) { - end($rr); - return key($rr); + end($array); + return key($array); } - public static function getLastValue($rr) + /** + * @param array $array + * + * @return mixed + */ + public static function getLastValue(array $array) { - return $rr[self::getLastKey($rr)]; + return $array[self::getLastKey($array)]; } /** @@ -101,7 +75,7 @@ public static function getLastValue($rr) * * @return array */ - public static function unflatten(array $array, $prefix = '.') + public static function unflatten(array $array, string $prefix = '.') { $output = []; foreach ($array as $key => $value) { @@ -114,7 +88,7 @@ public static function unflatten(array $array, $prefix = '.') return $output; } - public static function arraySet(&$array, string $keys, $value): array + public static function arraySet(array &$array, string $keys, $value): array { $keys = \explode(self::delimiter, $keys); while (\count($keys) > 1) { diff --git a/src/Framework/Functions/Characters.php b/src/Framework/Functions/Characters.php new file mode 100644 index 0000000..8ee3893 --- /dev/null +++ b/src/Framework/Functions/Characters.php @@ -0,0 +1,23 @@ + array ("'",'’'), + 'markUp' => array ('(',')','[',']','"','«','»',':','.','?','!',',',';','{','}','`'), + 'html' => array ('<','>','/'), + 'extras' => array ('~','@','$','%','^','&','|','+','='), + 'markDown' => array ('#','-','*'), + 'alfabet' => range('a', 'z'), + 'alfabetCap' => range('A', 'Z'), + 'numbers' => range(0, 9) + ); + } +} \ No newline at end of file diff --git a/src/Framework/Cookie.php b/src/Framework/HTTP/Cookie.php similarity index 94% rename from src/Framework/Cookie.php rename to src/Framework/HTTP/Cookie.php index ef18c4d..a92f395 100755 --- a/src/Framework/Cookie.php +++ b/src/Framework/HTTP/Cookie.php @@ -1,6 +1,6 @@ tokenName = $tokenName; + } + + public function generate(): void + { + return Session::set($this->token, md5(uniqid())); + } + + public function check(string $token): bool + { + if (Session::get($this->tokenName) && $token === Session::get($this->tokenName)) { + Session::delete($this->tokenName); + + return true; + } + + return false; + } +} diff --git a/src/Framework/Input.php b/src/Framework/Input.php deleted file mode 100644 index 93f1b8e..0000000 --- a/src/Framework/Input.php +++ /dev/null @@ -1,26 +0,0 @@ -options); } catch (\PDOException $e) { if (DEV_ENV === true) { throw dump($e->getMessage()); } - throw Output::page('500','CONNECTION ERROR'); + throw Output::page('500', 'CONNECTION ERROR'); } } @@ -37,8 +42,8 @@ private function processParams() public static function run(array $process) { $instance = Singleton::getInstance(get_class()); - $instance->query = (string) $process['query']; - $instance->params = (isset($process['params'])?$process['params']:[]); + $instance->query = (string)$process['Framework\Infrastructure\Query']; + $instance->params = (isset($process['params']) ? $process['params'] : []); $instance->stmt = null; $instance->results[] = $process; $instance->processParams(); @@ -63,7 +68,7 @@ public function fetchAllBy($value) public function get($value) { $temp = $this->stmt->fetch($this->fetchMode); - return (isset($temp[$value])) ? $temp[$value] : dump($value.' is not set'); + return (isset($temp[$value])) ? $temp[$value] : dump($value . ' is not set'); } public function getId($id = 'id') diff --git a/src/Framework/PaginationAdapter.php b/src/Infrastructure/PaginationAdapter.php similarity index 93% rename from src/Framework/PaginationAdapter.php rename to src/Infrastructure/PaginationAdapter.php index db41c8c..25c2cbb 100644 --- a/src/Framework/PaginationAdapter.php +++ b/src/Infrastructure/PaginationAdapter.php @@ -1,6 +1,9 @@ true); protected $params = array(); protected $paramKeys = array(); @@ -31,8 +33,8 @@ class Query ); /** - * assembles the queries. - */ + * assembles the queries. + */ private function assembleQuery($array, $arg) { $array = array_filter((array)$array); @@ -58,11 +60,11 @@ private function assembleQuery($array, $arg) $query .= '' . $key . '' . $arg['operator']; // optional key selection - if($arg['type'] == 'params') { + if ($arg['type'] == 'params') { $param = ':' . $key; $this->params[$param] = $value; - } elseif($arg['type'] == '?') { + } elseif ($arg['type'] == '?') { $this->params[] = $value; $param = '?'; @@ -70,8 +72,7 @@ private function assembleQuery($array, $arg) if ($arg['operator'] == ' LIKE ') { $query .= "CONCAT('%', " . $param . ", '%')"; - } - else $query .= $param; + } else $query .= $param; // new line $query .= "\n"; @@ -113,11 +114,11 @@ private function setWhere($whereValue, $arg) { $arg = array_merge($this->arguments, $arg); if ($this->where === true) { - $this->query .= ' ' . $arg['split'] . ' ' . (string) $whereValue; + $this->query .= ' ' . $arg['split'] . ' ' . (string)$whereValue; return; } $this->where = true; - $this->query .= ' WHERE ' . (string) $whereValue; + $this->query .= ' WHERE ' . (string)$whereValue; } public function where(array $where, $arg = array()) @@ -132,7 +133,7 @@ public function where(array $where, $arg = array()) static public function table($table, $nick = null) { - if ((string) $table) { + if ((string)$table) { $instance = new Query(); $instance->table = $table; $instance->startQuery('SELECT * FROM ' . $table); @@ -174,9 +175,9 @@ public function delete(array $where, $arg = array()) public function insert($fields = array(), $arg = array()) { - $this->assembleQuery((array) $fields, $arg = array_merge($this->arguments, $arg)); + $this->assembleQuery((array)$fields, $arg = array_merge($this->arguments, $arg)); - $placeholder = ($this->settings['namedParams'] === false) ? array_fill(0, count($this->paramKeys), '?') : array_keys($this->params); + $placeholder = ($this->settings['namedParams'] === false) ? array_fill(0, count($this->paramKeys), '?') : array_keys($this->params); $this->startQuery('INSERT INTO ' . $this->table . $this->sqlImplode($this->paramKeys, '`', '`') . 'VALUES' . @@ -187,7 +188,9 @@ public function insert($fields = array(), $arg = array()) public function sqlImplode(array $arr, $in = '', $out = '', $segment = ', ') { - array_walk($arr, function(&$x) use ($in, $out){ $x = $in . $x . $out; }); + array_walk($arr, function (&$x) use ($in, $out) { + $x = $in . $x . $out; + }); return ' (' . implode($segment, $arr) . ') '; } @@ -201,7 +204,7 @@ public function update($fields = array(), $arg = array()) public function build() { return array( - 'query' => $this->startQuery . $this->query . $this->endQuery, + 'Framework\Infrastructure\Query' => $this->startQuery . $this->query . $this->endQuery, 'params' => $this->params ); } @@ -217,7 +220,7 @@ public function save($fields = array(), $id = 'id') { $query = $this->assembleQuery($fields, $arg = array_merge($this->arguments, array('type' => 'noParams'))); $this->startQuery('INSERT INTO ' . $this->table . ' ' . $query); - if(in_array($id, array_flip($fields))) unset($fields[$id]); else exit('query::save no id in fields'); + if (in_array($id, array_flip($fields))) unset($fields[$id]); else exit('query::save no id in fields'); $q = "\n"; foreach ($fields as $key => $value) { diff --git a/tests/spec/Framework/ConfigurationManagerSpec.php b/tests/spec/Framework/ConfigurationManagerSpec.php index 8a7eec6..5c77ff5 100644 --- a/tests/spec/Framework/ConfigurationManagerSpec.php +++ b/tests/spec/Framework/ConfigurationManagerSpec.php @@ -4,7 +4,7 @@ use Romano\Framework\ConfigurationManager; use PhpSpec\ObjectBehavior; -use Romano\Framework\ContainerInterface; +use Romano\Component\Common\ContainerInterface; class ConfigurationManagerSpec extends ObjectBehavior { diff --git a/tests/unit/Framework/ApplicationTest.php b/tests/unit/Framework/ApplicationTest.php index 8387183..778d748 100644 --- a/tests/unit/Framework/ApplicationTest.php +++ b/tests/unit/Framework/ApplicationTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Romano\Framework\Application; -use Romano\Framework\Matroska; +use Romano\Component\Common\Matroska; class ApplicationTest extends TestCase { @@ -35,7 +35,7 @@ public function it_should_build_the_path_array(): void 'app' => 'app/blog/', 'src'=> 'src/', 'app_config' => 'app/blog/config/', - 'lang' => 'app/blog/config/Language/', + 'Romano\Component\Common\Locale\Lang' => 'app/blog/config/Language/', 'url' => 'app/blog/config/Url/', 'resource' => 'src/Resources/', 'cache' => 'src/Cache/', diff --git a/tests/unit/Framework/MatroskaTest.php b/tests/unit/Framework/MatroskaTest.php index 3cc232e..2b8c019 100644 --- a/tests/unit/Framework/MatroskaTest.php +++ b/tests/unit/Framework/MatroskaTest.php @@ -12,7 +12,7 @@ namespace Tests\Romano\Framework\Utils; use PHPUnit\Framework\TestCase; -use Romano\Framework\Matroska; +use Romano\Component\Common\Matroska; class MatroskaTest extends TestCase { diff --git a/web/index.php b/web/index.php index 2cb4d61..17330c9 100644 --- a/web/index.php +++ b/web/index.php @@ -3,7 +3,7 @@ require __DIR__.'/../vendor/autoload.php'; require __DIR__.'/../app/config.php'; -use \Romano\Framework\Request; +use \Romano\Framework\HTTP\Request; use \Romano\Framework\Application; $request = new Request();