Some improvements for PHPdoc

pull/360/head
Alex Shadie 7 years ago
parent db2c5c77e1
commit d3067e5eae

@ -15,6 +15,33 @@ use flight\core\Dispatcher;
* The Engine class contains the core functionality of the framework. * The Engine class contains the core functionality of the framework.
* It is responsible for loading an HTTP request, running the assigned services, * It is responsible for loading an HTTP request, running the assigned services,
* and generating an HTTP response. * and generating an HTTP response.
*
* Core methods
* @method void start() Starts engine
* @method void stop() Stops framework and outputs current response
* @method void halt(int $code = 200, string $message = '') Stops processing and returns a given response.
*
*
* Routing
* @method void route(string $pattern, callable $callback, bool $pass_route = false) Routes a URL to a callback function.
* @method \flight\net\Router router() Gets router
*
* Views
* @method void render(string $file, array $data = null, string $key = null) Renders template
* @method \flight\template\View view() Gets current view
*
* Request-response
* @method \flight\net\Request request() Gets current request
* @method \flight\net\Response response() Gets current response
* @method void error(\Exception $e) Sends an HTTP 500 response for any errors.
* @method void notFound() Sends an HTTP 404 response when a URL is not found.
* @method void redirect(string $url, int $code = 303) Redirects the current request to another URL.
* @method void json(mixed $data, int $code = 200, bool $encode = true, string $charset = 'utf-8', int $option = 0) Sends a JSON response.
* @method void jsonp(mixed $data, string $param = 'jsonp', int $code = 200, bool $encode = true, string $charset = 'utf-8', int $option = 0) Sends a JSONP response.
*
* HTTP caching
* @method void etag($id, string $type = 'strong') Handles ETag HTTP caching.
* @method void lastModified(int $time) Handles last modified HTTP caching.
*/ */
class Engine { class Engine {
/** /**
@ -27,14 +54,14 @@ class Engine {
/** /**
* Class loader. * Class loader.
* *
* @var object * @var Loader
*/ */
protected $loader; protected $loader;
/** /**
* Event dispatcher. * Event dispatcher.
* *
* @var object * @var Dispatcher
*/ */
protected $dispatcher; protected $dispatcher;
@ -148,7 +175,7 @@ class Engine {
/** /**
* Custom exception handler. Logs exceptions. * Custom exception handler. Logs exceptions.
* *
* @param object $e Thrown exception * @param \Exception $e Thrown exception
*/ */
public function handleException($e) { public function handleException($e) {
if ($this->get('flight.log_errors')) { if ($this->get('flight.log_errors')) {
@ -276,6 +303,7 @@ class Engine {
/** /**
* Starts the framework. * Starts the framework.
* @throws \Exception
*/ */
public function _start() { public function _start() {
$dispatched = false; $dispatched = false;
@ -330,6 +358,7 @@ class Engine {
* Stops the framework and outputs the current response. * Stops the framework and outputs the current response.
* *
* @param int $code HTTP status code * @param int $code HTTP status code
* @throws \Exception
*/ */
public function _stop($code = null) { public function _stop($code = null) {
$response = $this->response(); $response = $this->response();
@ -395,9 +424,6 @@ class Engine {
catch (\Throwable $t) { catch (\Throwable $t) {
exit($msg); exit($msg);
} }
catch (\Exception $ex) {
exit($msg);
}
} }
/** /**
@ -446,6 +472,7 @@ class Engine {
* @param string $file Template file * @param string $file Template file
* @param array $data Template data * @param array $data Template data
* @param string $key View variable name * @param string $key View variable name
* @throws \Exception
*/ */
public function _render($file, $data = null, $key = null) { public function _render($file, $data = null, $key = null) {
if ($key !== null) { if ($key !== null) {
@ -464,6 +491,7 @@ class Engine {
* @param bool $encode Whether to perform JSON encoding * @param bool $encode Whether to perform JSON encoding
* @param string $charset Charset * @param string $charset Charset
* @param int $option Bitmask Json constant such as JSON_HEX_QUOT * @param int $option Bitmask Json constant such as JSON_HEX_QUOT
* @throws \Exception
*/ */
public function _json( public function _json(
$data, $data,
@ -490,6 +518,7 @@ class Engine {
* @param bool $encode Whether to perform JSON encoding * @param bool $encode Whether to perform JSON encoding
* @param string $charset Charset * @param string $charset Charset
* @param int $option Bitmask Json constant such as JSON_HEX_QUOT * @param int $option Bitmask Json constant such as JSON_HEX_QUOT
* @throws \Exception
*/ */
public function _jsonp( public function _jsonp(
$data, $data,

@ -54,7 +54,7 @@ class Flight {
/** /**
* Framework engine. * Framework engine.
* *
* @var object * @var \flight\Engine
*/ */
private static $engine; private static $engine;

@ -35,6 +35,7 @@ class Dispatcher {
* @param string $name Event name * @param string $name Event name
* @param array $params Callback parameters * @param array $params Callback parameters
* @return string Output of callback * @return string Output of callback
* @throws \Exception
*/ */
public function run($name, array $params = array()) { public function run($name, array $params = array()) {
$output = ''; $output = '';
@ -119,6 +120,7 @@ class Dispatcher {
* @param array $filters Chain of filters * @param array $filters Chain of filters
* @param array $params Method parameters * @param array $params Method parameters
* @param mixed $output Method output * @param mixed $output Method output
* @throws \Exception
*/ */
public function filter($filters, &$params, &$output) { public function filter($filters, &$params, &$output) {
$args = array(&$params, &$output); $args = array(&$params, &$output);

@ -65,6 +65,7 @@ class Loader {
* @param string $name Method name * @param string $name Method name
* @param bool $shared Shared instance * @param bool $shared Shared instance
* @return object Class instance * @return object Class instance
* @throws \Exception
*/ */
public function load($name, $shared = true) { public function load($name, $shared = true) {
$obj = null; $obj = null;
@ -112,6 +113,7 @@ class Loader {
* @param string|callable $class Class name or callback function to instantiate class * @param string|callable $class Class name or callback function to instantiate class
* @param array $params Class initialization parameters * @param array $params Class initialization parameters
* @return object Class instance * @return object Class instance
* @throws \Exception
*/ */
public function newInstance($class, array $params = array()) { public function newInstance($class, array $params = array()) {
if (is_callable($class)) { if (is_callable($class)) {
@ -132,8 +134,12 @@ class Loader {
case 5: case 5:
return new $class($params[0], $params[1], $params[2], $params[3], $params[4]); return new $class($params[0], $params[1], $params[2], $params[3], $params[4]);
default: default:
try {
$refClass = new \ReflectionClass($class); $refClass = new \ReflectionClass($class);
return $refClass->newInstanceArgs($params); return $refClass->newInstanceArgs($params);
} catch (\ReflectionException $e) {
throw new \Exception("Cannot instantiate {$class}", 0, $e);
}
} }
} }
@ -159,7 +165,7 @@ class Loader {
* Starts/stops autoloader. * Starts/stops autoloader.
* *
* @param bool $enabled Enable/disable autoloading * @param bool $enabled Enable/disable autoloading
* @param mixed $dirs Autoload directories * @param array $dirs Autoload directories
*/ */
public static function autoload($enabled = true, $dirs = array()) { public static function autoload($enabled = true, $dirs = array()) {
if ($enabled) { if ($enabled) {

@ -6,4 +6,3 @@ Flight::route('/', function(){
}); });
Flight::start(); Flight::start();
?>

Loading…
Cancel
Save