1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
<?php
/**
* Core. Setup all settings and configurations for the application.
*
* @package Silla.IO
* @subpackage Core
* @author Plamen Nikolov <plamen@athlonsofia.com>
* @copyright Copyright (c) 2015, Silla.io
* @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3.0 (GPLv3)
*/
/**
* Framework Core namespace.
*/
namespace Core {
/* Hook the default auto-load class function. */
spl_autoload_extensions('.php');
spl_autoload_register('spl_autoload');
/**
* For easier access to Config.
*
* @return Base\Configuration
*/
function Config()
{
$configuration = 'Configurations\\' . SILLA_ENVIRONMENT . '\\Configuration';
return $configuration::getInstance();
}
/**
* For easier access to Router.
*
* @return Modules\Router\Router
*/
function Router()
{
return Modules\Router\Router::getInstance();
}
/**
* For easier access to Registry.
*
* @return Modules\Registry\Registry
*/
function Registry()
{
return Modules\Registry\Registry::getInstance();
}
/**
* For easier access to Session.
*
* @return Modules\Session\Session
*/
function Session()
{
return Modules\Session\Session::getInstance(Config()->SESSION['adapter']);
}
/**
* For easier access to Cache.
*
* @return Modules\Cache\Cache
*/
function Cache()
{
return Modules\Cache\Cache::getInstance(Config()->CACHE['adapter']);
}
/**
* For easier access to DB.
*
* @return Modules\DB\Adapters\PdoMySql|
* Modules\DB\Adapters\MySQLi|
* Modules\DB\Adapters\MySQL|
* Modules|DB\AdaptersSQLite Adapter Instance.
*/
function DB()
{
return Modules\DB\DB::getInstance(Config()->DB);
}
/**
* For easier access to DBCache.
*
* @return Modules\DB\DbCache
*/
function DbCache()
{
return Modules\DB\DB::getCache(Config()->DB);
}
}
/* Global namespace. */
namespace {
/**
* Prints human-readable information about a variable.
*
* @param mixed $what Input data.
* @param boolean $trace Whether to trace invokation place or not.
*
* @see debug_backtrace()
*
* @return void
*/
function d($what, $trace = true)
{
if ($trace) {
$trace = debug_backtrace();
$trace = "<br/><small><em>called in {$trace[0]['file']} on {$trace[0]['line']} line</em></small>";
echo '<pre>', print_r($what, true) . $trace, '</pre>';
} else {
echo '<pre>', print_r($what, true), '</pre>';
}
}
/**
* Stop the script and prints human-readable information about a variable.
*
* @param mixed $what Input data.
*
* @uses d()
* @see debug_backtrace()
*
* @return void
*/
function dd($what)
{
$trace = debug_backtrace();
$trace = "<small><em>called in {$trace[0]['file']} on {$trace[0]['line']} line</em></small>";
die(d($what, false) . $trace);
}
/**
* Prints all Database queries executed.
*
* @uses d()
*
* @return void
*/
function ds()
{
d(Core\Modules\DB\DB::$queries);
}
/**
* Prints human-readable information about a variable.
*
* @param mixed $what Input data.
*
* @see var_dump()
*
* @return void
*/
function vd($what)
{
echo '<pre>';
var_dump($what);
echo '</pre>';
}
/**
* Logs debug data to a log file.
*
* @param mixed $what Input data.
*
* @uses Core\Config()
* @see file_put_contents()
*
* @return void
*/
function var_log($what)
{
if (!is_scalar($what)) {
$what = print_r($what, true);
}
file_put_contents(
Core\Config()->paths('tmp') . 'debug.log',
gmdate('[Y-m-d H:i:s e] ') . $what . "\n",
FILE_APPEND
);
}
/* Registers vendors auto-loaders. */
require_once Core\Config()->paths('vendor') . 'autoload.php';
}