Skip to content

Commit

Permalink
Minor code and documentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ElbertF committed Feb 11, 2012
1 parent 626eb7e commit 2813e30
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 52 deletions.
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Buzzword compliance
-------------------

✔ Micro-Framework
✔ Loosely coupled
✔ Loosely coupled
✔ Namespaced
✔ Unit tested
✔ Pluggable
Expand Down Expand Up @@ -42,7 +42,7 @@ Controllers house the
[business logic](http:https://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
<?php
Expand Down Expand Up @@ -97,7 +97,7 @@ missing from the URL they will default to `index` (`/` will call `index()` on
`Swiftlet\Controller\Index`).

Underscores in the controller name are translated to directory separators, so
`/foo_bar` will point to `lib/Swiftlet/Controllers/Foo/Bar.php`.
`/foo_bar` will point to `Swiftlet/Controllers/Foo/Bar.php`.


Actions and arguments
Expand All @@ -117,16 +117,17 @@ will throw an exception by default but can be overridden.
The action name and arguments can be accessed through
`$this->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
------

Let's throw a model into the mix and update the controller.

**Model `lib/Swiftlet/Models/Foo.php`**
**Model `Swiftlet/Models/Foo.php`**

```php
<?php
Expand All @@ -141,7 +142,7 @@ class Foo extends \Swiftlet\Model
}
```

**Controller `lib/Swiftlet/Controllers/Foo.php`**
**Controller `Swiftlet/Controllers/Foo.php`**

```php
<?php
Expand All @@ -153,7 +154,7 @@ class Foo extends \Swiftlet\Controller

public function index()
{
// Get an instance of the Example class (lib/Swiftlet/Models/Example.php)
// Get an instance of the Example class (Swiftlet/Models/Example.php)
$exampleModel = $this->app->getModel('example');

$helloWorld = $exampleModel->getHelloWorld();
Expand Down Expand Up @@ -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
<?php
Expand All @@ -200,10 +201,10 @@ class Foo extends \Swiftlet\Plugin
```

This plugin implements the core `actionAfter` hook and changes the view
variable `hello world` from our previous example to `Hi world!`.
variable `helloWorld` from our previous example to `Hi world!`.

Plugins don't need to be installed or activated, all files in the
`/lib/Swiftlet/Plugins/` directory are automatically included and their classes
`Swiftlet/Plugins/` directory are automatically included and their classes
instantiated. They are hooked in alphabetical order.

The core hooks are:
Expand Down Expand Up @@ -235,24 +236,20 @@ Values can be set in `config.php` or a custom file.
--------------------------------------------------------------------------------


Public abstract methods
Abstract Public methods
-----------------------

All application and view methods can be called statically, e.g.
`App::getAction()` and `View::getTitle()`.


**Application `Swiftlet\App`**

* `serve()`
Render the view

* `setConfig(string $variable, mixed $value)`
Set a configuration value

* `mixed getConfig(string $variable)`
Get a configuration value

* `setConfig(string $variable, mixed $value)`
Set a configuration value

* `string getAction()`
Name of the action

Expand Down
39 changes: 20 additions & 19 deletions Swiftlet/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class App implements Interfaces\App
;

/**
* Initialize the application
* Constructor
*/
public function __construct()
{
Expand Down Expand Up @@ -114,6 +114,18 @@ public function serve()
$this->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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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
*/
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Swiftlet/Controllers/Error404.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function index()
*/
public function notImplemented()
{
$this->indexAction();
$this->index();
}
}
2 changes: 1 addition & 1 deletion Swiftlet/Controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Swiftlet/Interfaces/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Swiftlet/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 0 additions & 4 deletions Swiftlet/Models/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Swiftlet\Models;

use
Swiftlet\App
;

class Example extends \Swiftlet\Model
{
/**
Expand Down
1 change: 1 addition & 0 deletions Swiftlet/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 1 addition & 3 deletions Swiftlet/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -107,8 +107,6 @@ public function htmlDecode($value)

/**
* Render the view
* @param mixed $value
* @return mixed
*/
public function render()
{
Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Swiftlet;

try {
// Bootstrap the application
require 'Swiftlet/Interfaces/App.php';
require 'Swiftlet/App.php';

Expand Down
2 changes: 1 addition & 1 deletion robots.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
User-agent: *
Disallow: /lib/
Disallow: /Swiftlet/
Disallow: /tests/
Disallow: /views/
Disallow: /config.php
Expand Down

0 comments on commit 2813e30

Please sign in to comment.