AloFramework documentation
  • Namespace
  • Function
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alo
    • Cache
    • CLI
    • Controller
    • Db
    • Exception
    • FileSystem
    • Session
    • Statics
    • Test
    • Validators
    • Windows
  • Controller
  • None
  • PHP

Classes

  • Alo
  • Log

Functions

  • debug
  • escape_html5
  • get
  • getallheaders
  • includeifexists
  • includeonceifexists
  • lite_debug
  • server_is_windows
  • timestamp_precise
  1 <?php
  2 
  3    if(!defined('GEN_START')) {
  4       http_response_code(404);
  5       die();
  6    }
  7 
  8    ob_start();
  9    require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'log.php';
 10    include_once DIR_SYS . 'external' . DIRECTORY_SEPARATOR . 'kint' . DIRECTORY_SEPARATOR . '_main.php';
 11    require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'handler.php';
 12 
 13    spl_autoload_register('\Alo\Handler::autoloader');
 14    set_error_handler('\Alo\Handler::error', ini_get('error_reporting'));
 15    set_exception_handler('\Alo\Handler::ecxeption');
 16 
 17    /**
 18     * A shortcut to isset($var) ? $var : null
 19     *
 20     * @author Art <a.molcanovas@gmail.com>
 21     *
 22     * @param mixed $var The variable to "return"
 23     *
 24     * @return mixed
 25     */
 26    function get(&$var) {
 27       return isset($var) ? $var : null;
 28    }
 29 
 30    /**
 31     * Returns a debug string of the passed on variables
 32     *
 33     * @return string
 34     */
 35    function debug() {
 36       if(!Kint::enabled()) {
 37          return null;
 38       } else {
 39          ob_start();
 40          $args = func_get_args();
 41          call_user_func_array(['Kint', 'dump'], $args);
 42 
 43          return ob_get_clean();
 44       }
 45    }
 46 
 47    /**
 48     * Check if the server is running Windows
 49     *
 50     * @author Art <a.molcanovas@gmail.com>
 51     * @return bool
 52     */
 53    function server_is_windows() {
 54       return substr(strtoupper(php_uname('s')), 0, 3) === 'WIN';
 55    }
 56 
 57    /**
 58     * Returns a lite debug string of passed on variables
 59     *
 60     * @return string
 61     */
 62    function lite_debug() {
 63       if(!Kint::enabled()) {
 64          return '';
 65       } else {
 66          ob_start();
 67          $argv = func_get_args();
 68          echo '<pre>';
 69          foreach($argv as $k => $v) {
 70             $k && print("\n\n");
 71             echo kintLite($v);
 72          }
 73          echo '</pre>' . "\n";
 74 
 75          return ob_get_clean();
 76       }
 77    }
 78 
 79    /**
 80     * Returns a very precise timestamp
 81     *
 82     * @author Art <a.molcanovas@gmail.com>
 83     *
 84     * @param float $microtime Optionally, supply your own microtime
 85     *
 86     * @return string Y-m-d H:i:s:{milliseconds}
 87     */
 88    function timestamp_precise($microtime = null) {
 89       if(!$microtime) {
 90          $microtime = microtime(true);
 91       }
 92       $t = explode('.', $microtime);
 93 
 94       return date('Y-m-d H:i:s', $t[0]) . ':' . round($t[1] / 10);
 95    }
 96 
 97    if(!function_exists('getallheaders')) {
 98 
 99       /**
100        * Implement getallheaders() for non-apache servers
101        *
102        * @author Art <a.molcanovas@gmail.com>
103        * @return array
104        */
105       function getallheaders() {
106          $headers = [];
107          foreach($_SERVER as $name => $value) {
108             if(substr($name, 0, 5) == 'HTTP_') {
109                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
110             }
111          }
112 
113          return $headers;
114       }
115    }
116 
117    /**
118     * Escapes sensitive characters for HTML5 output
119     *
120     * @author Art <a.molcanovas@gmail.com>
121     *
122     * @param string $str The input string
123     *
124     * @return string
125     */
126    function escape_html5($str) {
127       return htmlspecialchars($str, ENT_QUOTES | ENT_HTML5);
128    }
129 
130    /**
131     * Performs include() only if a file exists
132     *
133     * @param string $path Path to the file
134     *
135     * @return bool true if the file exists, false if not.
136     */
137    function includeifexists($path) {
138       if(file_exists($path)) {
139          include $path;
140 
141          return true;
142       }
143 
144       return false;
145    }
146 
147    /**
148     * Performs include_once() only if a file exists
149     *
150     * @param string $path Path to the file
151     *
152     * @return bool true if the file exists, false if not.
153     */
154    function includeonceifexists($path) {
155       if(file_exists($path)) {
156          include_once $path;
157 
158          return true;
159       }
160 
161       return false;
162    }
163 
164    require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'alo.php';
165 
166    includeonceifexists(DIR_APP . 'core' . DIRECTORY_SEPARATOR . 'autoload.php');
167 
168    if(!defined('PHPUNIT_RUNNING')) {
169       Alo::$router = new Alo\Controller\Router();
170       Alo::$router->init();
171    }
AloFramework documentation API documentation generated by ApiGen 2.8.0