From 2813e300f62e1900608aba6a15a8815f305b5057 Mon Sep 17 00:00:00 2001 From: ElbertF Date: Sat, 11 Feb 2012 17:30:03 +1100 Subject: [PATCH] Minor code and documentation fixes --- README.md | 35 +++++++++++++-------------- Swiftlet/App.php | 39 ++++++++++++++++--------------- Swiftlet/Controllers/Error404.php | 2 +- Swiftlet/Controllers/Index.php | 2 +- Swiftlet/Interfaces/App.php | 6 ++--- Swiftlet/Model.php | 1 + Swiftlet/Models/Example.php | 4 ---- Swiftlet/Plugin.php | 1 + Swiftlet/View.php | 4 +--- config.php | 2 +- index.php | 1 + robots.txt | 2 +- 12 files changed, 47 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index a4fd7c7..3b9534a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Buzzword compliance ------------------- ✔ Micro-Framework -✔ Loosely coupled +✔ Loosely coupled ✔ Namespaced ✔ Unit tested ✔ Pluggable @@ -42,7 +42,7 @@ Controllers house the [business logic](http://en.wikipedia.org/wiki/Business_logic) of the page while views should be limited to simple UI logic (loops and switches). -**Controller `lib/Swiftlet/Controllers/Foo.php`** +**Controller `Swiftlet/Controllers/Foo.php`** ```php app->getAction()` and `$this->app->getArgs()` respectively. -Note: if you want to use a different view for each action you can change the -value of `$this->view->name`. +Note: to use a different view for each action you may change the value of +`$this->view->name`. The view name is a filename relative to the `view` +directory, without the `.html.php` suffix. Models @@ -126,7 +127,7 @@ Models Let's throw a model into the mix and update the controller. -**Model `lib/Swiftlet/Models/Foo.php`** +**Model `Swiftlet/Models/Foo.php`** ```php app->getModel('example'); $helloWorld = $exampleModel->getHelloWorld(); @@ -181,7 +182,7 @@ points for code that extends the application. Swiftlet has a few core hooks but they can be registered pretty much anywhere using `$this->app->registerHook($hookName)`. -**Plugin `lib/Swiftlet/Plugins/Foo.php`** +**Plugin `Swiftlet/Plugins/Foo.php`** ```php view->render(); } + /** + * Get a configuration value + * @param string $variabl + * @return mixed + */ + public function getConfig($variable) + { + if ( isset($this->config[$variable]) ) { + return $this->config[$variable]; + } + } + /** * Set a configuration value * @param string $variable @@ -125,15 +137,12 @@ public function setConfig($variable, $value) } /** - * Get a configuration value - * @param string $variabl - * @return mixed + * Get the client-side path to root + * @return string */ - public function getConfig($variable) - { - if ( isset($this->config[$variable]) ) { - return $this->config[$variable]; - } + public function getRootPath() + { + return $this->rootPath; } /** @@ -186,16 +195,7 @@ public function getSingleton($modelName) } /** - * Get the client-side path to root - * @return string - */ - public function getRootPath() - { - return $this->rootPath; - } - - /** - * Register a new hook for plugins to implement + * Register a hook for plugins to implement * @param string $hookName * @param array $params */ @@ -216,6 +216,7 @@ public function registerHook($hookName, array $params = array()) /** * Class autoloader + * @param $className * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md */ public function autoload($className) diff --git a/Swiftlet/Controllers/Error404.php b/Swiftlet/Controllers/Error404.php index 94d28e5..a4ec232 100644 --- a/Swiftlet/Controllers/Error404.php +++ b/Swiftlet/Controllers/Error404.php @@ -22,6 +22,6 @@ public function index() */ public function notImplemented() { - $this->indexAction(); + $this->index(); } } diff --git a/Swiftlet/Controllers/Index.php b/Swiftlet/Controllers/Index.php index bfe8515..dd11b09 100644 --- a/Swiftlet/Controllers/Index.php +++ b/Swiftlet/Controllers/Index.php @@ -15,7 +15,7 @@ public function index() { // Some example code to get you started - // Create a model instance, see /models/ExampleModel.php + // Create a model instance, see /Swiftlet/Models/Example.php $exampleModel = $this->app->getModel('example'); // Get some data from the model diff --git a/Swiftlet/Interfaces/App.php b/Swiftlet/Interfaces/App.php index 3070de8..2acd806 100644 --- a/Swiftlet/Interfaces/App.php +++ b/Swiftlet/Interfaces/App.php @@ -8,9 +8,11 @@ public function __construct(); public function serve(); + public function getConfig($variable); + public function setConfig($variable, $value); - public function getConfig($variable); + public function getRootPath(); public function getAction(); @@ -20,8 +22,6 @@ public function getModel($modelName); public function getSingleton($modelName); - public function getRootPath(); - public function registerHook($hookName, array $params = array()); public function autoload($className); diff --git a/Swiftlet/Model.php b/Swiftlet/Model.php index 502dae5..55766c0 100644 --- a/Swiftlet/Model.php +++ b/Swiftlet/Model.php @@ -14,6 +14,7 @@ abstract class Model implements Interfaces\Model * Constructor * @param object $app * @param object $view + * @param object $controller */ public function __construct(App $app, View $view, Controller $controller) { diff --git a/Swiftlet/Models/Example.php b/Swiftlet/Models/Example.php index 35c3e5a..f3ef336 100644 --- a/Swiftlet/Models/Example.php +++ b/Swiftlet/Models/Example.php @@ -2,10 +2,6 @@ namespace Swiftlet\Models; -use - Swiftlet\App - ; - class Example extends \Swiftlet\Model { /** diff --git a/Swiftlet/Plugin.php b/Swiftlet/Plugin.php index a87c239..73750b4 100644 --- a/Swiftlet/Plugin.php +++ b/Swiftlet/Plugin.php @@ -14,6 +14,7 @@ abstract class Plugin implements Interfaces\Plugin * Constructor * @param object $app * @param object $view + * @param object $controller */ public function __construct(App $app, View $view, Controller $controller) { diff --git a/Swiftlet/View.php b/Swiftlet/View.php index c9347fe..87a9f83 100644 --- a/Swiftlet/View.php +++ b/Swiftlet/View.php @@ -16,7 +16,7 @@ class View implements Interfaces\View /** * Constructor * @param object $app - * @param object $view + * @param string $name */ public function __construct(App $app, $name) { @@ -107,8 +107,6 @@ public function htmlDecode($value) /** * Render the view - * @param mixed $value - * @return mixed */ public function render() { diff --git a/config.php b/config.php index ee4cdb2..7491c61 100644 --- a/config.php +++ b/config.php @@ -2,4 +2,4 @@ $app->setConfig('siteName', 'Swiftlet'); -// Add your own configuration values here! +// Add your own configuration values here or in a separate file diff --git a/index.php b/index.php index fe2cf57..e4d08f8 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ namespace Swiftlet; try { + // Bootstrap the application require 'Swiftlet/Interfaces/App.php'; require 'Swiftlet/App.php'; diff --git a/robots.txt b/robots.txt index 3f912af..68b1855 100644 --- a/robots.txt +++ b/robots.txt @@ -1,5 +1,5 @@ User-agent: * -Disallow: /lib/ +Disallow: /Swiftlet/ Disallow: /tests/ Disallow: /views/ Disallow: /config.php