Skip to content

Commit

Permalink
PHPDoc inline documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AliasIO committed Jul 7, 2013
1 parent 8599301 commit b39e511
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 71 deletions.
83 changes: 59 additions & 24 deletions Swiftlet/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,68 @@

/**
* Application class
*
* @property string $action
* @property array $args
* @property array $config
* @property Interfaces\Controller $controller
* @property string $controllerName
* @property array $hooks
* @property array $plugins
* @property string $rootPath
* @property array $singletons
* @property Interfaces\View $view
*/
class App implements Interfaces\App
{
protected
$action = 'index',
$args = array(),
$config = array(),
$controller,
$controllerName = 'Index',
$hooks = array(),
$plugins = array(),
$rootPath = '/',
$singletons = array(),
$view
;
/**
* Action name
* @var string
*/
protected $action = 'index';

/**
* Arguments
* @var array
*/
protected $args = array();

/**
* Configuration values
* @var array
*/
protected $config = array();

/**
* Controller intance
* @var Interfaces/Controller
*/
protected $controller;

/**
* Controller name
* @var string
*/
protected $controllerName = 'Index';

/**
* Hooks
* @var array
*/
protected $hooks = array();

/**
* Plugins
* @var array
*/
protected $plugins = array();

/**
* Root path
* @var string
*/
protected $rootPath = '/';

/**
* Re-usable model instances
* @var array
*/
protected $singletons = array();

/**
* View instance
* @var Interfaces/View
*/
protected $view;

/**
* Run the application
Expand Down Expand Up @@ -266,7 +302,6 @@ public function autoload($className)
* @param string $string
* @param string $file
* @param int $line
*
* @throws Exception
*/
public function error($number, $string, $file, $line)
Expand Down
25 changes: 17 additions & 8 deletions Swiftlet/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@

/**
* Controller class
*
* @abstract
* @property Interfaces\App $app
* @property Interfaces\View $view
* @property string $title
*/
abstract class Controller implements Interfaces\Controller
{
protected
$app,
$view,
$title
;
/**
* Application instance
* @var Interfaces\App
*/
protected $app;

/**
* View instance
* @var Interfaces\View
*/
protected $view;

/**
* Page title
* @var string
*/
protected $title;

/**
* Constructor
*
* @param Interfaces\App $app
* @param Interfaces\View $view
*/
Expand All @@ -41,7 +51,6 @@ public function index()

/**
* Fallback in case action doesn't exist
*
* @throws Exception
*/
public function notImplemented()
Expand Down
10 changes: 5 additions & 5 deletions Swiftlet/Controllers/Error404.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

/**
* Error 404 controller
*
* @property $title
*/
class Error404 extends \Swiftlet\Controller
{
protected
$title = 'Error 404'
;
/**
* Page title
* @var string
*/
protected $title = 'Error 404';

/**
* Default action
Expand Down
10 changes: 5 additions & 5 deletions Swiftlet/Controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

/**
* Index controller
*
* @property $title
*/
class Index extends \Swiftlet\Controller
{
protected
$title = 'Home'
;
/**
* Page title
* @var string
*/
protected $title = 'Home';

/**
* Default action
Expand Down
60 changes: 60 additions & 0 deletions Swiftlet/Interfaces/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,89 @@
*/
interface App
{
/**
* Run the application
*/
public function run();

/**
* Serve the page
*/
public function serve();

/**
* Get a configuration value
* @param string $variable
* @return mixed|null
*/
public function getConfig($variable);

/**
* Set a configuration value
* @param string $variable
* @param mixed $value
*/
public function setConfig($variable, $value);

/**
* Get the client-side path to root
* @return string
*/
public function getRootPath();

/**
* Get the controller name
* @return string
*/
public function getControllerName();

/**
* Get the action name
* @return string
*/
public function getAction();

/**
* Get the arguments
* @return array
*/
public function getArgs();

/**
* Get a model
* @param string $modelName
* @return object
*/
public function getModel($modelName);

/**
* Get a model singleton
* @param string $modelName
* @return object
*/
public function getSingleton($modelName);

/**
* Register a hook for plugins to implement
* @param string $hookName
* @param array $params
*/
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);

/**
* Error handler
* @param int $number
* @param string $string
* @param string $file
* @param int $line
* @throws Exception
*/
public function error($number, $string, $file, $line);
}
12 changes: 12 additions & 0 deletions Swiftlet/Interfaces/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@
*/
interface Controller
{
/**
* Constructor
* @param App $app
* @param View $view
*/
public function __construct(App $app, View $view);

/**
* Default action
*/
public function index();

/**
* Fallback in case action doesn't exist
* @throws Exception
*/
public function notImplemented();
}
4 changes: 4 additions & 0 deletions Swiftlet/Interfaces/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
*/
interface Model
{
/**
* Constructor
* @param App $app
*/
public function __construct(App $app);
}
6 changes: 6 additions & 0 deletions Swiftlet/Interfaces/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
*/
interface Plugin
{
/**
* Constructor
* @param App $app
* @param View $view
* @param Controller $controller
*/
public function __construct(App $app, View $view, Controller $controller);
}
44 changes: 42 additions & 2 deletions Swiftlet/Interfaces/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,59 @@
*/
interface View
{
/**
* Constructor
* @param App $app
* @param string $name
*/
public function __construct(App $app, $name);

/**
* Get a view variable
* @param string $variable
* @param bool $htmlEncode
* @return mixed|null
*/
public function get($variable, $htmlEncode = true);

/**
* Magic method to get a view variable, forwards to $this->get()
* @param string $variable
* @return mixed
*/
public function __get($variable);

public function set($variable, $value = null);

/**
* Magic method to set a view variable, forwards to $this->set()
* @param string $variable
* @param mixed $value
*/
public function __set($variable, $value = null);

/**
* Magic method to set a view variable, forwards to $this->set()
* @param string $variable
* @param mixed $value
*/
public function set($variable, $value = null);

/**
* Recursively make a value safe for HTML
* @param mixed $value
* @return mixed
*/
public function htmlEncode($value);

/**
* Recursively decode an HTML encoded value
* @param mixed $value
* @return mixed
*/
public function htmlDecode($value);

/**
* Render the view
* @throws Exception
*/
public function render();
}
Loading

0 comments on commit b39e511

Please sign in to comment.