public static function instance(Db $db, Container $row) { $key = sha1($db->db . $db->table . serialize($row->assoc())); $has = Instance::has('DbjsonModel', $key); if (true === $has) { return Instance::get('DbjsonModel', $key); } else { return Instance::make('DbjsonModel', $key, new self($db, $row)); } }
public function forward($action = 'index', $controller = null, $module = null) { $actualRoute = container()->getRoute(); if (null === $actualRoute && null === $controller && null === $module) { throw new Exception('Invalid forward.'); } if (null === $module) { $module = $actualRoute->getModule(); } if (null === $controller) { $controller = $actualRoute->getController(); } $route = new Container(); $route->setModule($module)->setController($controller)->setAction($action); context()->dispatch($route); exit; }
private function related(Container $obj) { $fields = array_keys($obj->assoc()); foreach ($fields as $field) { if (endsWith($field, '_id')) { if (is_string($field)) { $value = $obj->{$field}; if (!is_callable($value)) { $fk = repl('_id', '', $field); $ns = $this->ns; $cb = function () use($value, $fk, $ns) { $db = container()->nbm($fk, $ns); return $db->find($value); }; $obj->event($fk, $cb); $setter = lcfirst(Inflector::camelize("link_{$fk}")); $cb = function (Container $fkObject) use($obj, $field, $fk) { $obj->{$field} = $fkObject->getId(); $newCb = function () use($fkObject) { return $fkObject; }; $obj->event($fk, $newCb); return $obj; }; $obj->event($setter, $cb); } } } } return $obj; }
public function row($tab = array()) { $fields = array_keys($this->map['fields']); $pk = $this->pk(); $id = isAke($tab, $pk, false); if (count($tab)) { foreach ($tab as $key => $value) { if (!Arrays::in($key, $fields)) { unset($tab[$key]); } } foreach ($fields as $field) { $val = isAke($tab, $field, false); if (false === $val && false === $id) { $tab[$field] = null; } } } else { foreach ($fields as $field) { if (false === $id) { $tab[$field] = null; } } } $o = new Container(); $o->populate($tab); return $this->closures($o); }
public static function language() { $isCMS = null !== container()->getPage(); $session = session('web'); if (true === $isCMS) { if (count($_POST)) { if (ake('cms_lng', $_POST)) { $session->setLanguage($_POST['cms_lng']); } else { $language = $session->getLanguage(); $language = null === $language ? Cms::getOption('default_language') : $language; $session->setLanguage($language); } } else { $language = $session->getLanguage(); $language = null === $language ? Cms::getOption('default_language') : $language; $session->setLanguage($language); } } else { $route = Utils::get('appDispatch'); $language = $session->getLanguage(); if (null === $language || $language != $route->getLanguage()) { $language = null === $route->getLanguage() ? options()->getDefaultLanguage() : $route->getLanguage(); $session->setLanguage($language); } $module = $route->getModule(); $controller = $route->getController(); $action = $route->getAction(); $module = is_string($action) ? Inflector::lower($module) : $module; $controller = is_string($action) ? Inflector::lower($controller) : $controller; $action = is_string($action) ? Inflector::lower($action) : $action; $config = array(); $config['language'] = $language; $config['module'] = $module; $config['controller'] = $controller; $config['action'] = $action; $configLanguage = new Container(); $configLanguage->populate($config); container()->setLanguage(new Language($configLanguage)); } }
function request() { $tab = explode('?', $_SERVER['REQUEST_URI']); if (count($tab) > 1) { list($start, $query) = explode('?', $_SERVER['REQUEST_URI']); if (strlen($query)) { $str = parse_str($query, $output); if (count($output)) { foreach ($output as $k => $v) { $_REQUEST[$k] = $v; } } } } $object = new Container(); $object->populate($_REQUEST); $uri = substr($_SERVER['REQUEST_URI'], 1, strlen($_SERVER['REQUEST_URI'])); $object->setThinUri(explode('/', $uri)); return $object; }
public function row(array $values) { $class = $this; $obj = new Container(); $key = $this->key; $record = function () use($class, $obj, $key) { $tab = $obj->assoc(); return $class->push($key, $tab); }; $purge = function () use($class, $obj, $key) { $tab = $obj->assoc(); return $class->pop($key, $tab['id']); }; $date = function ($f) use($obj) { return date('Y-m-d H:i:s', $obj->{$f}); }; $hydrate = function ($data) use($obj) { if (Arrays::isAssoc($data)) { foreach ($data as $k => $v) { $obj->{$k} = $v; } } return $obj; }; $display = function ($field) use($obj) { return \Thin\Html\Helper::display($obj->{$field}); }; $tab = function () use($obj) { return $obj->assoc(); }; $asset = function ($field) use($obj) { return '/storage/img/' . $obj->{$field}; }; $obj->event('record', $record)->event('purge', $purge)->event('date', $date)->event('hydrate', $hydrate)->event('tab', $tab)->event('asset', $asset)->event('display', $display); return $obj->populate($values); }
private function related(Container $obj) { $fields = array_keys($obj->assoc()); foreach ($fields as $field) { if (fnmatch('*_id', $field)) { if (is_string($field)) { $value = $obj->{$field}; if (!is_callable($value)) { $fk = str_replace('_id', '', $field); $ns = $this->db; $cb = function () use($value, $fk, $ns) { $db = jdb($ns, $fk); return $db->find($value); }; $obj->event($fk, $cb); $setter = lcfirst(Inflector::camelize("link_{$fk}")); $cb = function (Container $fkObject) use($obj, $field, $fk) { $obj->{$field} = $fkObject->id; $newCb = function () use($fkObject) { return $fkObject; }; $obj->event($fk, $newCb); return $obj; }; $obj->event($setter, $cb); } } } } return $obj; }
public function toObject($tab = array()) { $o = new Container(); $o->populate($tab); return $this->functions($o); }
public static function forward($name) { $route = static::getRouteByName($name); if (null !== $route) { $module = isAke($route, 'module', 'www'); $controller = isAke($route, 'controller', 'static'); $action = isAke($route, 'action', 'index'); $route = new Container(); $route->setModule($module)->setController($controller)->setAction($action); context()->dispatch($route); exit; } }
/** * @param string $name * @param array $context * @return string */ public function render($name, array $context = []) { $context = array_merge($context, ['route' => $this->app->getRoute(), 'baseUrl' => $this->app['request']->getBasePath(), 'theme' => $this->app['config']->get('theme')]); return $this->environment->render($name, $context); }