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 +}