Example #1
0
 public static function getMemcachedInstance($storageEngineConfig = null)
 {
     $serverIp = '';
     $serverPort = '';
     if (!is_null($storageEngineConfig)) {
         $serverIp = $storageEngineConfig['ip'];
         $serverPort = $storageEngineConfig['port'];
     } else {
         $registry = \Litpi\Registry::getInstance();
         $conf = $registry->get('conf');
         $serverIp = $conf['memcached'][0]['ip'];
         $serverPort = $conf['memcached'][0]['port'];
     }
     $output = null;
     try {
         $memcached = null;
         if (class_exists('Memcached', false)) {
             $memcached = new \Memcached();
             $memcached->addServer($serverIp, $serverPort);
         } else {
             //Wrapper memcache in Windows
             $memcached = new \Litpi\Memcached();
             $memcached->addServer($serverIp, $serverPort);
         }
         $output = $memcached;
     } catch (\Exception $e) {
         //Can not connect to Memcache Server
         echo 'Can not connect to Memcache Server';
     }
     return $output;
 }
Example #2
0
function rewriteruleParsing($route)
{
    $registry = \Litpi\Registry::getInstance();
    $conf = $registry->get('conf');
    ////////////////////////////
    // Parsing Route to get MODULE, CONTROLLER & ACTION
    $parts = explode('/', $route);
    $module = '';
    $controller = '';
    $action = '';
    if ($parts[0]) {
        $module = $parts[0];
    }
    if (!empty($parts[1])) {
        $controller = $parts[1];
        if (!empty($parts[2])) {
            $action = $parts[2];
        } else {
            $action = 'index';
            $route = $module . '/' . $controller . '/' . 'index';
        }
    } else {
        $controller = 'index';
        $action = 'index';
        $route = $module . '/' . 'index' . '/' . 'index';
    }
    $registry->set('module', $module);
    $registry->set('controller', $controller);
    $registry->set('action', $action);
    $registry->set('route', $route);
    return $route;
}
Example #3
0
 public function _before(\Codeception\TestCase $test)
 {
     require_once \Codeception\Configuration::projectDir() . 'src/includes/autoload.php';
     require_once \Codeception\Configuration::projectDir() . 'src/includes/classmap.php';
     require_once \Codeception\Configuration::projectDir() . 'src/Vendor/autoload.php';
     spl_autoload_register('autoloadlitpi');
     include_once \Codeception\Configuration::projectDir() . 'src/libs/smarty/Smarty.class.php';
     //Overwrite remoteaddr
     $_SERVER['REMOTE_ADDR'] = $this->config['remoteaddr'];
     //INIT REGISTRY VARIABLE - MAIN STORAGE OF APPLICATION
     $registry = \Litpi\Registry::getInstance();
     $request = \Litpi\Request::createFromGlobals();
     $response = new \Litpi\Response();
     $session = new \Litpi\Session();
     $registry->set('request', $request);
     $registry->set('response', $response);
     $registry->set('session', $session);
     require_once \Codeception\Configuration::projectDir() . 'src/includes/conf.php';
     require_once \Codeception\Configuration::projectDir() . 'src/includes/config.php';
     require_once \Codeception\Configuration::projectDir() . 'src/includes/setting.php';
     $registry->set('conf', $conf);
     $registry->set('setting', $setting);
     $registry->set('https', PROTOCOL == 'https' ? true : false);
     require_once \Codeception\Configuration::projectDir() . 'src/includes/permission.php';
     $registry->set('groupPermisson', $groupPermisson);
     require_once \Codeception\Configuration::projectDir() . 'src/includes/rewriterule.php';
     require_once \Codeception\Configuration::projectDir() . 'src/includes/startup.php';
     $this->registry = $registry;
     $this->client = new \Codeception\Lib\Connector\LitpiConnectorHelper();
     $this->client->setRegistry($this->registry);
 }
Example #4
0
 /**
  * Luu thong tin vao cache
  *
  */
 public static function cacheSet($key, $value)
 {
     $registry = \Litpi\Registry::getInstance();
     $setting = $registry->get('setting');
     $myCacher = new \Litpi\Cacher($key);
     $duration = $setting['apc']['shortDelay'];
     return $myCacher->set($value, $duration);
 }
Example #5
0
function rewriteruleParsing($route)
{
    $registry = \Litpi\Registry::getInstance();
    $setting = $registry->get('setting');
    $conf = $registry->get('conf');
    $partTmps = explode('/', $route);
    //Refine empty part from parts
    $parts = array();
    foreach ($partTmps as $part) {
        $part = trim($part);
        if ($part != '') {
            $parts[] = $part;
        }
    }
    // Fallback for frontend site
    if ($route == '') {
        $route = 'site/index/index';
    }
    ////////////////////////////
    // Parsing Route to get MODULE, CONTROLLER & ACTION
    $parts = explode('/', $route);
    $module = '';
    $controller = '';
    $action = '';
    if ($parts[0]) {
        $module = $parts[0];
    }
    if (!empty($parts[1])) {
        $controller = $parts[1];
        if (!empty($parts[2])) {
            $action = $parts[2];
        } else {
            $action = 'index';
            $route = $module . '/' . $controller . '/' . 'index';
        }
    } else {
        $controller = 'index';
        $action = 'index';
        $route = $module . '/' . 'index' . '/' . 'index';
    }
    $registry->set('module', $module);
    $registry->set('controller', $controller);
    $registry->set('action', $action);
    $registry->set('route', $route);
    return $route;
}
Example #6
0
 /**
  * Ham dung de test general security token
  *
  * duoc tao trong $_SESSION['securityToken'] va duoc truyen vao bang $_GET['token']
  *
  */
 public static function checkSecurityToken()
 {
     $registry = new \stdClass();
     $registry = \Litpi\Registry::getInstance();
     $request = $registry->get('request');
     $session = $registry->get('session');
     return $request->query->get('token') == $session->get('securityToken');
 }
Example #7
0
<?php

$registry = \Litpi\Registry::getInstance();
define('PROTOCOL', \Litpi\Router::getProtocol($registry));
$conf['host'] = HOST;
$conf['rooturl'] = PROTOCOL . '://' . $conf['host'] . '/';
$conf['rooturl_admin'] = PROTOCOL . '://' . $conf['host'] . '/admin/';
ini_set('session.name', 'SHASH');
ini_set('session.use_only_cookies', true);
ini_set('session.use_trans_sid', false);
Example #8
0
 public static function cacheBuildKeystringDetail($userid)
 {
     $registry = \Litpi\Registry::getInstance();
     $setting = $registry->get('setting');
     return $setting['site']['cacheKeyPrefix'] . 'userdetail_' . $userid;
 }
Example #9
0
 public static function getDb()
 {
     $registry = \Litpi\Registry::getInstance();
     return $registry->get('db');
     //return $GLOBALS['db'];
 }