소스 검색

Doc blocks

Sergio Brighenti 6 년 전
부모
커밋
732cf7ff48
6개의 변경된 파일88개의 추가작업 그리고 1개의 파일을 삭제
  1. 17 0
      app/Controllers/Controller.php
  2. 17 0
      app/Database/DB.php
  3. 4 0
      app/Traits/SingletonController.php
  4. 40 0
      app/Web/Session.php
  5. 8 0
      bootstrap/app.php
  6. 2 1
      composer.json

+ 17 - 0
app/Controllers/Controller.php

@@ -15,6 +15,7 @@ abstract class Controller
 {
 
 	/**
+	 * Check if the current user is logged in
 	 * @throws AuthenticationException
 	 */
 	protected function checkLogin(): void
@@ -34,6 +35,7 @@ abstract class Controller
 	}
 
 	/**
+	 * Check if the current user is an admin
 	 * @throws AuthenticationException
 	 * @throws UnauthorizedException
 	 */
@@ -50,6 +52,12 @@ abstract class Controller
 	}
 
 
+	/**
+	 * Generate a human readable file size
+	 * @param $size
+	 * @param int $precision
+	 * @return string
+	 */
 	protected function humanFilesize($size, $precision = 2): string
 	{
 		for ($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) {
@@ -57,11 +65,20 @@ abstract class Controller
 		return round($size, $precision) . ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][$i];
 	}
 
+	/**
+	 * Get a filesystem instance
+	 * @return Filesystem
+	 */
 	protected function getStorage(): Filesystem
 	{
 		return new Filesystem(new Local(Flight::get('config')['storage_dir']));
 	}
 
+	/**
+	 * Set http2 header for a resource if is supported
+	 * @param string $url
+	 * @param string $as
+	 */
 	protected function http2push(string $url, string $as = 'image'): void
 	{
 		if (Flight::request()->scheme === 'HTTP/2.0') {

+ 17 - 0
app/Database/DB.php

@@ -50,6 +50,7 @@ class DB
 	}
 
 	/**
+	 * Get the PDO instance
 	 * @return PDO
 	 */
 	public function getPdo(): PDO
@@ -58,6 +59,7 @@ class DB
 	}
 
 	/**
+	 * Get the current PDO driver
 	 * @return string
 	 */
 	public function getCurrentDriver(): string
@@ -65,6 +67,12 @@ class DB
 		return $this->currentDriver;
 	}
 
+	/**
+	 * Perform a query
+	 * @param string $query
+	 * @param array $parameters
+	 * @return bool|\PDOStatement|string
+	 */
 	public static function query(string $query, $parameters = [])
 	{
 
@@ -75,6 +83,10 @@ class DB
 		return self::$instance->doQuery($query, $parameters);
 	}
 
+	/**
+	 * Static method to get the current driver name
+	 * @return string
+	 */
 	public static function driver(): string
 	{
 
@@ -85,6 +97,10 @@ class DB
 		return self::$instance->getCurrentDriver();
 	}
 
