From d5f15957bae8e123b15866eb25f01fdd601ae952 Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Mon, 17 Aug 2020 10:13:31 +0100 Subject: [PATCH 1/7] Implement ADR --- decisionlog.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 decisionlog.md diff --git a/decisionlog.md b/decisionlog.md new file mode 100644 index 0000000..8d89fdf --- /dev/null +++ b/decisionlog.md @@ -0,0 +1,14 @@ +# ADR + +An Architectural Decision (AD) is a software design choice that addresses a functional or non-functional requirement that is architecturally significant. An Architecturally Significant Requirement (ASR) is a requirement that has a measurable effect on a software system’s architecture and quality. An Architectural Decision Record (ADR) captures a single AD, such as often done when writing personal notes or meeting minutes; the collection of ADRs created and maintained in a project constitute its decision log. All these are within the topic of Architectural Knowledge Management (AKM). + +## Overall goals + +A) Strive to simplify. +B) Everyone contributes. + + +# Decision Record + +- 001 Developers run Cuttlefish via the included PHP webserver. Supports simplicity. +- 002 Support static and dynamic deployments. From de9393294014bd654183055d369326ff892c03e2 Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Mon, 17 Aug 2020 10:16:42 +0100 Subject: [PATCH 2/7] use /plugins as the external code directory --- src/Environment.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index 4d28de7..6f78810 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -18,7 +18,7 @@ public function __construct() } // Externals environment - $this->registerExternals(); + $this->registerPlugins(); session_start(); } @@ -63,9 +63,9 @@ public function writeHtaccess(): void fclose($fp); } - protected function registerExternals(): void + protected function registerPlugins(): void { - $Files = new Files(array( 'url' => '/system/Ext' ), 'php'); + $Files = new Files(array( 'url' => '/plugins' ), 'php'); foreach ($Files->files() as $key => $filepath) { $this->register[ pathinfo($filepath, PATHINFO_FILENAME) ] = true; $this->addIncludePath(pathinfo($filepath, PATHINFO_DIRNAME)); From fb1691b7fef1346538345cab6dfee11b48bb88ee Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Mon, 17 Aug 2020 10:19:02 +0100 Subject: [PATCH 3/7] Add plugin interface --- src/iPlugin.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/iPlugin.php diff --git a/src/iPlugin.php b/src/iPlugin.php new file mode 100644 index 0000000..43cdb7c --- /dev/null +++ b/src/iPlugin.php @@ -0,0 +1,9 @@ + Date: Sun, 23 Aug 2020 23:11:52 +0100 Subject: [PATCH 4/7] Reintegrate blog --- composer.json | 7 ++- composer.lock | 36 +++++++---- src/blog/ControllerAdmin.php | 109 +++++++++++++++++++++++++++++++++ src/blog/ControllerArchive.php | 42 +++++++++++++ src/blog/ControllerError.php | 45 ++++++++++++++ src/blog/ControllerFeed.php | 41 +++++++++++++ src/blog/ControllerHome.php | 45 ++++++++++++++ src/blog/ControllerImage.php | 39 ++++++++++++ src/blog/ControllerPage.php | 44 +++++++++++++ src/blog/ControllerPost.php | 44 +++++++++++++ src/blog/ModelFile.php | 21 +++++++ src/blog/ModelPage.php | 24 ++++++++ src/blog/ModelPost.php | 35 +++++++++++ src/blog/functions.php | 12 ++++ src/blog/template-post.md | 8 +++ src/view_functions.php | 4 +- 16 files changed, 537 insertions(+), 19 deletions(-) create mode 100644 src/blog/ControllerAdmin.php create mode 100644 src/blog/ControllerArchive.php create mode 100644 src/blog/ControllerError.php create mode 100644 src/blog/ControllerFeed.php create mode 100644 src/blog/ControllerHome.php create mode 100644 src/blog/ControllerImage.php create mode 100644 src/blog/ControllerPage.php create mode 100644 src/blog/ControllerPost.php create mode 100644 src/blog/ModelFile.php create mode 100644 src/blog/ModelPage.php create mode 100644 src/blog/ModelPost.php create mode 100644 src/blog/functions.php create mode 100644 src/blog/template-post.md diff --git a/composer.json b/composer.json index b151baa..fa559ec 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ }, "autoload": { "psr-4": { - "Cuttlefish\\": "src" + "Cuttlefish\\": "src", + "Cuttlefish\\Blog\\": "src/blog" } }, "config": { @@ -35,7 +36,7 @@ ], "prep": [ "phpcbf", - "psalm --alter --issues=all", + "psalm --alter", "@lint" ], "lint": [ @@ -44,4 +45,4 @@ "phpcs" ] } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 72131c4..358acf3 100644 --- a/composer.lock +++ b/composer.lock @@ -63,12 +63,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "57353ec1a34527a2dbbd3c0fb9418ffc008c6f60" + "reference": "89bed6788d61977969b89d912b5844e8beee09f0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/57353ec1a34527a2dbbd3c0fb9418ffc008c6f60", - "reference": "57353ec1a34527a2dbbd3c0fb9418ffc008c6f60", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/89bed6788d61977969b89d912b5844e8beee09f0", + "reference": "89bed6788d61977969b89d912b5844e8beee09f0", "shasum": "" }, "conflict": { @@ -135,14 +135,16 @@ "friendsofsymfony/oauth2-php": "<1.3", "friendsofsymfony/rest-bundle": ">=1.2,<1.2.2", "friendsofsymfony/user-bundle": ">=1.2,<1.3.5", + "friendsoftypo3/mediace": ">=7.6.2,<7.6.5", "fuel/core": "<1.8.1", "getgrav/grav": "<1.7-beta.8", + "gos/web-socket-bundle": "<1.10.4|>=2,<2.6.1|>=3,<3.3", "gree/jose": "<=2.2", "gregwar/rst": "<1.0.3", "guzzlehttp/guzzle": ">=4-rc.2,<4.2.4|>=5,<5.3.1|>=6,<6.2.1", "illuminate/auth": ">=4,<4.0.99|>=4.1,<=4.1.31|>=4.2,<=4.2.22|>=5,<=5.0.35|>=5.1,<=5.1.46|>=5.2,<=5.2.45|>=5.3,<=5.3.31|>=5.4,<=5.4.36|>=5.5,<5.5.10", - "illuminate/cookie": ">=4,<=4.0.11|>=4.1,<=4.1.31|>=4.2,<=4.2.22|>=5,<=5.0.35|>=5.1,<=5.1.46|>=5.2,<=5.2.45|>=5.3,<=5.3.31|>=5.4,<=5.4.36|>=5.5,<5.5.42|>=5.6,<5.6.30", - "illuminate/database": ">=4,<4.0.99|>=4.1,<4.1.29", + "illuminate/cookie": ">=4,<=4.0.11|>=4.1,<=4.1.99999|>=4.2,<=4.2.99999|>=5,<=5.0.99999|>=5.1,<=5.1.99999|>=5.2,<=5.2.99999|>=5.3,<=5.3.99999|>=5.4,<=5.4.99999|>=5.5,<=5.5.49|>=5.6,<=5.6.99999|>=5.7,<=5.7.99999|>=5.8,<=5.8.99999|>=6,<6.18.31|>=7,<7.22.4", + "illuminate/database": ">=4,<4.0.99|>=4.1,<4.1.29|>=5.5,<=5.5.44|>=6,<6.18.34|>=7,<7.23.2", "illuminate/encryption": ">=4,<=4.0.11|>=4.1,<=4.1.31|>=4.2,<=4.2.22|>=5,<=5.0.35|>=5.1,<=5.1.46|>=5.2,<=5.2.45|>=5.3,<=5.3.31|>=5.4,<=5.4.36|>=5.5,<5.5.40|>=5.6,<5.6.15", "illuminate/view": ">=7,<7.1.2", "ivankristianto/phpwhois": "<=4.3", @@ -150,9 +152,10 @@ "joomla/session": "<1.3.1", "jsmitty12/phpwhois": "<5.1", "kazist/phpwhois": "<=4.2.6", + "kitodo/presentation": "<3.1.2", "kreait/firebase-php": ">=3.2,<3.8.1", "la-haute-societe/tcpdf": "<6.2.22", - "laravel/framework": ">=4,<4.0.99|>=4.1,<=4.1.31|>=4.2,<=4.2.22|>=5,<=5.0.35|>=5.1,<=5.1.46|>=5.2,<=5.2.45|>=5.3,<=5.3.31|>=5.4,<=5.4.36|>=5.5,<5.5.42|>=5.6,<5.6.30|>=7,<7.1.2", + "laravel/framework": ">=4,<4.0.99|>=4.1,<=4.1.99999|>=4.2,<=4.2.99999|>=5,<=5.0.99999|>=5.1,<=5.1.99999|>=5.2,<=5.2.99999|>=5.3,<=5.3.99999|>=5.4,<=5.4.99999|>=5.5,<=5.5.49|>=5.6,<=5.6.99999|>=5.7,<=5.7.99999|>=5.8,<=5.8.99999|>=6,<6.18.34|>=7,<7.23.2", "laravel/socialite": ">=1,<1.0.99|>=2,<2.0.10", "league/commonmark": "<0.18.3", "librenms/librenms": "<1.53", @@ -160,14 +163,20 @@ "magento/magento1ce": "<1.9.4.3", "magento/magento1ee": ">=1,<1.14.4.3", "magento/product-community-edition": ">=2,<2.2.10|>=2.3,<2.3.2-p.2", + "marcwillmann/turn": "<0.3.3", + "mittwald/typo3_forum": "<1.2.1", "monolog/monolog": ">=1.8,<1.12", "namshi/jose": "<2.2", "nystudio107/craft-seomatic": "<3.3", "nzo/url-encryptor-bundle": ">=4,<4.3.2|>=5,<5.0.1", - "october/october": ">=1.0.319,<1.0.467", + "october/backend": ">=1.0.319,<1.0.467", + "october/cms": ">=1.0.319,<1.0.466", + "october/october": ">=1.0.319,<1.0.466", + "october/rain": ">=1.0.319,<1.0.468", "onelogin/php-saml": "<2.10.4", "oneup/uploader-bundle": "<1.9.3|>=2,<2.1.5", "openid/php-openid": "<2.3", + "openmage/magento-lts": "<19.4.6|>=20,<20.0.2", "oro/crm": ">=1.7,<1.7.4", "oro/platform": ">=1.7,<1.7.4", "padraic/humbug_get_contents": "<1.1.2", @@ -204,8 +213,8 @@ "silverstripe/cms": "<4.3.6|>=4.4,<4.4.4", "silverstripe/comments": ">=1.3,<1.9.99|>=2,<2.9.99|>=3,<3.1.1", "silverstripe/forum": "<=0.6.1|>=0.7,<=0.7.3", - "silverstripe/framework": "<4.4.5|>=4.5,<4.5.2", - "silverstripe/graphql": ">=2,<2.0.5|>=3,<3.1.2", + "silverstripe/framework": "<4.4.7|>=4.5,<4.5.4", + "silverstripe/graphql": ">=2,<2.0.5|>=3,<3.1.2|>=3.2,<3.2.4", "silverstripe/registry": ">=2.1,<2.1.2|>=2.2,<2.2.1", "silverstripe/restfulserver": ">=1,<1.0.9|>=2,<2.0.4", "silverstripe/subsites": ">=2,<2.1.1", @@ -224,11 +233,12 @@ "ssddanbrown/bookstack": "<0.29.2", "stormpath/sdk": ">=0,<9.9.99", "studio-42/elfinder": "<2.1.49", + "sulu/sulu": "<1.6.34|>=2,<2.0.10|>=2.1,<2.1.1", "swiftmailer/swiftmailer": ">=4,<5.4.5", "sylius/admin-bundle": ">=1,<1.0.17|>=1.1,<1.1.9|>=1.2,<1.2.2", "sylius/grid": ">=1,<1.1.19|>=1.2,<1.2.18|>=1.3,<1.3.13|>=1.4,<1.4.5|>=1.5,<1.5.1", "sylius/grid-bundle": ">=1,<1.1.19|>=1.2,<1.2.18|>=1.3,<1.3.13|>=1.4,<1.4.5|>=1.5,<1.5.1", - "sylius/resource-bundle": "<1.3.13|>=1.4,<1.4.6|>=1.5,<1.5.1|>=1.6,<1.6.3", + "sylius/resource-bundle": "<1.3.14|>=1.4,<1.4.7|>=1.5,<1.5.2|>=1.6,<1.6.4", "sylius/sylius": "<1.3.16|>=1.4,<1.4.12|>=1.5,<1.5.9|>=1.6,<1.6.5", "symbiote/silverstripe-multivaluefield": ">=3,<3.0.99", "symbiote/silverstripe-versionedfiles": "<=2.0.3", @@ -267,8 +277,8 @@ "titon/framework": ">=0,<9.9.99", "truckersmp/phpwhois": "<=4.3.1", "twig/twig": "<1.38|>=2,<2.7", - "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.30|>=9,<9.5.17|>=10,<10.4.2", - "typo3/cms-core": ">=8,<8.7.30|>=9,<9.5.17|>=10,<10.4.2", + "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.32|>=8,<8.7.30|>=9,<9.5.20|>=10,<10.4.6", + "typo3/cms-core": ">=8,<8.7.30|>=9,<9.5.20|>=10,<10.4.6", "typo3/flow": ">=1,<1.0.4|>=1.1,<1.1.1|>=2,<2.0.1|>=2.3,<2.3.16|>=3,<3.0.10|>=3.1,<3.1.7|>=3.2,<3.2.7|>=3.3,<3.3.5", "typo3/neos": ">=1.1,<1.1.3|>=1.2,<1.2.13|>=2,<2.0.4", "typo3/phar-stream-wrapper": ">=1,<2.1.1|>=3,<3.1.1", @@ -341,7 +351,7 @@ "type": "tidelift" } ], - "time": "2020-07-03T16:50:03+00:00" + "time": "2020-08-19T19:01:52+00:00" } ], "aliases": [], diff --git a/src/blog/ControllerAdmin.php b/src/blog/ControllerAdmin.php new file mode 100644 index 0000000..ad84024 --- /dev/null +++ b/src/blog/ControllerAdmin.php @@ -0,0 +1,109 @@ + 'Overview', + 'clearCache' => 'Clear cache', + 'generateSite' => 'Generate static site', + 'logout' => 'Logout', + ); + + // admin section does not use content files + protected string $contents; + + protected function isAllowedMethod($action): bool + { + return array_key_exists($action, $this->allowed_methods); + } + + protected function showTasks(): string + { + $output = '
    '; + $am = $this->allowed_methods; + array_shift($am); + foreach ($am as $key => $value) : + $Url = new Cuttlefish\Url("/admin/$key"); + $output .= sprintf('
  • %s
  • ', $Url->url_absolute, $value); + endforeach; + + $output .= '
