protected function preprocess($template, $name, $data) { parent::preprocess($template, $name, $data); $class_name = $this->css_class_name($name, $data); $parms = $template->parms; if (empty($parms['tagparms']['class']) || !Core_Strings::contains('mce', $parms['tagparms']['class'])) { $template->update_parm('tagparms', array('class' => (isset($parms['tagparms']['class']) ? $parms['tagparms']['class'] : '') . ' ' . $class_name)); } $template->update_parm('tagparms', array('id' => $name . '-' . $this->url_class())); }
/** * Возвращает объект адаптера соответствующего DSN * * @params DB_DSN $dsn объект строки DSN * * @throws DB_Exception Если отсутствует параметр type в строке DSN * * @return object */ public static function instantiate(DB_DSN $dsn) { $adapters = self::option('adapters'); if (isset($adapters[$dsn->type])) { $module = $adapters[$dsn->type]; $module = Core_Strings::contains('.', $module) ? $module : 'DB.Adapter.' . $module; Core::load($module); return Core::make($module . '.Connection', $dsn); } else { throw new DB_Exception("Missing adapter for type {$module}"); } }
/** */ public function generate() { foreach (new Dev_Source_LibraryDirIterator($this->path_to_library) as $module_name => $module) { if (Core_Strings::contains($module_name, '.')) { $file_place = $this->path_to_html . "/" . Core_Regexps::replace('{/\\w+$}', '', Core_Strings::replace($module_name, '.', '/')); if (!IO_FS::exists($file_place)) { IO_FS::mkdir($file_place, 0775, true); } } try { $module_generator = new Dev_Source_Doc_ModuleGenerator($module, $this->path_to_html . "/" . Core_Strings::replace($module_name, '.', '/')); $module_generator->write(); $module_generator->write_diagram(); $this->add_to_toc($module_generator); } catch (Dev_Source_InvalidSourceException $e) { } } $this->write_css(); $this->write_toc(); $this->write_index(); }
/** * @param $body * * @return string */ protected function format_body($body) { switch (true) { case is_array($body) && Core_Strings::contains($body[0], '%'): return vsprintf($body[0], array_slice($body, 1)); case is_object($body) && !method_exists($body, '__toString'): case is_array($body): return var_export($body, true); default: return (string) $body; } }
/** * Обработка вызовов методов установки значений опций * * @param string $method * @param array $args * * @return mixed */ public function __call($method, $args) { switch ($method) { case 'classname': return $this->option($method, (string) $args[0]); case 'column': $this->array_option('columns', (string) $args[0]); if (isset($args[1])) { $this->array_option('defaults', $args[1], $args[0]); } return $this; case 'validator': return $this->use_validator($args[0]); case 'table': return $this->option($method, explode(' ', (string) $args[0])); case 'columns': case 'exclude': case 'only': case 'key': foreach ((array) $args[0] as $v) { $this->array_option($method, (string) $v); } return $this; case 'defaults': foreach ((array) $args[0] as $k => $v) { $this->array_option($method, $v, $k); } return $this; case 'lookup_by': case 'search_by': return $this->option($method, (string) $args[0]); case 'explicit_key': return $this->option($method, (bool) $args[0]); case 'calculate': foreach ((array) $args[0] as $k => $v) { $alias = (string) $k; if (is_int($k)) { switch (true) { case Core_Strings::contains($v, ' '): $v = preg_replace('!\\sas\\s!i', ' ', $v); $parts = explode(' ', $v); $alias = array_pop($parts); $v = implode(' ', $parts) . ' as '; break; case preg_match('{[0-9a-zA-Z_]+\\.([0-9a-zA-Z_]+)}', $v, $m): $alias = $m[1]; break; default: $alias = $v; } } $this->array_option($method, $v, $alias, false); } return $this; case 'having': case 'where': return $this->array_option($method, (string) $args[0]); case 'order_by': case 'group_by': return $this->option($method, (string) $args[0]); case 'join': return $this->array_option('join', array((string) $args[0], (string) $args[1], (array) $args[2])); case 'range': return $this->option('range', array((int) $args[0], isset($args[1]) ? (int) $args[1] : 0)); case 'index': return $this->option('index', (string) $args[0]); case 'union': return $this->array_option($method, $args[0], $args[1]); default: return $this->option($method, $args[0]); } }
public function get($url = '', $parms = null) { $encoded = $this->encode_parameters($parms); return $this->url($url . ($encoded ? (Core_Strings::contains($url, '?') ? '&' : '?') . $encoded : ''))->exec_with_options(array(CURLOPT_HTTPGET => 1)); }
public function action_url($action, $p = false, $args = false, $extra = false) { $res = parent::action_url($action, $p, $args, $extra); if ($this->default_action($action, $args) !== 'tree') { return $res; } $res = preg_replace('!/list!', '', $res); if (preg_match('!/page-(\\d+)!', $res, $m)) { $page = $m[1]; $res = str_replace('/page-' . $page, '', $res); $res .= (Core_Strings::contains($res, '?') ? '&' : '?') . "page={$page}"; } return $res; }
/** * @param Dev_Source_Module $module * @param Dev_Source_Check_Result $result */ public function run(Dev_Source_Module $module, Dev_Source_Check_Result $result) { foreach ($module->file as $line_number => $line) { if (Core_Strings::contains($line, "\t")) { $result->add_error($this, $module, "Tab on line {$line_number}"); } } $module->file->close(); }
public function test_contains() { $this->assertTrue(Core_Strings::contains('Start', 'ar')); $this->assertFalse(Core_Strings::contains('Start', 'www')); }
/** * Преобразует дату в строку заданного формата * * @params string $format Строка формата по умолчанию Time::FMT_DEFAULT * @params null|boolean $clib Флаг, показывающий как форматировать строку * * @return string */ public function format($format = Time::FMT_DEFAULT, $clib = null) { if (is_null($clib) && Core_Strings::contains($format, '%')) { $clib = true; } if ($clib) { return $this->format_clib($format); } else { return parent::format($format); } }
/** * Возвращает путь к файлу, в котором храниться значение с ключом $key * * @param string $key * * @return string */ public function path($key) { $key = str_replace(DIRECTORY_SEPARATOR, '_', $key); $key = str_replace('.', '_', $key); if (Core_Strings::contains($key, ':') && preg_match('{(.*)\\:([^:]+)$}', $key, $m)) { $dir = $this->path . DIRECTORY_SEPARATOR . trim(str_replace(':', DIRECTORY_SEPARATOR, $m[1]), DIRECTORY_SEPARATOR . ' '); if (!IO_FS::exists($dir)) { IO_FS::mkdir($dir, null, true); } $key = $m[2]; } else { $dir = $this->path; } return $dir . DIRECTORY_SEPARATOR . $key; }
/** * @param WebKit_HTTP_Request $request * * @return WebKit_Controller_Route */ public function route($request) { if ($this->is_not_match_for($request->urn)) { return null; } if ($route = $this->route_index($request)) { return $route; } $uri = Core_Regexps::replace('{^/|/$}', '', $this->clean_url($request->urn)); $uri = Core_Strings::replace($uri, '.' . ($format = $this->guess_format($uri)), ''); $current = false; $action = false; $nested_ids = array(); $parts = Core_Strings::split_by('/', $uri); $last_idx = count($parts) - 1; foreach ($parts as $idx => $part) { if (!$current) { if (isset($this->resources[$part]) && !isset($this->resources[$part]['parent'])) { $current = $part; } else { return null; } } else { if (isset($nested_ids["{$this->resources[$current]['single']}_id"])) { if (isset($this->resources[$current]['instance']) && isset($this->resources[$current]['instance'][$part]) && Core_Strings::contains($this->resources[$current]['instance'][$part], $request->method) && $idx == $last_idx) { $action = $part; break; } if (isset($this->resources[$part]) && isset($this->resources[$current]['nested']) && Core_Arrays::contains($this->resources[$current]['nested'], $part)) { $current = $part; } else { return null; } } else { if (isset($this->resources[$current]['collection']) && isset($this->resources[$current]['collection'][$part]) && Core_Strings::contains($this->resources[$current]['collection'][$part], $request->method) && $idx == $last_idx) { $action = $part; } else { $nested_ids["{$this->resources[$current]['single']}_id"] = $part; } } } } $id = isset($nested_ids["{$this->resources[$current]['single']}_id"]) ? $nested_ids["{$this->resources[$current]['single']}_id"] : false; if (!$action) { switch ($request->method_name) { case 'get': $action = $id === false ? 'index' : 'view'; break; case 'post': $action = 'create'; break; case 'put': $action = 'update'; break; case 'delete': $action = 'delete'; break; } } return WebKit_Controller::Route()->merge(array('controller' => isset($this->resources[$current]['controller']) ? $this->resources[$current]['controller'] : Core_Strings::capitalize($current) . 'Controller', 'action' => $action, 'format' => $format))->merge($id ? array($id) : array())->merge($nested_ids)->merge($this->defaults)->add_controller_prefix($this->options['prefix']); }
/** * Создает блок и заполняет его контентом * * @param string $name * @param string $content * @param boolean $prepend * * @return Templates_HTML_Template */ public function content($name, $content, $prepend = true) { if ($this->record) { $this->record_call(__FUNCTION__, func_get_args()); } $old_content = isset($this->content[$name]) ? $this->content[$name] : ''; $root = $this->root; $spawn = $this->spawn_from; if ($this->no_duplicates[$name] && ($spawn && Core_Strings::contains($spawn[$name], $content)) || (Core_Strings::contains($this[$name], $content) || Core_Strings::contains($root[$name], $content))) { return $this; } if ($prepend) { $this->content[$name] = $content . $old_content; } else { $this->content[$name] = $old_content . $content; } return $this; }
public function map_type($column) { if (!empty($column['mysql_type'])) { return $column['mysql_type']; } $key = Core_Strings::contains(':', $column['type']) ? $column['type'] : Core_Strings::downcase($column['type']) . ':' . (isset($column['size']) ? $column['size'] : 'normal'); return self::$type_map[$key]; }
static function column_schema($db_name, $src, &$schema, $table_name = null, $field_name = null) { $type = 'text'; $length = false; $size = false; $index = false; $index_name = false; $index_type = false; $index_columns = array(); $precision = false; $scale = false; $default = ''; $not_default = false; $nn = true; $src = trim(strtolower($src)); $parms = array(); $unsetparms = array(); // index if ($m = Core_Regexps::match_with_results('{(.+)(\\s+index(_[a-z_\\-0-9]+)?(\\(.+\\))?)}i', $src)) { $index = true; $index_name = trim($m[3], ' _'); if ($index_name === 'primary') { $index_type = 'primary key'; $index_name = false; } if (Core_Strings::starts_with($index_name, 'unique')) { $index_type = 'unique'; $index_name = trim(str_replace('unique', '', $index_name), '_ '); } $index_data = trim($m[4], '() '); if (!empty($index_data)) { foreach (explode(',', $index_data) as $ipart) { $ipart = trim($ipart); $int_val = filter_var($ipart, FILTER_VALIDATE_INT); if (Core_Strings::contains($ipart, ':')) { $index_columns[] = explode(':', $ipart); } else { if ($int_val !== false) { $index_columns[] = array($db_name, $ipart); } else { $index_columns[] = $ipart; } } } } $src = trim(str_replace($m[2], '', $src)); } // type $type = $src; if ($m = Core_Regexps::match_with_results('{^([a-z]+)(\\((\\d+)\\))?}i', $src)) { $type = $m[1]; $length = trim($m[3]); } // null if ($m = Core_Regexps::match_with_results('{\\s+null}', $src)) { $nn = false; } // parms if ($m = Core_Regexps::match_with_results('{/(.*)$}', $src)) { $parms_str = trim($m[1]); foreach (explode(',', $parms_str) as $parm) { list($k, $v) = explode('=', $parm); $v = trim($v); $k = trim($k); $int_val = filter_var($v, FILTER_VALIDATE_INT); if ($int_val !== false) { $v = $int_val; } else { $bool_val = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if (!is_null($bool_val)) { $v = $bool_val; } } if ($v === 'null') { $v = null; } if ($v !== 'none') { $parms[$k] = $v; } else { $unsetparms[$k] = $v; } } } // process parms if ($type == 'bigtext' || $type == 'longtext') { $type = 'text'; $size = 'big'; } if ($type == 'tinyint') { $type = 'int'; $size = 'tiny'; } if ($type == 'price') { $type = 'numeric'; $precision = 10; $scale = 2; $default = '0.00'; } if ($type == 'datetime') { $default = '0000-00-00 00:00:00'; } if ($type == 'date') { $default = '0000-00-00'; } if ($type == 'int') { $default = 0; } if ($type == 'serial') { $default = null; } if ($type == 'float' || $type == 'double') { $type = 'float'; $default = 0.0; } if ('timestamp' == $type) { $not_default = true; } // compose all in one $rc = array('name' => $db_name, 'type' => $type, 'not null' => $nn, 'index' => $index); if (!$not_default) { $rc['default'] = $default; } if ($length) { $rc['length'] = $length; } if ($size) { $rc['size'] = $size; } if ($precision) { $rc['precision'] = $precision; } if ($scale) { $rc['scale'] = $scale; } if ($idx = $rc['index']) { if (!$index_name) { $index_name = "idx_" . ($table_name ? str_replace('_', '', $table_name) : '') . "_{$db_name}"; } if (empty($index_columns)) { $index_columns = array($db_name); } $idx = array('name' => $index_name, 'columns' => $index_columns); if ($index_type) { $idx['type'] = $index_type; } $schema['indexes'][] = $idx; } unset($rc['index']); foreach ($unsetparms as $k => $v) { unset($rc[$k]); } $rc = array_replace_recursive($rc, $parms); if ($type == 'serial') { $schema['indexes']['PRIMARY'] = array('name' => 'PRIMARY', 'type' => 'primary key', 'columns' => array($db_name)); } $rc['__from_field'] = $field_name; if ($type !== 'empty') { $schema['columns'][$db_name] = $rc; } return $rc; }
/** * @param DOM_Element $el */ protected function parse_type($el) { foreach ($el->getElementsByTagName('Type') as $t) { $value = $t->textContent; switch ($value) { case 'http://specs.openid.net/auth/2.0/signon': case 'http://specs.openid.net/auth/2.0/': $this->client->version = OpenId::Version2(); break; case 'http://specs.openid.net/auth/2.0/server': $this->client->version = OpenId::Version2(); $this->client->identifier_select = true; break; case 'http://openid.net/signon/1.1': case 'http://openid.net/signon/1.0': $this->client->version = OpenId::Version1(); break; case 'http://openid.net/srv/ax/1.0': case 'http://openid.net/srv/ax/1.1': if (!Core_Strings::contains($this->client->server, 'myopenid.com')) { $this->client->option('ax', true); } break; case 'http://openid.net/sreg/1.0': case 'http://openid.net/extensions/sreg/1.1': $this->client->option('sreg', true); break; } } }
public function map_type($column, $for_inspect = false) { if (!empty($column['pgsql_type'])) { return $column['pgsq_type']; } if ($for_inspect && $this->is_serial_column($column)) { if ($column['type'] == 'bigserial') { $column['size'] = 'big'; } $column['type'] = 'int'; } if (isset($column['precision'])) { return 'NUMERIC'; } $key = Core_Strings::contains(':', $column['type']) ? $column['type'] : Core_Strings::downcase($column['type']) . ':' . (isset($column['size']) ? $column['size'] : 'normal'); $type = self::$type_map[$key]; return $type; }