public function use_file(array $file, $type = null) { $path = $file['name']; if (!Templates_HTML::path($type, $path)) { if (!is_null($type)) { $paths = Templates_HTML::option('paths'); $prefix = $paths[$type]; if (!Core_Strings::starts_with($path, $prefix)) { $path = $prefix . '/' . ltrim($path, '/'); } } $component = false; if ($file['component']) { $component = $file['component']; } $component_url = CMS::component_static_path($path, $component); $component_path = str_replace('file://', '', $component_url); if (is_file($component_path)) { $file['name'] = $component_url; } } return parent::use_file($file, $type); }
/** * Преобразует значение полученное из БД в нужный формат, для работы с ним в php * * @param DB_ColumnMeta $metadata * @param $value * * @return mixed */ public function cast_column(DB_ColumnMeta $metadata, $value) { switch (true) { case $metadata->type == 'date': return is_null($value) ? null : Time::parse($value); case $metadata->type == 'timestamp': return is_null($value) ? null : Time::parse($value); case Core_Strings::starts_with($metadata->type, '_'): $arr = array(); foreach (explode(',', Core_Strings::substr($value, 1, strlen($value) - 2)) as $element) { $arr[] = $this->cast_column(new DB_ColumnMeta($metadata->name, Core_Strings::substr($metadata->type, 1), $metadata->length, $metadata->precision), ltrim(rtrim($element, '"'), '"')); } return $arr; case Core_Strings::starts_with($metadata->type, 'int'): return (int) $value; case in_array($metadata->type, array('varchar', 'text')): return (string) $value; case in_array($metadata->type, array('numeric', 'double', 'float')): return (double) $value; default: return $value; } }
public function filter() { foreach (Core::normalize_args(func_get_args()) as $arg) { $this->filters[str_replace('!', '', $arg)] = !Core_Strings::starts_with($arg, '!'); } return $this; }
/** * Подгружает модуль * * @param string $module * * @return Core_ModuleLoader */ public function load($module) { if (!$this->is_loaded($module)) { $real_module_name = Core_Types::real_class_name_for($module); $this->mark_as_loaded($module); $cached_path = Core::cached_modules($module); if ($cached_path) { $loaded = true; //FIXME: if (!Core_Strings::starts_with($cached_path, '.') && !Core_Strings::starts_with($cached_path, '/')) { $cached_path = $this->paths['*'] . '/' . $cached_path; } include_once $cached_path; } else { $loaded = $this->load_module_file($file = $this->file_path_for($module, false), $real_module_name, $module); if ($file && $loaded) { Core::cached_modules($module, $file); } } if (Core::option('spl_autoload') && !$loaded) { return false; } if ($this->is_module($real_module_name)) { if (method_exists($real_module_name, 'initialize')) { call_user_func(array($real_module_name, 'initialize'), isset($this->configs[$module]) ? $this->configs[$module] : array()); } } else { throw new Core_InvalidModuleException($module); } } return Core::option('spl_autoload') ? true : $this; }
/** * Выполняет развертывание имени компонента * * @param string $name * * @return string */ protected function complete_name($name) { if (Core_Strings::ends_with($name, '.')) { $name = $name . WS_DSL::SUFFIX; } if (Core_Strings::starts_with($name, '.')) { $name = WS_DSL::PREFIX . $name; } return $name; }
/** * @param string $name * * @return boolean */ protected function is_http_field($name) { return Core_Strings::starts_with($name, 'http_'); }
/** * Возвращает значение стандартного свойства link * * @abstract * * @param DOMNode $element * * @return string */ public function link_for(DOMNode $element) { $e = $this->xpath("./link[rel='alternate']", $element); if (!$e) { $e = $this->xpath('./link', $element); } return $this->xpath('/*')->getAttribute('xml:base') . (Core_Strings::starts_with($h = $e->getAttribute('href'), '/') ? substr($h, 1) : $h); }
public function test_starts_with() { $this->assertTrue(Core_Strings::starts_with('Start', 'St')); $this->assertTrue(Core_Strings::starts_with('Яблочный сироп', 'Яб')); $this->assertFalse(Core_Strings::starts_with('Start', 'rt')); }
/** * @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; }
/** * Проверяет имеет ли письмо вложения * * @return boolean */ public function is_multipart() { return Core_Strings::starts_with(Core_Strings::downcase($this->head['Content-Type']->value), 'multipart'); }
/** * Выполняет EXPLAIN для анализа запроса * * @uses DB::PLACEHOLDER_REGEXP * * @return array|null */ public function explain() { if (Core_Strings::starts_with(Core_Strings::trim($this->sql), 'SELECT')) { return $this->connection->adapter->explain(Core_Regexps::replace('{' . DB::PLACEHOLDER_REGEXP . '}', '?', $this->sql), $this->binds); } else { return null; } }
protected function create_action($column_defs, $index_defs) { $defs = $column_defs; $sql = array(); foreach ($index_defs as $key => $value) { if (empty($value)) { continue; } if (Core_Strings::starts_with($value, 'QUERY:')) { $sql[] = str_replace('QUERY:', '', $value); } else { $defs[] = $value; } } array_unshift($sql, $this->db_schema->create_table($this->data, $defs)); $rc = true; foreach ($sql as $q) { $this->db->execute($q) && $rc; } return $rc; }
protected function compile($less_fname, $css_fname) { self::load(); $options = self::option('options'); // generate source map if (self::option('sourse_map')) { $map_file = str_replace('styles/', '', $css_fname); $map_file = trim(str_replace('.less.css', '.map', $map_file), '/.'); $map_dir = './styles/less-maps/'; $map_path = "{$map_dir}{$map_file}"; IO_FS::mkdir(dirname($map_path)); $options = array_merge($options, array('sourceMap' => true, 'sourceMapWriteTo' => $map_path, 'sourceMapURL' => trim($map_path, '.'))); // if is out of docroot if ($less_fname[0] == '/' || Core_Strings::starts_with($less_fname, '..') || Core_Strings::starts_with($less_fname, './..')) { $less_fname = "file://{$less_fname}"; $less_fname = '.' . Templates_HTML::extern_filepath($less_fname); } } $options['import_dirs'] = self::option('less_import_dirs'); $dir = dirname($css_fname); $url = 'http://' . WS::env()->request->host . '/'; $args = array(array($less_fname => $url), $options); $css_file_name = Core::invoke(self::option('less_callback'), $args); $cached_file = rtrim($options['cache_dir'], '/') . '/' . $css_file_name; if (is_file($cached_file) && !(WS::env()->request['less_compile'] && self::option('debug'))) { $less_ftime = filemtime($cached_file); $css_ftime = false; if (IO_FS::exists($css_fname)) { $css_ftime = filemtime($css_fname); } if ($css_ftime && $css_ftime >= $less_ftime) { return false; } } $css = file_get_contents($cached_file); IO_FS::File($css_fname)->update($css); }
/** * @param string $method * @param array $args * * @return mixed */ public function __call($method, $args) { if (Core_Strings::ends_with($method, '_url')) { $redirect = false; // TODO: Ugly hack, needs refactoring if (Core_Strings::starts_with($method, 'redirect_to_')) { $redirect = true; $method = Core_Strings::substr($method, 12); } $parms = array(); foreach ($this->completion_parms as $name) { if (isset($this->request[$name])) { $parms[$name] = $this->request[$name]; } } if (count($args) && is_array($args[count($args) - 1])) { if (count($parms)) { $args[count($args) - 1] = Core_Arrays::merge($parms, $args[count($args) - 1]); } } else { if (count($parms)) { $args[] = $parms; } } $url = method_exists($this->urls, $method) ? Core_Types::reflection_for($this->urls)->getMethod($method)->invokeArgs($this->urls, $args) : $this->urls->__call($method, $args); return $redirect ? $this->redirect_to($url) : $url; } else { throw new Core_MissingMethodException($method); } }
/** * @abstract * * @param Net_HTTP_Request $request * @param OpenId_Client $client */ public function retrieve(Net_HTTP_Request $request, OpenId_Client $client) { $values = array(); $sreg_to_ax = array_flip(self::$ax_to_sreg); $schema_to_name = array_flip(array_merge($client->optional, $client->required)); $prefix = 'openid.sreg.'; foreach ($request->parameters as $k => $v) { if (Core_Strings::starts_with($k, $prefix) && ($name = substr($k, strlen($prefix))) && isset($sreg_to_ax[$name])) { $ax = $sreg_to_ax[$name]; $alias = $schema_to_name[$ax]; $values[$alias] = trim($this->is_date($ax, $v) ? Time::DateTime($v) : urldecode($v)); } } return $values; }
protected function tag_attrs_filter($attr) { return Core_Strings::starts_with($attr, 'data-') || Core_Strings::starts_with($attr, 'on') || in_array($attr, $this->tag_attrs()); }
public function render_urls() { $res = array(); $base_path = realpath($_SERVER['DOCUMENT_ROOT']); foreach ($this->filelist($dir) as $file) { $real_path = realpath($file); $name = basename($file); if ($base_path && $real_path && Core_Strings::starts_with($real_path, $base_path)) { $res[$name] = '/' . trim($file, '\\/.'); } else { $res[$name] = '#'; } } return $res; }
protected function inspect_columns($mapper) { $columns = array(); foreach ($mapper->as_array() as $r) { $col = array(); $col['name'] = $r['column_name']; if (!empty($r['check_clause']) && preg_match("!{$col['name']}\\s>=?\\s0!i", $r['check_clause'])) { $col['unsigned'] = true; } if (isset($columns[$col['name']])) { $columns[$col['name']] = array_merge($columns[$col['name']], $col); continue; } $col['type'] = $r['data_type']; list($col['type'], $col['size']) = self::flip_column($col['type']); $col['not null'] = $r['is_nullable'] == 'YES' ? false : true; $default = $r['column_default']; if (!is_null($default)) { if (Core_Strings::starts_with($default, 'nextval')) { $col['type'] = 'serial'; } else { $col['default'] = preg_replace('!::.*!i', '', $default); } } if (!empty($r['character_maximum_length'])) { $col['length'] = $r['character_maximum_length']; } if (Core_Strings::downcase($r['data_type']) == 'numeric') { $col['type'] = 'float'; $col['size'] = 'normal'; $col['precision'] = $r['numeric_precision']; $col['scale'] = $r['numeric_scale']; } $columns[$col['name']] = $col; } return $columns; }