Ejemplo n.º 1
0
 public function test_split_by()
 {
     $this->assertEquals(Core_Strings::split_by(',', "piece1,piece2,piece3,piece4"), array("piece1", "piece2", "piece3", "piece4"));
     //var_dump(Core_Strings::split_by('', "piece1,piece2,piece3,piece4"));
     $this->assertEquals(Core_Strings::split_by('', "piece1,piece2,piece3,piece4"), array("piece1,piece2,piece3,piece4"));
     $this->assertEquals(Core_Strings::split_by(' ', "piece1,piece2,piece3,piece4"), array("piece1,piece2,piece3,piece4"));
     $this->assertEquals(Core_Strings::split_by(',', ""), array());
 }
Ejemplo n.º 2
0
Archivo: Dump.php Proyecto: techart/tao
 /**
  * Запускает приложение
  *
  * @param array $argv
  *
  * @return int
  */
 public function run(array $argv)
 {
     $cache = Cache::connect($this->config->dsn);
     if ($this->config->modules != null) {
         foreach (Core_Strings::split_by(',', $this->config->modules) as $v) {
             Core::load($v);
         }
     }
     foreach ($argv as $v) {
         IO::stdout()->write_line($v)->write_line(var_export($cache[$v], true));
     }
     return 0;
 }
Ejemplo n.º 3
0
Archivo: Core.php Proyecto: techart/tao
 /**
  * Выполняет разбор переменной окружения TAO_PATH
  *
  * @return array
  */
 private static function parse_environment_paths()
 {
     $result = array();
     if (($path_var = getenv(self::PATH_VARIABLE)) !== false) {
         foreach (Core_Strings::split_by(';', $path_var) as $rule) {
             if ($m = Core_Regexps::match_with_results('{^([-A-Za-z0-9*][A-Za-z0-9_.]*):(.+)$}', $rule)) {
                 $result[$m[1]] = $m[2];
             }
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
Archivo: DSL.php Proyecto: techart/tao
 /**
  * @param string $name
  * @param int    $http_mask
  * @param string $path
  * @param string $formats
  *
  * @return WS_REST_DSL_Resource
  */
 public function method($name, $http_mask = Net_HTTP::ANY, $path = null, $formats = null, $defaults = array())
 {
     $formats = $formats === null ? isset($this->scope->formats) ? $this->scope->formats : array() : $formats;
     $path = $path === null ? isset($this->scope->path) ? $this->scope->path : 'index' : $path;
     $name = $name ? $name : $path;
     $http_mask = $http_mask === null ? isset($this->scope->http_methods) ? $this->scope->http_methods : Net_HTTP::ANY : $http_mask;
     $this->object->method(Core::with(new WS_Services_REST_Method($name))->path($path)->http($http_mask)->defaults($defaults)->produces(is_array($formats) ? $formats : Core_Strings::split_by(',', (string) $formats)));
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Приводит имя к виду соответствующему почтовому стандарту
  *
  * @param string $name
  *
  * @return string
  */
 protected function canonicalize($name)
 {
     $parts = Core_Arrays::map('return strtolower($x);', Core_Strings::split_by('-', trim($name)));
     foreach ($parts as &$part) {
         $part = isset(self::$acronyms[$part]) ? self::$acronyms[$part] : (preg_match('{[aeiouyAEIOUY]}', $part) ? ucfirst($part) : strtoupper($part));
     }
     return Core_Arrays::join_with('-', $parts);
 }
Ejemplo n.º 6
0
Archivo: Rest.php Proyecto: techart/tao
 /**
  * @param string $name
  * @param array  $args
  *
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (!Core_Regexps::match('{_url$}', $name)) {
         throw new Core_MissingMethodException($name);
     }
     $name = Core_Strings::replace($name, 'single_', 'single-');
     $url = '';
     $args = Core_Arrays::reverse($args);
     $parms = Core_Types::is_array($args[0]) ? Core_Arrays::shift($args) : array();
     $parts = Core_Arrays::reverse(Core_Strings::split_by('_', Core_Regexps::replace('{_url$}', '', $name)));
     $last_idx = count($parts) - 1;
     $target = false;
     foreach ($parts as $idx => $part) {
         $part = Core_Strings::replace($part, '-', '_');
         if ($target) {
             if (isset($this->single_names[$part])) {
                 $url = '/' . $this->single_names[$part] . '/' . (Core_Types::is_object($arg = Core_Arrays::shift($args)) ? $arg->id : (string) $arg) . $url;
             } elseif ($idx == $last_idx && (isset($this->resources[$target]) && isset($this->resources[$target]['collection']) && isset($this->resources[$target]['collection'][$part])) || isset($this->single_names[$target]) && isset($this->resources[$this->single_names[$target]]['instance']) && isset($this->resources[$this->single_names[$target]]['instance'][$part])) {
                 $url .= "/{$part}";
             } else {
                 throw new Core_MissingMethodException($name);
             }
         } else {
             if (isset($this->resources[$part])) {
                 $url = "/{$part}{$url}";
                 $target = $part;
             } elseif (isset($this->single_names[$part])) {
                 $id = Core_Arrays::shift($args);
                 $url = '/' . $this->single_names[$part] . '/' . (Core_Types::is_object($id) ? $id->id : (string) $id) . $url;
                 $target = $part;
             } else {
                 throw new Core_MissingMethodException($name);
             }
         }
     }
     return $this->add_keyword_parameters($this->add_path($url) . (isset($args[0]) ? '.' . $args[0] : ".{$this->default_format}"), $parms);
 }
Ejemplo n.º 7
0
 /**
  * @return string
  */
 protected function make_name_and_views_path()
 {
     $parts = Core_Strings::split_by('_', Core_Strings::downcase(Core_Regexps::replace('{Controller$}', '', Core_Types::class_name_for($this))));
     array_shift($parts);
     $this->name = Core_Arrays::join_with('.', $parts);
     //$this->views_path = Core_Arrays::join_with('/', $parts);
 }
Ejemplo n.º 8
0
Archivo: HTML.php Proyecto: techart/tao
 protected function http_to_string($name, $content)
 {
     return sprintf("<meta http-equiv=\"%s\" content=\"%s\" />\n", htmlspecialchars(Core_Arrays::join_with('-', Core_Arrays::map('return ucfirst(strtolower($x));', Core_Strings::split_by('_', $name)))), htmlspecialchars($content));
 }