Esempio n. 1
0
 /**
  * Init session
  *
  * @staticvar boolean $is_init
  * @return void
  */
 private static function __init()
 {
     static $is_init = false;
     if (!self::__isSession()) {
         session_cache_limiter(false);
         session_start();
         if (!$is_init) {
             drone()->log->trace('Session started', Logger::CATEGORY_DRONE);
         }
         $is_init = true;
     }
 }
Esempio n. 2
0
<?php

/**
 * Drone - Rapid Development Framework for PHP 5.5.0+
 *
 * @package Drone
 * @version 0.2.3
 * @copyright 2015 Shay Anderson <http://www.shayanderson.com>
 * @license MIT License <http://www.opensource.org/licenses/mit-license.php>
 * @link <https://github.com/shayanderson/drone>
 */
//////////////////////////////////////////////////////////////////////////
// Load Drone Framework + run application
//////////////////////////////////////////////////////////////////////////
// set root path
define('PATH_ROOT', __DIR__ . '/');
// include Drone common functions
require_once './_app/lib/Drone/com.php';
// set class autoloading paths
autoload([PATH_ROOT . '_app/lib']);
// include app/Drone bootstrap
require_once './_app/com/app.bootstrap.php';
// run application (execute last)
drone()->run();
Esempio n. 3
0
 /**
  * Global error handler
  *
  * @param int $err_no
  * @param string $err_message
  * @param string $err_file
  * @param int $err_line
  * @return boolean
  */
 public static function errorHandler($err_no, $err_message, $err_file, $err_line)
 {
     static $handler;
     if (is_callable($err_no)) {
         $handler = $err_no;
         drone()->log->trace('Error default handler registered', Logger::CATEGORY_DRONE);
         return true;
     }
     if (!($err_no & error_reporting())) {
         return false;
     }
     $err_message .= ' (' . $err_file . ':' . $err_line . ')';
     switch ($err_no) {
         case \E_ERROR:
         case \E_USER_ERROR:
             $err_message = 'Error: ' . $err_message;
             drone()->log->fatal($err_message, Logger::CATEGORY_DRONE);
             break;
         case \E_WARNING:
         case \E_USER_WARNING:
             $err_message = 'Warning: ' . $err_message;
             drone()->log->warn($err_message, Logger::CATEGORY_DRONE);
             break;
         case \E_NOTICE:
         case \E_USER_NOTICE:
             $err_message = 'Notice: ' . $err_message;
             drone()->log->debug($err_message, Logger::CATEGORY_DRONE);
             break;
     }
     if (Registry::get(self::KEY_ERROR_LOG)) {
         error_log($err_message, $err_no);
     }
     self::$__error_last = $err_message;
     // cache error message
     if (is_callable($handler)) {
         $handler($err_message);
     }
     if ($err_no === \E_ERROR || $err_no === \E_USER_ERROR) {
         drone()->stop();
     }
     return true;
     // error handled
 }
Esempio n. 4
0
 /**
  * Init
  */
 public function __construct()
 {
     $this->__session =& drone()->session;
 }
Esempio n. 5
0
 /**
  * Format log message
  *
  * @param string $message
  * @param int $level
  * @param string $category
  * @return string
  */
 public static function __formatMessage($message, $level, $category)
 {
     return '[' . date(self::$__date_format) . ' +' . drone()->timer() . '] [' . $category . '] [' . self::$__levels[$level] . '] ' . $message . (count(self::$__data) > 0 ? ' (' . self::__arrayToString(self::$__data) . ')' : '');
 }
Esempio n. 6
0
// drone()->log->setLogFile('_app/var/drone.log'); // set log file (optional)
//////////////////////////////////////////////////////////////////////////
// Settings
//////////////////////////////////////////////////////////////////////////
// framework settings
// \Drone\Registry::set(\Drone\Core::KEY_DEBUG, false); // debug mode - off for production
// \Drone\Registry::set(\Drone\Core::KEY_ERROR_BACKTRACE, false); // backtrace in log - off for production
// \Drone\Registry::set(\Drone\Core::KEY_ERROR_LOG, true); // errors to server log - on for production
//////////////////////////////////////////////////////////////////////////
// Error handlers
//////////////////////////////////////////////////////////////////////////
drone()->error(function ($error) {
    pa('<div style="color:#f00;">' . $error, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), '</div>');
});
drone()->error(404, function () {
    drone()->run('error->\\ErrorController->_404');
});
drone()->error(500, function () {
    drone()->run('error->\\ErrorController->_500');
});
//////////////////////////////////////////////////////////////////////////
// Hooks
//////////////////////////////////////////////////////////////////////////
// after hook that displays log example:
drone()->hook(\Drone\Core::HOOK_AFTER, function () {
    pa('', 'Log:', drone()->log->get());
});
//////////////////////////////////////////////////////////////////////////
// Mapped routes
//////////////////////////////////////////////////////////////////////////
// example: drone()->route(['/user/:id' => 'user->view']);
Esempio n. 7
0
/**
 * \Drone\View instance getter (drone()->view alias)
 *
 * @return \Drone\View
 */
function view()
{
    return drone()->view;
}
Esempio n. 8
0
 /**
  * Template to formatted path getter
  *
  * @param string $template (ex: 'my_template')
  * @return string (ex: '/var/www/proj/.../my_template.tpl')
  */
 public function template($template)
 {
     $template = Registry::get(Core::KEY_PATH_TEMPLATE) . self::__formatTemplate($template);
     if ($template === $this->__template) {
         drone()->error(Core::ERROR_500, 'View template loop detected');
         return '';
     }
     return $template;
 }
Esempio n. 9
0
 /**
  * Form fields values are valid
  *
  * @return boolean
  */
 public function isValid()
 {
     if (!$this->isSubmitted()) {
         return false;
     }
     $is_valid = true;
     foreach ($this->__fields as $k => &$f) {
         if (isset($f['rule'])) {
             foreach ($f['rule'] as $r => $v) {
                 if ($r === self::VALIDATE_MATCH) {
                     // valid match value
                     if (!drone()->data->validateMatch($this->getData($k), $this->getData($v['param'][0]))) {
                         $is_valid = false;
                         $f['error'][$r] = $v['message'];
                     }
                 } else {
                     self::__validate($r, $this->hasData($k) ? $this->__data[$k] : null, $f, $v, $is_valid);
                 }
             }
         }
     }
     return $is_valid;
 }
Esempio n. 10
0
<?php

/**
 * Drone - Rapid Development Framework for PHP 5.5.0+
 *
 * @package Drone
 * @version 0.2.3
 * @copyright 2015 Shay Anderson <http://www.shayanderson.com>
 * @license MIT License <http://www.opensource.org/licenses/mit-license.php>
 * @link <https://github.com/shayanderson/drone>
 */
namespace Drone;

// deny static requests (or mapped requests with no action)
drone()->deny();
/**
 * Drone abstract base Controller class
 *
 * @author Shay Anderson 06.14 <http://www.shayanderson.com/contact>
 */
abstract class Controller
{
}