/** * @return string */ public function make_uri() { $args = func_get_args(); if (!$this->make_uri_method) { $this->make_uri_method = Core_Types::reflection_for(CMS::$current_mapper)->getMethod('make_uri'); } return $this->make_uri_method->invokeArgs(CMS::$current_mapper, $args); }
/** * Запускает CLI-приложение * * @param array $argv */ public static function run_module(array $argv) { Core::load($argv[0]); if (Core_Types::reflection_for($module = Core_Types::real_class_name_for($argv[0]))->implementsInterface('CLI_RunInterface')) { return call_user_func(array($module, 'main'), $argv); } else { throw new CLI_NotRunnableModuleException($argv[0]); } }
static function register_type() { $args = func_get_args(); foreach ($args as $class) { $instance = Core_Types::reflection_for($class)->newInstance(); $type = $instance->type(); self::$types[$type] = $instance; } }
protected function get_title($item) { $title = false; if (!$this->component) { return false; } $component_class_name = CMS::component_class_name($this->component); if ($component_class_name) { $title = Core_Types::reflection_for($component_class_name)->getStaticPropertyValue('admin_vars_title', false); if (!$title) { $title = "Настройки: {$component_class_name}"; } if ($item->id > 0 && trim($item->title) != '') { $title .= ': ' . $item->title; } } return $title; }
/** * Создает объект заданного класса с массивом значений параметров конструктора * * @param string $class * @param array $parms * * @return object */ public static function amake($class, array $parms) { self::push_dir(); $class = self::replace_class($class); $real_name = Core_Types::real_class_name_for($class); self::autoload($class, $real_name); $reflection = Core_Types::reflection_for($real_name); self::pop_dir(); return $reflection->getConstructor() ? $reflection->newInstanceArgs($parms) : $reflection->newInstance(); }
public function process($data) { foreach ($data as $title => $item) { if (is_string($item) && trim($item) == '' && ($m = Core_Regexps::match_with_results('{^\\%(.+)$}', trim($title)))) { $_component = trim($m[1]); $_parms = false; if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $_component)) { $_component = $m[1]; $_parms = trim($m[2]); } if (CMS::component_exists($_component)) { $_class = CMS::$component_names[$_component]; $_classref = Core_Types::reflection_for($_class); $links = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms)) : array(); foreach ($links as $k => $v) { if (is_string($v)) { $v = array('url' => $v); } $v["from-{$_component}"] = 1; $links[$k] = $v; } $this->process($links); } } else { $this->add($title, $item); } } }
protected function entity_reflection() { if ($this->entity_reflection) { return $this->entity_reflection; } $this->entity_reflection = Core_Types::reflection_for(Core_Strings::replace($this->entity, '.', '_')); return $this->entity_reflection; }
public function add_item($link, $level, $parent = null) { $access = isset($link->access) ? trim($link->access) : ''; if ($access != '' && !CMS::check_globals_or($access)) { return $this; } if (empty($link->url) && empty($link->id) && ($m = Core_Regexps::match_with_results('{^\\%(.+)$}', trim($link->title)))) { $_component = trim($m[1]); $_parms = false; if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $_component)) { $_component = $m[1]; $_parms = trim($m[2]); } if (CMS::component_exists($_component)) { $_class = CMS::$component_names[$_component]; $_classref = Core_Types::reflection_for($_class); $links = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms)) : array(); foreach ($links as $k => &$v) { $v["from-{$_component}"] = 1; } return $this->load_data($links, $level, $parent); } return $this; } return parent::add_item($link, $level, $parent); }
public function add($title, $item) { if (!Core_Types::is_iterable($item)) { $item = array('uri' => $item, 'url' => $item); } if (isset($item['title'])) { $title = $item['title']; } $title = CMS::lang($title); //Events::dispatch('cms.navigation.add', $ev = Events::Event(array('title' => $title, 'data' => $item, 'url' => $item['url']))); //$title = $ev['title']; //$item = $ev['data']; //$item['url'] = $ev['url']; $url = $item['url']; Events::call('cms.navigation.add', $title, $item, $url); $item['url'] = $url; $access = isset($item['access']) ? trim($item['access']) : ''; if ($access != '' && !CMS::check_globals_or($access)) { return $this; } if (isset($item['disabled'])) { if (CMS::check_yes($item['disabled'])) { return $this; } } $uri = ''; if (isset($item['uri'])) { $uri = $item['uri']; } if (isset($item['url'])) { $uri = $item['url']; } $id = isset($item['id']) ? $item['id'] : md5($title . $uri); if (isset($item['navigation_id'])) { $id = trim($item['navigation_id']); } $selected = false; $disabled = false; if (isset($item['match'])) { if (preg_match($item['match'], CMS_Navigation3::$uri)) { $selected = true; } } if (isset($item['flag'])) { if (CMS::$navigation->is_flag($item['flag'])) { $selected = true; } } if ($uri == CMS_Navigation3::$uri) { $selected = true; } $item['selected'] = $selected; $item['disabled'] = $disabled; $sub = isset($item['sub']) ? $item['sub'] : null; if (is_string($sub)) { $sub = trim($sub); $_component = $sub; $_parms = $uri; if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $sub)) { $_component = trim($m[1]); $_parms = trim($m[2]); } if (CMS::component_exists($_component)) { $_class = CMS::$component_names[$_component]; $_classref = Core_Types::reflection_for($_class); $sub = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms, $item)) : false; } } if (Core_Types::is_iterable($sub)) { $set = new CMS_Navigation3_LinkSet(); $set->level_num = $this->level_num + 1; $set->process($sub); $this->link($id, $uri, $title, $item, $set); } else { $this->link($id, $uri, $title, $item); } return $this; }
public static function access($realm, $extra_auth_callback = null) { if (!$realm) { return array(); } if (isset(self::$realms[$realm]) && self::$realms[$realm]) { return self::$realms[$realm]; } $data = false; $cfg_name = "{$realm}_realm"; $cfg = WS::env()->config; if (isset($cfg->{$cfg_name})) { $data = (array) $cfg->{$cfg_name}; } elseif (isset(CMS::$restricted_realms[$realm])) { $data = CMS::$restricted_realms[$realm]; } else { return self::$realms[$realm] = false; } if (!$data) { return self::$realms[$realm] = false; } if ($realm == CMS::$admin_realm) { CMS::$in_admin = true; } if (isset($data['page_404'])) { CMS::$page_404 = $data['page_404']; } if (isset($data['navigation_var'])) { Core::load(CMS::$nav_module); Core_Types::reflection_for(CMS::$nav_module)->setStaticPropertyValue('var', $data['navigation_var']); } $user = false; if (isset($data['auth_type']) && $data['auth_type'] == 'basic' || !isset($data['auth_type'])) { $user = WS::env()->admin_auth->user; } if ($user) { $client = false; $access = false; $mp = false; self::passwords($data, $user, $client, $access, $mp); Core::load('Net.HTTP.Session'); $session = Net_HTTP_Session::Store(); if (!$access && isset($session['auth_url_access']) && $session['auth_url_access']) { $access = true; $mp = $session['auth_url_parms']; } if (!$access && isset($data['auth_url'])) { Core::load('Net.Agents.HTTP'); $url = $data['auth_url']; $agent = Net_HTTP::Agent(); $res = $agent->with_credentials($user->login, $user->password)->send(Net_HTTP::Request($url)); if ($res->status->code == '200') { $r = trim($res->body); if ($r == 'ok' || $r == 'ok:') { $access = true; } else { if ($m = Core_Regexps::match_with_results('{^ok:(.+)$}', $r)) { $access = true; $mp = trim($m[1]); } } } if ($access) { $session['auth_url_access'] = true; $session['auth_url_parms'] = $mp; } } if (!$access) { $args = array($user->login, $user->password, $realm); if (Core_Types::is_callable($extra_auth_callback)) { $extra_auth = Core::invoke($extra_auth_callback, $args); } else { $extra_auth = self::extra_auth($args[0], $args[1], $args[2]); } if ($extra_auth || Core_Types::is_iterable($extra_auth)) { $mp = $extra_auth; $access = true; } else { return self::$realms[$realm] = false; } } $auth_parms = self::auth_parms($mp, $client); $user->parms = $auth_parms; if ($access) { return self::$realms[$realm] = array('data' => $data, 'auth_parms' => $auth_parms); } } else { return self::$realms[$realm] = false; } return self::$realms[$realm] = false; }
/** * Возвращает все строки результата * * @params string|array|ArrayAccess $prototype Прототип объекта записи или имя класса такого объекта * @params mixed $key свойство объекта $row * * @return mixed * @throws Core_InvalidArgumentTypeException Не верный $prototype */ public function fetch_all($prototype = null, $key = null) { switch (true) { case $prototype == null: $result = Core::make(DB::option('collection_class')); break; case Core_Types::is_string($prototype): $result = Core_Types::reflection_for($prototype)->newInstance(); break; case Core_Types::is_array($prototype): $result = $prototype; break; case $prototype instanceof ArrayAccess: $result = clone $prototype; break; default: throw new Core_InvalidArgumentTypeException('prototype', $prototype); } while ($row = $this->fetch()) { if (is_null($key) || !isset($row[$key])) { $result[] = $row; } else { $result[$row[$key]] = $row; } } return $result; }
public function test_reflection_for() { $this->assertInstanceOf('ReflectionClass', Core_Types::reflection_for($this)); $this->assertInstanceOf('ReflectionClass', Core_Types::reflection_for('CoreTypesTest')); }
/** * Трансформирует wiki-разметку в HTML * * @param string $src * * @return string */ static function parse_wiki($src, $config = array()) { if (!self::$wiki_parser) { Core::load(self::$wiki_parser_module); self::$wiki_parser = Core_Types::reflection_for(str_replace('.', '_', self::$wiki_parser_module))->newInstance(); } return self::$wiki_parser->parse($src, $config); }
public function map($name, $type) { $this->map[$name] = Core_Types::reflection_for("{$this->prefix}{$type}"); return $this; }
/** * @param WebKit_Environment $env * @param WebKit_HTTP_Response $response * * @return mixed */ public function dispatch(WS_Environment $env, $response) { if ($route = $this->mapper->route($env->request)) { try { Core::load($module = $route['controller']); return Core_Types::reflection_for($module)->newInstance($env, $response)->dispatch($route); } catch (Core_ModuleException $e) { throw new WebKit_Controller_BadControllerException($module, $e->getMessage()); } catch (ReflectionException $e) { throw new WebKit_Controller_BadControllerException($module, $e->getMessage()); } } else { return Net_HTTP::not_found(); } //throw new WebKit_Controller_NoRouteException($env->request->urn); }
/** * @param string $class * * @return Dev_Unit_TestLoader */ public function from_class($class) { $class = (string) $class; if (Core_Types::is_subclass_of('Dev.Unit.TestCase', $class)) { $reflection = Core_Types::reflection_for($class); if ($reflection->hasMethod('run_test')) { $this->suite->append(Core::make($class)); } else { foreach ($reflection->getMethods() as $method) { if (Core_Strings::starts_with($method->getName(), Dev_Unit::TEST_METHOD_SIGNATURE)) { $this->suite->append(Core::make($class, $method->getName())); } } } } return $this; }
public function __call($method, $args) { switch ($method) { case 'columns': $this->set_columns($args); break; case 'from': case 'where': case 'having': case 'order_by': case 'group_by': foreach (Core_Arrays::flatten($args) as $arg) { $target =& $this->{$method}; $target[] = $arg; } break; case 'left_join': case 'right_join': case 'inner_join': case 'outer_join': $this->joins[] = array(Core_Strings::upcase(Core_Strings::replace($method, '_join', '')), Core_Arrays::shift($args), $args); break; default: return Core_Types::reflection_for($sql = $this->find_statement($method))->getMethod('run')->invokeArgs($sql, $args); } return $this; }
private function load_from_component($_component, $_parms) { if (CMS::component_exists($_component)) { $_class = CMS::$component_names[$_component]; $_classref = Core_Types::reflection_for($_class); return $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(null, array($_parms, $this)) : false; } return false; }