Пример #1
0
 public function test_ends_with()
 {
     $this->assertTrue(Core_Strings::ends_with('Start', 'rt'));
     $this->assertFalse(Core_Strings::ends_with('Start', 'St'));
     $this->assertTrue(Core_Strings::ends_with('Яблочный сироп', 'оп'));
     $this->assertFalse(Core_Strings::ends_with('Яблочный сироп', 'Яб'));
 }
Пример #2
0
 public function preprocess($file)
 {
     //TODO: to options
     $suffix = '.less';
     if (Core_Strings::ends_with($file, $suffix)) {
         $file = Templates_HTML::css_path($file, false);
         $css_file = md5($file) . '.css';
         $css_file = Templates_HTML_Preprocess::option('less_output_dir') . '/' . $css_file;
         //TODO: errors
         $this->compile('./' . $file, $css_file);
         return '/' . ltrim($css_file, '\\/.');
     }
     return $file;
 }
Пример #3
0
 public function preprocess($file, $data)
 {
     //TODO: to options
     $suffix = '.less';
     $content = null;
     if (Core_Strings::ends_with($file, $suffix)) {
         $file = Templates_HTML::css_path($file, false);
         $file_name = ltrim($file, '/\\.');
         $less_file = './' . ltrim($file, '/');
         $css_file = str_replace('css.less', 'less.css', $file_name);
         $css_file = str_replace('styles/', '', $css_file);
         $css_file = './' . self::option('less_output_dir') . '/' . $css_file;
         $css_file = str_replace('//', '/', $css_file);
         $dir = dirname($css_file);
         if (!IO_FS::exists($dir)) {
             IO_FS::mkdir($dir);
         }
         $this->compile($less_file, $css_file);
         return array('/' . ltrim($css_file, '\\/.'), $content);
     }
     return array($file, $content);
 }
Пример #4
0
 /**
  * @param string $ax_name
  * @param mixed  $value
  */
 protected function is_date($ax_name, $value)
 {
     return Core_Strings::ends_with($ax_name, 'Date') || Core_Strings::ends_with($ax_name, 'date');
 }
Пример #5
0
 public function __call($method, $args)
 {
     if (Core_Strings::ends_with($method, '_cache')) {
         $method = str_replace('_cache', '', $method);
         //TODO: to Core::call
         if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
             $call = array('parent', '__call');
         } else {
             $call = array($this, 'parent::__call');
         }
         return $this->cached_call($this->helper_cache_key($method, $args), $call, array($method, $args));
     }
     return parent::__call($method, $args);
 }
Пример #6
0
 /**
  * Выполняет развертывание имени компонента
  *
  * @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;
 }
Пример #7
0
 public function preprocess($file, $data)
 {
     $suffix = '.scss';
     $content = null;
     if (Core_Strings::ends_with($file, $suffix)) {
         $this->load();
         if (!$this->server) {
             return array($file, $content);
         }
         // TODO: move to function
         $file = Templates_HTML::css_path($file, false);
         $file_name = ltrim($file, '/\\.');
         $scss_file = './' . ltrim($file, '/');
         $css_file = str_replace('.scss', '.css', $file_name);
         $css_file = str_replace('styles/', '', $css_file);
         $css_file = './' . self::option('scss_output_dir') . '/' . $css_file;
         $css_file = str_replace('//', '/', $css_file);
         $dir = dirname($css_file);
         if (!IO_FS::exists($dir)) {
             IO_FS::mkdir($dir);
         }
         if ($this->server->needsCompile($scss_file, $css_file, $etag = '')) {
             $this->server->compile($scss_file, $css_file);
         }
         return array('/' . ltrim($css_file, '\\/.'), $content);
     }
     return array($file, $content);
 }
Пример #8
0
 /**
  * Возвращает значение произвольного свойства с преобразованием типов и имен
  *
  * @param string     $query
  * @param DOMElement $element
  * @param int        $index
  *
  * @return mixed
  */
 public function get($query, DOMElement $element, $index = 0)
 {
     if ($this->has_child_nodes_for($e = $this->xpath($query, $element, $index))) {
         return $e;
     }
     return ($r = $this->node_value_for($e)) && Core_Strings::ends_with($query, 'ed') ? Time::DateTime($r) : $r;
 }
Пример #9
0
 /**
  * Возвращает значение поля
  *
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     if ($wants_date = $property == 'date' || Core_Strings::ends_with($property, '_date')) {
         $property = preg_replace('/_date$/', '', $property);
     }
     return isset($this->fields[$idx = $this->canonicalize($property)]) ? $wants_date ? Time::parse($this->fields[$idx], Time::FMT_RFC1123) : $this->fields[$idx] : null;
 }
Пример #10
0
 /**
  * @param  $property
  *
  * @return boolean
  */
 protected function is_date($property)
 {
     return Core_Strings::ends_with($property, '_at');
 }
Пример #11
0
Файл: FS.php Проект: techart/tao
 /**
  * Корректирует новый путь к файлу для операций копирования и перемещения
  *
  * @return string
  */
 private function fix_destination($destination)
 {
     return is_dir($destination) ? (Core_Strings::ends_with($destination, '/') ? $destination : $destination . '/') . @basename($this->path) : $destination;
 }
Пример #12
0
 /**
  * @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);
     }
 }
Пример #13
0
 /**
  * Возвращает путь до partial шаблона
  *
  * @param string $name
  *
  * @return string
  */
 protected function get_partial_path($name, $paths = array())
 {
     if (Core_Strings::starts_with($name, '!')) {
         $trace = debug_backtrace();
         foreach ($trace as $k => $t) {
             if (Core_Strings::ends_with($t['file'], $this->extension)) {
                 break;
             }
         }
         return Templates::add_extension(dirname($trace[$k]['file']) . '/' . substr($name, 1), $this->extension);
     }
     $file = Templates::add_extension($name, $this->extension);
     if (Templates::is_absolute_path($name)) {
         return $file;
     }
     $paths = array_merge($paths, $this->partial_paths(), Templates::option('templates_root'));
     foreach ($paths as $path) {
         $result = rtrim($path, '/') . '/' . $file;
         if (is_file($result)) {
             return $result;
         }
     }
     return $result;
 }