public function newRow($data = array()) { $object = o(sha1(time() . $this->settings['entity'] . session_id() . Utils::token())); $object->thin_litedb = $this; $object->id = null; if (count($data) && Arrays::isAssoc($data)) { foreach ($this->settings['modelFields'] as $field => $infos) { $value = ake($field, $data) ? $data[$field] : null; $object->{$field} = $value; } } return $object; }
public function __construct($namespace, $ttl = 3600) { $ns = 'thin_' . $namespace; $c = cookies()->{$ns}; if (null === $c) { setcookie($ns, Utils::token(), strtotime('+1 year')); } else { setcookie($ns, $c, strtotime('+1 year')); } $key = cookies()->{$ns}; $this->__namespace = $namespace . '::' . $key; $this->__ttl = $ttl; $this->__db = redisDB::instance('core', 'session'); $this->clean(); $this->populate(); }
private function nextId() { return sha1(Utils::UUID() . Utils::token() . time()); }
public function offsetExists($key) { $check = Utils::token(); return $check != isAke($this->_data, $key, $check); }
public static function has($key) { $dummy = Utils::token(); return $dummy != static::get($key, $dummy); }
private function closures($obj) { $db = $this; $db->results = null; $db->wheres = null; $save = function () use($obj, $db) { return $db->save($obj); }; $database = function () use($db) { return $db; }; $delete = function () use($obj, $db) { return $db->deleteRow($obj->id); }; $deleteSoft = function () use($obj, $db) { $obj->deleted_at = time(); return $db->save($obj); }; $id = function () use($obj) { return isset($obj->id) ? $obj->id : null; }; $exists = function () use($obj) { return isset($obj->id); }; $touch = function () use($obj) { if (!isset($obj->created_at)) { $obj->created_at = time(); } $obj->updated_at = time(); return $obj; }; $duplicate = function () use($obj, $db) { $obj->copyrow = Utils::token(); $data = $obj->assoc(); unset($data['id']); unset($data['created_at']); unset($data['updated_at']); $obj = $db->row($data); return $obj->save(); }; $hydrate = function ($data = []) use($obj) { $data = empty($data) ? $_POST : $data; if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { if ('true' == $v) { $v = true; } elseif ('false' == $v) { $v = false; } elseif ('null' == $v) { $v = null; } $obj->{$k} = $v; } } return $obj; }; $date = function ($field, $format = 'Y-m-d H:i:s') use($obj) { return date($format, $obj->{$field}); }; $string = function () use($obj) { if (isset($obj->name)) { return $obj->name; } return $obj->id; }; $model = function () use($db, $obj) { return Model::instance($db, $obj); }; $obj->event('save', $save)->event('delete', $delete)->event('deletesoft', $deleteSoft)->event('date', $date)->event('exists', $exists)->event('id', $id)->event('db', $database)->event('touch', $touch)->event('hydrate', $hydrate)->event('string', $string)->event('model', $model)->event('duplicate', $duplicate); $settings = isAke(self::$config, "{$this->db}.{$this->table}"); $functions = isAke($settings, 'functions'); if (!empty($functions)) { foreach ($functions as $closureName => $callable) { $closureName = lcfirst(Inflector::camelize($closureName)); if (Arrays::is($callable)) { list($callable, $callableArgs) = $callable; } else { $callableArgs = []; } $share = function () use($obj, $callable, $db, $callableArgs) { $args = []; if (!empty($callableArgs)) { $args[] = $callableArgs; } $args[] = $obj; $args[] = $db; return call_user_func_array($callable, $args); }; $obj->event($closureName, $share); } } return $this->related($obj); }
public function has($key) { $dummy = Utils::token(); return $dummy != $this->get($key, $dummy); }
public function hasEvent($key) { $check = Utils::token(); return $check != isake($this->_events, $key, $check); }
public function __isset($key) { $check = Utils::token(); return $check != isake($this->_data, $key, $check); }
public function __construct($app = 'core') { $this->__token = sha1($app . Utils::token()); }
public function token() { return Utils::token(); }
public function __construct($object) { $this->object = $object; $this->token = Utils::token(); $this->hooks[$this->token] = []; }
private function authorize($publicKey, $privateKey) { $exists = Raw::ApiUser()->where(['public_key', '=', (string) $publicKey])->where(['private_key', '=', (string) $privateKey])->first(true); if ($exists) { $token = Utils::token(); $row = Raw::ApiAuth()->firstOrCreate(['user_id' => (int) $exists->id]); $row->setToken($token)->setExpiration(time() + 3600)->save(); Api::render(['status' => 200, 'execution_time' => Timer::get(), 'token' => $token]); } Api::forbidden(); }
function setLocationAsync($object, $address) { $address = str_replace(["\n", "\r", ', ', ','], ' ', $address); $address = str_replace([' '], ' ', $address); $cb = function ($id, $db, $table, $address) { $object = rdb($db, $table)->findOrFail($id); $coords = lib('geo')->getCoords($address, 250); setLocation($object, $coords['lng'], $coords['lat']); }; lib('later')->set('setLocationAsync.' . Utils::token(), $cb, [$object->id, $object->db()->db, $object->db()->table, $address]); lib('later')->background(); }
private function closures($obj) { $db = $this->model; $db->results = null; $db->wheres = null; $save = function () use($obj, $db) { return $db->save($obj); }; $database = function () use($db) { return $db; }; $delete = function () use($obj, $db) { return $db->deleteRow($obj->id); }; $id = function () use($obj) { return $obj->id; }; $exists = function () use($obj) { return isset($obj->id); }; $touch = function () use($obj) { if (!isset($obj->created_at)) { $obj->created_at = time(); } $obj->updated_at = time(); return $obj; }; $duplicate = function () use($obj, $db) { $obj->copyrow = Utils::token(); $data = $obj->assoc(); unset($data['id']); unset($data['created_at']); unset($data['updated_at']); $obj = $db->row($data); return $obj->save(); }; $hydrate = function ($data = []) use($obj) { $data = empty($data) ? $_POST : $data; if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { if ('true' == $v) { $v = true; } elseif ('false' == $v) { $v = false; } elseif ('null' == $v) { $v = null; } $obj->{$k} = $v; } } return $obj; }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $obj->event('save', $save)->event('delete', $delete)->event('date', $date)->event('exists', $exists)->event('id', $id)->event('db', $database)->event('touch', $touch)->event('hydrate', $hydrate)->event('duplicate', $duplicate); $settings = isAke(Db::$config, "{$this->model}->db.{$this->model}->table"); $functions = isAke($settings, 'functions'); if (count($functions)) { foreach ($functions as $closureName => $callable) { $closureName = lcfirst(Inflector::camelize($closureName)); $share = function () use($obj, $callable, $db) { $args[] = $obj; $args[] = $db; return call_user_func_array($callable, $args); }; $obj->event($closureName, $share); } } return $this->related($obj); }