Ejemplo n.º 1
0
 public function __construct(Database $model)
 {
     /* CLI case */
     if (!defined('APPLICATION_ENV')) {
         define('APPLICATION_ENV', 'production');
     }
     $this->model = $model;
     $ageChange = $model->cache()->get(sha1($model->dir));
     $ageDb = $model->cache()->get(sha1($model->dir) . '_ageDb');
     $dbFile = Config::get('directory.store', STORAGE_PATH) . DS . $model->db . '_' . APPLICATION_ENV . '.db';
     $this->db = new PDO('sqlite:' . $dbFile);
     umask(00);
     chmod($dbFile, 0777);
     $populate = true;
     if (strlen($ageDb) && strlen($ageChange)) {
         if ($ageDb > $ageChange) {
             $populate = false;
         } else {
             $model->cache()->del(sha1($model->dir) . '_ageDb');
         }
     }
     if ($populate) {
         $this->populate();
     }
 }
Ejemplo n.º 2
0
 public function __construct(Database $model)
 {
     /* CLI case */
     if (!defined('APPLICATION_ENV')) {
         define('APPLICATION_ENV', 'production');
     }
     $this->model = $model;
     $this->db = Database::instance('system', 'archive');
 }
Ejemplo n.º 3
0
 public static function __callStatic($method, $args)
 {
     $db = Inflector::uncamelize($method);
     if (fnmatch('*_*', $db)) {
         list($database, $table) = explode('_', $db, 2);
     } else {
         $database = SITE_NAME;
         $table = $db;
     }
     if (!count($args)) {
         return Db::instance($database, $table);
     } elseif (count($args) == 1) {
         $id = Arrays::first($args);
         if (is_numeric($id)) {
             return Db::instance($database, $table)->find($id);
         }
     }
 }
Ejemplo n.º 4
0
 public static function flush($db = null, $table = null, $name = null)
 {
     $db = is_null($db) ? '*' : $db;
     $table = is_null($table) ? '*' : $table;
     $name = is_null($name) ? '*' : Inflector::urlize($name, '.');
     if ($db != '*' && $table != '*') {
         $cache = Database::instance($db, $table)->cache();
     } else {
         $cache = Database::instance('auth', 'user')->cache();
     }
     $hashes = $cache->keys("dbjson::cachedQueries::{$db}::{$table}");
     $ages = $cache->keys("dbjson::cachedQueries::{$db}::{$table}::{$name}::age");
     if (count($hashes)) {
         foreach ($hashes as $hash) {
             $cache->del($hash);
         }
     }
     if (count($ages)) {
         foreach ($ages as $age) {
             $cache->del($age);
         }
     }
 }
Ejemplo n.º 5
0
 public static function __callStatic($method, $args)
 {
     $instance = Db::instance(static::$database, static::$table);
     return call_user_func_array([$instance, $method], $args);
 }
Ejemplo n.º 6
0
 function coreCache()
 {
     return \Dbjson\Dbjson::instance();
 }
Ejemplo n.º 7
0
Archivo: Jdb.php Proyecto: schpill/thin
 public static function instance($db, $table)
 {
     return Driver::instance($db, $table);
 }
Ejemplo n.º 8
0
Archivo: jma.php Proyecto: noikiy/inovi
if (false === $isAuth && true === context()->isPost()) {
    $login = $request->getLogin();
    $password = $request->getPassword();
    if (!is_null($login) && !is_null($password)) {
        $count = $dbAuth->where("login = {$login}")->where('password = '******'Wrong credentials.';
    }
}
if (true === $isAuth) {
    $session->setAuth($isAuth);
    \Dbjson\Dbjson::tables();
    $action = $request->getAction();
    $action = is_null($action) ? 'home' : $action;
    $dbTable = jmodel('jma_table');
    $tables = $dbTable->fetch()->order(array('name', 'ns'))->exec();
    $rma = new Jma();
    $content = $rma->content($action, $tables);
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>jsonMyAdmin</title>
        <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.css" media="screen" rel="stylesheet" type="text/css" />
        <link href="http://fonts.googleapis.com/css?family=Oswald:400,300,700|Questrial:400,300,700,900,600&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css" />
Ejemplo n.º 9
0
function jdbView(DBJ $db, $nameView)
{
    $database = $db->db;
    $table = $db->table;
    $file = APPLICATION_PATH . DS . 'models' . DS . 'Views' . DS . $database . DS . ucfirst(strtolower($table)) . DS . strtolower($nameView) . '.php';
    if (File::exists($file)) {
        $config = (include $file);
        return $db->view($config);
    } else {
        throw new Exception($nameView . ' does not exist.');
    }
}
Ejemplo n.º 10
0
 public static function depopulate($database = null)
 {
     $database = is_null($database) ? SITE_NAME : $database;
     $tables = glob(Config::get('directory.store', STORAGE_PATH) . DS . 'dbjson' . DS . $database . '_' . APPLICATION_ENV . DS . '*');
     $tableDir = Arrays::first($tables);
     $table = Arrays::last(explode(DS, $tableDir));
     $db = Db::instance($database, $table);
     $db->cache()->flushall();
 }
Ejemplo n.º 11
0
 public function create($db, $table, Closure $next = null)
 {
     $this->model = Database::instance($db, $table);
     $this->singular = ucfirst($table);
     $this->plural = substr($this->singular, -1) != 's' ? $this->singular . 's' : $this->singular;
     $this->order = 'id';
     if (!is_null($next)) {
         $next($this);
     }
 }