'; + + return $output; + } + + protected function showLogin(): string + { + return App::getInstance()->Security->login(); + } + + protected function clearCache() + { + $App = App::getInstance(); + $App->Security->maybeLoginRedirect(); + + return $App->Cache->clear(); + } + + protected function generateSite(): void + { + $App = App::getInstance(); + $App->Security->maybeLoginRedirect(); + echo $App->Cache->generateSite(); + } + + + /** + * @return void + */ + public function init() + { + App::getInstance()->Cache->abort(); + + $action = ( isset($this->args[0]) ) ? $this->args[0] : 'index'; + if ($this->isAllowedMethod($action)) { + $this->contents = $this->$action(); + } else { + exit("Method $action is not allowed"); + } + + parent::init(); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + + $this->View = new Html($this->contents, array( + 'layout' => 'layout.php', + 'controller' => 'admin', + 'model' => 'page', + )); + } + + public function index(): string + { + if (App::getInstance()->Security->isLoggedIn()) { + return $this->showTasks(); + } + + return $this->showLogin(); + } + + public function logout() + { + $App = App::getInstance(); + $App->Security->maybeLoginRedirect(); + + return $App->Security->logout(); + } +} diff --git a/src/blog/ControllerArchive.php b/src/blog/ControllerArchive.php new file mode 100644 index 0000000..7878f94 --- /dev/null +++ b/src/blog/ControllerArchive.php @@ -0,0 +1,42 @@ + $content_dir ), $this->ext); + $this->records = $Files->files(); + } + + /** + * @return void + */ + public function model() + { + $this->Model = new ModelPost($this->records); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + $this->View = new Html($this->Model->contents, array( + 'layout' => 'layout.php', + 'controller' => 'archive', + 'model' => 'post', + )); + } +} diff --git a/src/blog/ControllerError.php b/src/blog/ControllerError.php new file mode 100644 index 0000000..e1b006a --- /dev/null +++ b/src/blog/ControllerError.php @@ -0,0 +1,45 @@ +args) . '.' . $this->ext; + $this->records = [ Filesystem::convertUrlToPath($url) ]; + } + + /** + * @return void + */ + public function model() + { + $this->Model = new ModelPage($this->records); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + + $this->View = new Html($this->Model->contents, array( + 'layout' => 'layout.php', + 'controller' => 'errors', + 'model' => 'page', + )); + } +} diff --git a/src/blog/ControllerFeed.php b/src/blog/ControllerFeed.php new file mode 100644 index 0000000..5b1c4c4 --- /dev/null +++ b/src/blog/ControllerFeed.php @@ -0,0 +1,41 @@ + $content_dir ), $this->ext); + $this->records = $Records->limit($limit + 5); + } + + /** + * @return void + */ + public function model() + { + $Model = new ModelPost($this->records); + $this->Model = $Model->limit(10); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + $this->View = new Feed($this->Model->contents); + } +} diff --git a/src/blog/ControllerHome.php b/src/blog/ControllerHome.php new file mode 100644 index 0000000..d339008 --- /dev/null +++ b/src/blog/ControllerHome.php @@ -0,0 +1,45 @@ + $content_dir ), $this->ext); + $this->records = $Files->limit($limit + 5); + } + + /** + * @return void + */ + public function model() + { + $Model = new ModelPost($this->records); + $this->Model = $Model->limit(Configuration::POSTS_HOMEPAGE); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + $this->View = new Html($this->Model->contents, array( + 'layout' => 'layout.php', + 'controller' => 'home', + 'model' => 'post', + )); + } +} diff --git a/src/blog/ControllerImage.php b/src/blog/ControllerImage.php new file mode 100644 index 0000000..6566434 --- /dev/null +++ b/src/blog/ControllerImage.php @@ -0,0 +1,39 @@ +records = [ Filesystem::convertUrlToPath($content_dir . implode('/', $this->args)) ]; + } + + /** + * @return void + */ + public function model() + { + $this->Model = new ModelFile($this->records); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + $this->View = new File($this->Model->contents[0]); + $this->View->render(); + } +} diff --git a/src/blog/ControllerPage.php b/src/blog/ControllerPage.php new file mode 100644 index 0000000..090b049 --- /dev/null +++ b/src/blog/ControllerPage.php @@ -0,0 +1,44 @@ +args) . '.' . $this->ext; + $this->records = [ Filesystem::convertUrlToPath($url) ]; + } + + /** + * @return void + */ + public function model() + { + $this->Model = new ModelPage($this->records); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + + $this->View = new Html($this->Model->contents, array( + 'layout' => 'layout.php', + 'controller' => 'pages', + 'model' => 'page', + )); + } +} diff --git a/src/blog/ControllerPost.php b/src/blog/ControllerPost.php new file mode 100644 index 0000000..775a193 --- /dev/null +++ b/src/blog/ControllerPost.php @@ -0,0 +1,44 @@ +args) . '.' . $this->ext; + $this->records = [ Filesystem::convertUrlToPath($url) ]; + } + + /** + * @return void + */ + public function model() + { + $this->Model = new ModelPost($this->records); + } + + /** + * @return void + */ + public function view() + { + parent::view(); + + $this->View = new Html($this->Model->contents, array( + 'layout' => 'layout.php', + 'controller' => 'posts', + 'model' => 'post', + )); + } +} diff --git a/src/blog/ModelFile.php b/src/blog/ModelFile.php new file mode 100644 index 0000000..11ac036 --- /dev/null +++ b/src/blog/ModelFile.php @@ -0,0 +1,21 @@ +contents = $records; + } +} diff --git a/src/blog/ModelPage.php b/src/blog/ModelPage.php new file mode 100644 index 0000000..20f8dcc --- /dev/null +++ b/src/blog/ModelPage.php @@ -0,0 +1,24 @@ + 'content', + ); + + /** + * @return void + */ + public function contents($records) + { + foreach ($records as $record) { + $this->contents[] = $this->listContents($record); + } + } +} diff --git a/src/blog/ModelPost.php b/src/blog/ModelPost.php new file mode 100644 index 0000000..f4d560c --- /dev/null +++ b/src/blog/ModelPost.php @@ -0,0 +1,35 @@ + 'metadata', + 'markdown|html' => 'content', + ); + + /** + * @return int + */ + public function sortByPublished($a, $b) + { + return strcmp($b->metadata->Published, $a->metadata->Published); + } + + /** + * @return self + */ + public function contents($records) + { + foreach ($records as $record) { + $this->contents[] = $this->listContents($record); + } + usort($this->contents, array( $this, 'sortByPublished' )); + + return $this; + } +} diff --git a/src/blog/functions.php b/src/blog/functions.php new file mode 100644 index 0000000..68992b0 --- /dev/null +++ b/src/blog/functions.php @@ -0,0 +1,12 @@ +Security->isLoggedIn(); + return Cuttlefish\App::getInstance()->Security->isLoggedIn(); } From e80c24563585c08d09d8c23012a890b962139788 Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Sun, 23 Aug 2020 23:15:28 +0100 Subject: [PATCH 5/7] App is a singleton. --- decisionlog.md | 6 ++++-- src/App.php | 18 ++++++++++++++++++ src/Cache.php | 3 +-- src/File.php | 12 ++++++------ src/Files.php | 10 +++++----- src/Router.php | 1 + src/Template.php | 10 +++++----- src/iPlugin.php | 5 +++-- 8 files changed, 43 insertions(+), 22 deletions(-) diff --git a/decisionlog.md b/decisionlog.md index 8d89fdf..ca9d8c6 100644 --- a/decisionlog.md +++ b/decisionlog.md @@ -10,5 +10,7 @@ B) Everyone contributes. # Decision Record -- 001 Developers run Cuttlefish via the included PHP webserver. Supports simplicity. -- 002 Support static and dynamic deployments. +Decision IDs are auto incremented. IDs not in the document no longer apply. + +- 003 Cuttlefish only generates static websites. +- 004 A content project consists of content assets and a php configuration file. All other code is in this project. diff --git a/src/App.php b/src/App.php index 8243d17..3bc38c6 100644 --- a/src/App.php +++ b/src/App.php @@ -10,6 +10,8 @@ class App public $Cache; public $Environment; + private static $instance = null; + public function __construct() { $this->Cache = new Cache(); @@ -40,4 +42,20 @@ public function run(array $routes) new Router($routes); $this->Cache->end(); } + + + /** + * Singleton. The object is created from within the class itself + * only if the class has no instance. + * + * @return void + */ + public static function getInstance() + { + if (self::$instance == null) { + self::$instance = new App(); + } + + return self::$instance; + } } diff --git a/src/Cache.php b/src/Cache.php index d2bb8b8..ce4921d 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -148,7 +148,6 @@ public function hasExistingCachefile() */ public function clear() { - global $App; $dir = $this->getCacheFolder(); $output = sprintf('Removing all files in %s
', $dir); $Files = new Files(array( 'path' => $dir )); @@ -157,7 +156,7 @@ public function clear() foreach ($dirs as $dir) { Filesystem::removeDirs(realpath($dir . '/.')); } - $App->Environment->writeHtaccess(); + App::getInstance()->Environment->writeAccess(); return (string) $output; } diff --git a/src/File.php b/src/File.php index 69df352..7fdc517 100644 --- a/src/File.php +++ b/src/File.php @@ -69,10 +69,10 @@ public function relative(): self return $this; } - public function render(): void - { - $mime = $this->mime; - header("Content-Type: $mime"); - readfile($this->path); - } + public function render(): void + { + $mime = $this->mime; + header("Content-Type: $mime"); + readfile($this->path); + } } diff --git a/src/Files.php b/src/Files.php index 5a064ec..407b9e7 100644 --- a/src/Files.php +++ b/src/Files.php @@ -55,12 +55,12 @@ protected function collect(string $dir = ".", $filter = null): array return $files; } - public function limit(int $max): array - { - $this->files = array_slice($this->files, 0, $max); + public function limit(int $max): array + { + $this->files = array_slice($this->files, 0, $max); - return $this->files; - } + return $this->files; + } public function removeAll(): string { diff --git a/src/Router.php b/src/Router.php index 9946481..47ab324 100644 --- a/src/Router.php +++ b/src/Router.php @@ -24,6 +24,7 @@ public function __construct($routes) if (isset($routes[$args[1]])) { $controller_class = $routes[$args[1]]; } + $controller_arguments = array_slice($args, 2); if (class_exists($controller_class, true)) { $this->Controller = new $controller_class($this, $controller_arguments); diff --git a/src/Template.php b/src/Template.php index e100a2a..c8e3984 100644 --- a/src/Template.php +++ b/src/Template.php @@ -15,14 +15,14 @@ public function __construct($file, $args = array()) $this->args = $args; } - public function __get($name) - { - return $this->args[ $name ]; - } + public function __get($name) + { + return $this->args[ $name ]; + } public function render(): void { - $path = BASE_FILEPATH . trim(theme_dir(),'/') . "/views" . DIRECTORY_SEPARATOR . $this->file; + $path = BASE_FILEPATH . trim(theme_dir(), '/') . "/views" . DIRECTORY_SEPARATOR . $this->file; require $path; } } diff --git a/src/iPlugin.php b/src/iPlugin.php index 43cdb7c..0759934 100644 --- a/src/iPlugin.php +++ b/src/iPlugin.php @@ -2,8 +2,9 @@ namespace Cuttlefish; -interface iPlugin { +interface IPlugin +{ public function load($pluginConfiguration); public function run(); public function unload(); -} \ No newline at end of file +} From bf374f39f3acfa17251e4b7a72f1a72acb47836b Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Sun, 23 Aug 2020 23:28:19 +0100 Subject: [PATCH 6/7] add route fallback --- src/Defaults.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Defaults.php b/src/Defaults.php index 8a581ee..545f360 100644 --- a/src/Defaults.php +++ b/src/Defaults.php @@ -21,4 +21,6 @@ class Defaults public const CONTENT_FOLDER = '../content'; public const LOGS_FOLDER = '../_logs'; public const THEMES_FOLDER = 'themes'; + + const routes = []; } From b15940b64b00b3d221cbc6c8de8f0e9a01311357 Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Sun, 23 Aug 2020 23:28:36 +0100 Subject: [PATCH 7/7] Missing route error --- src/Router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Router.php b/src/Router.php index 47ab324..fa7b945 100644 --- a/src/Router.php +++ b/src/Router.php @@ -72,6 +72,9 @@ protected function classNotCallable($controller_class): void { $Url = new Url('/errors/404'); $log_message = "Not callable '$controller_class' or missing parameter."; + if (empty($controller_class)) { + $log_message = "Missing route"; + } $this->redirect($Url, $log_message); } @@ -85,7 +88,7 @@ protected function classNotCallable($controller_class): void */ protected function redirect($Url, string $log_message): void { - echo( "Location: " . $Url->url_absolute ); + echo( "Location: " . $Url->url_absolute . PHP_EOL ); exit($log_message); } }