+	/**
+	 * Get directly the PDO instance
+	 * @return PDO
+	 */
 	public static function raw(): PDO
 	{
 		if (self::$instance === null) {
@@ -95,6 +111,7 @@ class DB
 	}
 
 	/**
+	 * Set the PDO connection string
 	 * @param string $dsn
 	 * @param string|null $username
 	 * @param string|null $password

+ 4 - 0
app/Traits/SingletonController.php

@@ -9,6 +9,10 @@ trait SingletonController
 {
 	protected static $instance;
 
+	/**
+	 * Return the controller instance
+	 * @return Controller
+	 */
 	public static function instance(): Controller
 	{
 		if (static::$instance === null) {

+ 40 - 0
app/Web/Session.php

@@ -6,6 +6,9 @@ namespace App\Web;
 class Session
 {
 
+	/**
+	 * Start a session if is not already started in the current context
+	 */
 	public static function init(): void
 	{
 		if (session_status() === PHP_SESSION_NONE) {
@@ -16,47 +19,84 @@ class Session
 		}
 	}
 
+	/**
+	 * Destroy the current session
+	 * @return bool
+	 */
 	public static function destroy(): bool
 	{
 		return session_destroy();
 	}
 
+	/**
+	 * Clear all session stored values
+	 */
 	public static function clear(): void
 	{
 		self::init();
 		$_SESSION = [];
 	}
 
+	/**
+	 * Check if session has a stored key
+	 * @param $key
+	 * @return bool
+	 */
 	public static function has($key): bool
 	{
 		self::init();
 		return isset($_SESSION[$key]);
 	}
 
+	/**
+	 * Get the content of the current session
+	 * @return array
+	 */
 	public static function all(): array
 	{
 		self::init();
 		return $_SESSION;
 	}
 
+	/**
+	 * Returned a value given a key
+	 * @param $key
+	 * @param null $default
+	 * @return mixed
+	 */
 	public static function get($key, $default = null)
 	{
 		self::init();
 		return self::has($key) ? $_SESSION[$key] : $default;
 	}
 
+	/**
+	 * Add a key-value pair to the session
+	 * @param $key
+	 * @param $value
+	 */
 	public static function set($key, $value): void
 	{
 		self::init();
 		$_SESSION[$key] = $value;
 	}
 
+	/**
+	 * Set a flash alert
+	 * @param $message
+	 * @param string $type
+	 */
 	public static function alert($message, string $type = 'info'): void
 	{
 		self::init();
 		$_SESSION['_flash'] = [$type => $message];
 	}
 
+
+	/**
+	 * Retrieve flash alerts
+	 * @return array
+	 */
 	public static function getAlert()
 	{
 		$flash = self::get('_flash');

+ 8 - 0
bootstrap/app.php

@@ -2,6 +2,7 @@
 
 use App\Database\DB;
 
+// Load the config
 $config = array_replace_recursive([
 	'app_name' => 'XBackBone',
 	'base_url' => isset($_SERVER['HTTPS']) ? 'https://' . $_SERVER['HTTP_HOST'] : 'http://' . $_SERVER['HTTP_HOST'],
@@ -15,12 +16,15 @@ $config = array_replace_recursive([
 	],
 ], require 'config.php');
 
+// Set flight parameters
 Flight::set('flight.base_url', $config['base_url']);
 Flight::set('flight.log_errors', false);
 Flight::set('config', $config);
 
+// Set the database dsn
 DB::setDsn($config['db']['connection'] . ':' . $config['db']['dsn'], $config['db']['username'], $config['db']['password']);
 
+// Register the Twig instance
 Flight::register('view', 'Twig_Environment',
 	[new Twig_Loader_Filesystem('resources/templates'),
 		[
@@ -32,10 +36,12 @@ Flight::register('view', 'Twig_Environment',
 	]
 );
 
+// Redirect back helper
 Flight::register('redirectBack', function () {
 	Flight::redirect(Flight::request()->referrer);
 });
 
+// Map the render call to the Twig view instance
 Flight::map('render', function (string $template, array $data = []) use (&$config) {
 	Flight::view()->addGlobal('config', $config);
 	Flight::view()->addGlobal('request', Flight::request());
@@ -45,6 +51,7 @@ Flight::map('render', function (string $template, array $data = []) use (&$confi
 	Flight::view()->display($template, $data);
 });
 
+// The application error handler
 Flight::map('error', function (Exception $exception) {
 	if ($exception instanceof \App\Exceptions\AuthenticationException) {
 		Flight::redirect('/login');
@@ -72,4 +79,5 @@ Flight::map('notFound', function () {
 	Flight::render('errors/404.twig');
 });
 
+// Load the application routes
 require 'app/routes.php';

+ 2 - 1
composer.json

@@ -10,7 +10,8 @@
     "monolog/monolog": "^1.23",
     "php": ">=7.1",
     "ext-json": "*",
-    "ext-gd": "*"
+    "ext-gd": "*",
+    "ext-pdo": "*"
   },
   "autoload": {
     "psr-4": {