public function __construct()
 {
     // Loader initialiseren
     $this->_loader = Loader::getInstance();
     // input class initialiseren
     $this->_input = new Input();
 }
Ejemplo n.º 2
0
 function __construct()
 {
     $this->titan = Loader::getInstance();
     // Get config elements
     $this->config = $this->titan->config('cache');
     // Set configurations
     $this->path = APP_DIR . $this->config['path'];
     $this->extension = $this->config['extension'];
     $this->default_expire_time = $this->config['default_expire_time'];
 }
Ejemplo n.º 3
0
 function __construct()
 {
     $this->titan = Loader::getInstance();
     if (ENVIRONMENT != 'production') {
         $this->config = $this->titan->config('db', 'dev');
     } else {
         $this->config = $this->titan->config('db');
     }
     require_once SYSTEM_DIR . 'plugins/Database.php';
     $this->db = Database::init($this->config);
 }
Ejemplo n.º 4
0
 function __construct()
 {
     // Configurations for security
     ini_set('session.cookie_httponly', 1);
     ini_set('session.use_only_cookies', 1);
     $this->titan = Loader::getInstance();
     // Getting config elements
     $this->config = $this->titan->config('config');
     // Initialize Session
     $this->init();
 }
Ejemplo n.º 5
0
function __($string, $variables = NULL)
{
    $filename = 'Locale/' . $_SESSION['lang' . APPKEY] . '.po';
    $loader = Loader::getInstance();
    $match = $loader->load($filename);
    $string = htmlspecialchars($string);
    $find = preg_match('/msgid "(' . $string . ')"\\nmsgstr "(.+)"/', $match, $matches);
    $find = htmlspecialchars_decode($find);
    if ($find) {
        return vsprintf($matches[2], $variables);
    } else {
        return vsprintf($string, $variables);
    }
}
Ejemplo n.º 6
0
 /**
  * 自定义路由
  * @param $uri
  * @return bool|int|string
  */
 private function customMapping($uri)
 {
     $mappings = Loader::getInstance()->getConfig(self::CONFIG_N_MAPPINGS, self::CONFIG_F_ROUTER);
     //将url与controller进行映射
     $matches = array();
     foreach ($mappings as $class_name => $mapping) {
         foreach ($mapping as $pattern) {
             $pattern = str_replace('/', '\\/', $pattern);
             if (preg_match("/{$pattern}/i", $uri, $matches)) {
                 Application::getInstance()->getDispatcher()->getRequest()->setRouterMatches($matches);
                 return $class_name;
             }
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 /**
  * Constructor for the core
  * it loads in all configuration and interfaces
  * and then continues to load all components.
  * When that's done the Loader component will be loaded in an instructed
  * to load the designated controller.
  */
 public function __construct()
 {
     // Include all configurations
     require_once "application/config/config.php";
     require_once "application/config/database.php";
     // Include all interfaces
     require_once "system/interfaces/isystemcomponent.php";
     require_once "system/interfaces/isystemcomponentdatacompatible.php";
     require_once "system/interfaces/icontroller.php";
     require_once "system/interfaces/imodel.php";
     require_once "system/interfaces/itable.php";
     // Include all components
     $sysFiles = glob("system/components/*.php");
     foreach ($sysFiles as $file) {
         require_once $file;
     }
     /*
      * If controller is not set default to
      * the default controller.
      * If the controller is set we use it. 
      */
     if (!isset($_GET["c"])) {
         $_GET["c"] = DEFAULT_CONTROLLER;
     }
     // Check for the controller's actual file.
     if (!file_exists("application/controllers/" . $_GET["c"] . ".php")) {
         if (DEBUG_MODE) {
             die("Couldn't find controller: " . $_GET["c"] . " :(");
         }
     }
     // Get it.
     require_once "application/controllers/" . $_GET["c"] . ".php";
     // Link it, detach the GET request and add the Controller affix.
     $controllerActual = $_GET["c"] . "Controller";
     $_GET["c"] = null;
     // Define the loader
     $this->load = Loader::getInstance();
     // Register the loader to the core
     self::$loader = Loader::getInstance();
     // Use the loader to load the controller
     $this->load->controller($controllerActual);
 }
Ejemplo n.º 8
0
 function lang($file = '', $key = '', $change = '')
 {
     global $lang;
     $titan = Loader::getInstance();
     $config = $titan->config('language');
     if (!is_string($file) || !is_string($key)) {
         return false;
     }
     $appLangDir = APP_DIR . 'languages/' . strtolower($config['languages'][get_lang()]) . '/' . strtolower($file) . '.php';
     $sysLangDir = SYSTEM_DIR . 'languages/' . strtolower($config['languages'][get_lang()]) . '/' . strtolower($file) . '.php';
     if (file_exists($appLangDir)) {
         require_once $appLangDir;
     } elseif (file_exists($sysLangDir)) {
         require_once $sysLangDir;
     }
     $zone = strtolower($file);
     if (array_key_exists($key, $lang[$zone])) {
         $str = $lang[$zone][$key];
         // Change special words
         if (!is_array($change)) {
             if (!empty($change)) {
                 return str_replace('%s', $change, $str);
             } else {
                 return $str;
             }
         } else {
             if (!empty($change)) {
                 $keys = [];
                 $vals = [];
                 foreach ($change as $key => $value) {
                     $keys[] = $key;
                     $vals[] = $value;
                 }
                 return str_replace($keys, $vals, $str);
             } else {
                 return $str;
             }
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 9
0
 public function bootstrap()
 {
     $bootstrapClass = Bootstrap_Abstract::YAF_DEFAULT_BOOTSTRAP;
     if (isset($this->_options['bootstrap'])) {
         $bootstrap = $this->_options['bootstrap'];
     } else {
         $bootstrap = $this->getAppDirectory() . DIRECTORY_SEPARATOR . $bootstrapClass . '.' . G::get('ext');
     }
     $loader = Loader::getInstance();
     if (Loader::import($bootstrap)) {
         if (!class_exists($bootstrapClass)) {
             throw new Exception('Couldn\'t find class Bootstrap in ' . $bootstrap);
         } else {
             $bootstrap = new $bootstrapClass();
             if (!$bootstrap instanceof Bootstrap_Abstract) {
                 throw new Exception('Expect a Yaf_Bootstrap_Abstract instance, ' . get_class($bootstrap) . ' give ');
             }
             if (version_compare(PHP_VERSION, '5.2.6') === -1) {
                 $class = new \ReflectionObject($bootstrap);
                 $classMethods = $class->getMethods();
                 $methodNames = array();
                 foreach ($classMethods as $method) {
                     $methodNames[] = $method->getName();
                 }
             } else {
                 $methodNames = get_class_methods($bootstrap);
             }
             $initMethodLength = strlen(Bootstrap_Abstract::YAF_BOOTSTRAP_INITFUNC_PREFIX);
             foreach ($methodNames as $method) {
                 if ($initMethodLength < strlen($method) && Bootstrap_Abstract::YAF_BOOTSTRAP_INITFUNC_PREFIX === substr($method, 0, $initMethodLength)) {
                     $bootstrap->{$method}($this->_dispatcher);
                 }
             }
         }
     } else {
         throw new Exception('Couldn\'t find bootstrap file ' . $bootstrap);
     }
     return $this;
 }
Ejemplo n.º 10
0
 public function __construct()
 {
     $this->titan = Loader::getInstance();
     // Getting config file
     $this->config = $this->titan->config('config');
     // Setting default controller and method
     $this->controller = $this->config['default_controller'];
     $this->method = $this->config['default_method'];
     // Setting controller directory
     if ($this->config['default_directory']) {
         $this->directory = 'controllers/' . $this->config['default_directory'] . '/';
     } else {
         $this->directory = 'controllers/';
     }
     // Getting current URL
     $this->url = $this->parseURL();
     // Getting routes
     $this->routes = $this->titan->config('routes');
     if ($this->run() === false) {
         // Getting Controller
         $this->set_controller($this->url);
         // Getting Method
         $this->set_action($this->url);
         // Getting parameters
         $this->set_params($this->url);
     }
     // Composer Autoload
     if ($this->config['composer'] == true) {
         if (file_exists('vendor/autoload.php')) {
             require_once 'vendor/autoload.php';
         } else {
             echo '<span style="color:#bc5858;"><strong>UYARI:</strong> Composer yükleyicisi bulunamadı.</span>';
         }
     }
     call_user_func_array([$this->controller, $this->method], $this->params);
 }
Ejemplo n.º 11
0
 public function __construct()
 {
     $this->loader = Loader::getInstance();
 }
Ejemplo n.º 12
0
 function __construct()
 {
     $this->titan = Loader::getInstance();
     // Getting config elements
     $this->config = $this->titan->config('config');
 }
Ejemplo n.º 13
0
 protected function initialize()
 {
     $arrConf = Loader::getInstance()->getConfig();
     if ($arrConf) {
         //初始化插件列表
         if (isset($arrConf['plugins'])) {
             foreach ($arrConf['plugins'] as $p) {
                 $plugin = new $p();
                 $this->_dispatcher->addPlugin($plugin);
             }
         }
         //初始化请求类
         if (isset($arrConf['request_class']) && $arrConf['request_class']) {
             $request = new $arrConf['request_class']();
             $this->_dispatcher->setRequest($request);
         }
         //初始化响应类
         if (isset($arrConf['response_class']) && $arrConf['response_class']) {
             $response = new $arrConf['response_class']();
             $this->_dispatcher->setResponse($response);
         }
         //初始化试图类
         if (isset($arrConf['view_class']) && $arrConf['view_class']) {
             $view = new $arrConf['view_class']();
             $this->_dispatcher->setView($view);
         }
         if (isset($arrConf['enable_debug']) && $arrConf['enable_debug']) {
             $this->setDebugEnabled(true);
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * @return Session
  */
 public function getSession()
 {
     return Loader::getInstance()->get('Session');
 }
Ejemplo n.º 15
0
 /**
  * 请求分发
  */
 public function dispatch()
 {
     if (!$this->_request) {
         $this->_request = new Request();
     }
     if (!$this->_response) {
         $this->_response = new Response();
     }
     if (!$this->_router) {
         $this->_router = new Router();
     }
     if (!$this->_view) {
         $this->_view = new View();
     }
     //router startup
     $this->executePlugins(Plugin::STEP_ROUTER_STARTUP);
     $class = $this->_router->mapping();
     //router shutdown
     $this->executePlugins(Plugin::STEP_ROUTER_SHUTDOWN);
     $controller = new $class();
     //dispatchloop startup
     $this->executePlugins(Plugin::STEP_DISPATCH_LOOP_STARTUP);
     //load current controller's interceptors
     self::$_interceptors = Loader::getInstance()->loadInterceptors($class);
     $this->executeInterceptor(Interceptor::INVOKE_BEFORE);
     while (true) {
         //preDispatch
         $this->executePlugins(Plugin::STEP_DISPATCH_STARTUP);
         $result = $controller->execute();
         //postDispatch
         $this->executePlugins(Plugin::STEP_DISPATCH_SHUTDOWN);
         if ($result instanceof Controller) {
             $controller = $result;
             continue;
         }
         break;
     }
     if (empty($result)) {
         //尝试根据controller名字自动加载视图
         $result = $this->getAutoView($class);
     }
     if (is_string($result)) {
         $this->_view->display($result);
     }
     $this->executeInterceptor(Interceptor::INVOKE_AFTER);
     //dispatch loop shutdown
     $this->executePlugins(Plugin::STEP_DISPATCH_LOOP_SHUTDOWN);
 }
Ejemplo n.º 16
0
 function csrf_check($token)
 {
     $titan = Loader::getInstance();
     $titan->plugin('session');
     if ($titan->session->is_exists('titan_token') && $token === $titan->session->get('titan_token')) {
         $titan->session->delete('titan_token');
         return true;
     }
     return false;
 }
Ejemplo n.º 17
0
 private function getController($appDir, $module, $controller)
 {
     $controllerDir = '';
     if ($this->_default_module == $module) {
         $controllerDir = $appDir . DIRECTORY_SEPARATOR . Loader::YAF_CONTROLLER_DIRECTORY_NAME;
     } else {
         $controllerDir = $appDir . DIRECTORY_SEPARATOR . Loader::YAF_MODULE_DIRECTORY_NAME . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . Loader::YAF_CONTROLLER_DIRECTORY_NAME;
     }
     $nameSeparator = G::iniGet('yaf.name_separator');
     if (G::iniGet('yaf.name_suffix') == true) {
         $classname = $controller . $nameSeparator . 'Controller';
     } else {
         $classname = 'Controller' . $nameSeparator . $controller;
     }
     if (!@class_exists($classname, false)) {
         if (!Loader::getInstance()->internal_autoload($controller, $controllerDir)) {
             throw new Exception\LoadFailed\Controller('Could not find controller script ' . $controllerDir . DIRECTORY_SEPARATOR . $controller . '.' . G::get('ext'));
         }
     }
     if (!class_exists($classname, false)) {
         throw new Exception\LoadFailed\LoadFailed('Could not find class ' . $classname . ' in controller script ' . $controllerDir);
     }
     return $classname;
 }
Ejemplo n.º 18
0
 function __construct()
 {
     $this->load =& Loader::getInstance();
     $this->init_all_hooks();
 }
Ejemplo n.º 19
0
 private function _doLoad($path)
 {
     return Loader::getInstance()->_load($path);
 }
Ejemplo n.º 20
0
 /**
  * Proxy method for Loader::getModel()
  */
 public function getModel($name)
 {
     return Loader::getInstance()->getModel($name);
 }
Ejemplo n.º 21
0
        $namespaces = self::$namespaces;
        $expl = explode('\\', $classname);
        foreach ($namespaces as $namespace => $nspath) {
            if ($expl[0] . '\\' == $namespace) {
                $reg_path = $nspath;
                break;
            }
        }
        $path = str_replace($expl[0], '', $classname);
        $dir = !empty($reg_path) ? $reg_path : __DIR__;
        $path = $dir . str_replace("\\", "/", $path) . '.php';
        if (file_exists($path)) {
            include_once $path;
        }
    }
    private function __construct()
    {
        // Init
        spl_autoload_register(array(__CLASS__, 'load'));
    }
    private function __clone()
    {
        // lock
    }
    public static function addNamespacePath($namespace, $path)
    {
        self::$namespaces[$namespace] = $path;
    }
}
Loader::getInstance();
Ejemplo n.º 22
0
 public function __construct($name, $version)
 {
     $this->name = $name;
     $this->version = $version;
     $this->NEMESIS = Loader::getInstance();
 }
Ejemplo n.º 23
0
 /**
  * 加载指定控制器的拦截器
  * @param $class
  * @return Interceptor[]
  */
 public function loadInterceptors($class)
 {
     $Interceptors = array();
     $interceptorClasses = array();
     $globalInterceptorClasses = Loader::getInstance()->getConfig('global', 'interceptor');
     if ($globalInterceptorClasses && is_array($globalInterceptorClasses)) {
         $interceptorClasses = $globalInterceptorClasses;
     }
     $classInterceptors = Loader::getInstance()->getConfig($class, 'interceptor');
     if (empty($classInterceptors)) {
         //@todo 获取基类Controller的拦截器
         $classInterceptors = Loader::getInstance()->getConfig('default', 'interceptor');
     }
     if ($classInterceptors && is_array($classInterceptors)) {
         $interceptorClasses = array_merge($interceptorClasses, $classInterceptors);
     }
     if ($interceptorClasses) {
         $interceptorClasses = array_unique($interceptorClasses);
         foreach ($interceptorClasses as $key => $className) {
             if (strpos($className, '!') === 0) {
                 unset($interceptorClasses[$key]);
                 $className = substr($className, 1);
                 $idx = array_search($className, $interceptorClasses);
                 if ($idx !== false) {
                     unset($interceptorClasses[$idx]);
                 }
                 continue;
             }
             if (class_exists($className)) {
                 $Interceptors[] = new $className();
             }
         }
     }
     return $Interceptors;
 }
Ejemplo n.º 24
0
                return $file;
            }
        }
        if (false !== ($pos = strrpos($class, '\\'))) {
            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
        } else {
            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
        }
        if (isset($this->prefixesPsr0[$first])) {
            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
                if (0 === strpos($class, $prefix)) {
                    foreach ($dirs as $dir) {
                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                            return $file;
                        }
                    }
                }
            }
        }
        foreach ($this->fallbackDirsPsr0 as $dir) {
            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                return $file;
            }
        }
        if ($this->useIncludePath && ($file = stream_resolve_include_path($logicalPathPsr0))) {
            return $file;
        }
    }
}
return Loader::getInstance();
Ejemplo n.º 25
0
 function query_debug($stop = false)
 {
     $titan = Loader::getInstance();
     $db = $titan->database();
     debug($db->last_query(), $stop);
 }
Ejemplo n.º 26
0
 public function __construct()
 {
     $this->_loader = Loader::getInstance();
     $this->parseUri();
 }
Ejemplo n.º 27
0
 public function __construct()
 {
     $this->titan = Loader::getInstance();
     $this->hook = $this->titan->config('hooks');
 }
Ejemplo n.º 28
0
 /**
  * Execute authorization by crypted password
  *
  * @param string $userId
  * @param string $password
  * @return boolean
  */
 public function crypt($userId, $password)
 {
     if ($this->_inputedUserId == null) {
         self::_showInput();
     }
     if ($userId != $this->_inputedUserId) {
         self::_failed();
     }
     $crypter = Loader::getInstance('Crypter', 'utility');
     $match = $crypter->compare($this->_inputedPassword, $password);
     if ($match == false) {
         self::_failed();
     }
     return true;
 }