Example #1
0
 /**
  * @param WS_Environment $env
  *
  * @return mixed
  */
 public function run(WS_Environment $env)
 {
     $env->auth = Core::object(array('user' => null, 'module' => $this->auth_module));
     $this->set_user($env);
     $uri = $env->request->url;
     try {
         $response = $this->application->run($env);
     } catch (WS_Auth_UnauthenticatedException $e) {
         $response = Net_HTTP::Response(Net_HTTP::UNAUTHORIZED);
     } catch (WS_Auth_ForbiddenException $e) {
         $response = Net_HTTP::Response(Net_HTTP::FORBIDDEN);
     }
     if ($response->status->code == Net_HTTP::UNAUTHORIZED) {
         return Net_HTTP::redirect_to(Core_Strings::replace($this->auth_url, '{url}', $uri));
     } else {
         return $response;
     }
 }
Example #2
0
File: SQL.php Project: techart/tao
 public function __call($method, $args)
 {
     switch ($method) {
         case 'columns':
             $this->set_columns($args);
             break;
         case 'offset':
             $this->{$method} = $args[0];
             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;
     }
     return $this;
 }
Example #3
0
 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;
 }
Example #4
0
 /**
  * @param string $path
  *
  * @return string
  */
 protected function module_name($path)
 {
     return Core_Strings::replace(Core_Strings::replace(Core_Strings::replace($path, $this->path . "/", ''), '.php', ''), '/', '.');
 }
Example #5
0
File: Doc.php Project: techart/tao
 /**
  * @return mixed
  */
 protected function get_classes()
 {
     if ($this->classes != null) {
         return $this->classes;
     }
     $this->classes = array();
     foreach ($this->module->xml->getElementsByTagName('class') as $k => $v) {
         $name = $v->getAttribute('name');
         $this->classes[$name] = $this->ref . '#c-' . Core_Strings::replace($name, '.', '-');
     }
     return $this->classes;
 }
Example #6
0
 /**
  * @param Dev_Source_Module       $module
  * @param Dev_Source_Check_Result $result
  */
 public function run(Dev_Source_Module $module, Dev_Source_Check_Result $result)
 {
     $comment_name = false;
     $code_name = false;
     foreach ($module->file as $line_number => $line) {
         if (!$comment_name) {
             $m1 = Core_Regexps::match_with_results('{/' . '//\\s+<(class|interface|method).*name="([^"\']+)"}', $line);
             if ($m1) {
                 $comment_name = $m1[2];
                 $code_name = false;
             }
         }
         if (!$code_name && $comment_name) {
             $m2 = Core_Regexps::match_with_results('{^[a-zA-Z\\s]*(class|interface|function)\\s+([a-zA-Z_0-9]+)}', $line);
             if ($m2) {
                 $code_name = $m2[2];
                 if ($m2[1] != 'function') {
                     $code_name = Core_Strings::replace($code_name, '_', '.');
                 }
                 if ($code_name != $comment_name) {
                     $result->add_error($this, $module, "names no equal {$code_name}, {$comment_name} in line {$line_number}");
                 }
                 $comment_name = false;
             }
         }
     }
     $module->file->close();
 }
Example #7
0
 public function test_replace()
 {
     $this->assertEquals(Core_Strings::replace('string', 's', 'S'), 'String');
 }
Example #8
0
 /**
  * @param string $str
  */
 protected function str_to_validurl($str)
 {
     return Core_Strings::replace(Core_Strings::replace($str, ' ', '+'), "\n", '|');
 }
Example #9
0
 /**
  * @param string $method
  *
  * @return string
  */
 protected function field_name_for_method($method)
 {
     return Core_Strings::replace($method, '_', '-');
 }
Example #10
0
File: Rest.php Project: 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);
 }
Example #11
0
File: FS.php Project: techart/tao
 /**
  * Задает шаблон поиска с использованием * и ?
  *
  * @param string $wildcard
  *
  * @return IO_FS_Query
  */
 public function glob($wildcard)
 {
     $this->regexp = '{' . Core_Strings::replace(Core_Strings::replace(Core_Strings::replace($wildcard, '.', '\\.'), '?', '.'), '*', '.*') . '}';
     return $this;
 }
Example #12
0
 /**
  * @param string $string
  *
  * @return array
  */
 protected function parse_credentials($string)
 {
     return ($m = Core_Regexps::match_with_results('{(.+):(.+)}', Core_Strings::decode64(Core_Strings::replace($string, 'Basic ', '')))) ? array($m[1], $m[2]) : array(null, null);
 }
Example #13
0
 /**
  * @param WebKit_Environment   $env
  * @param WebKit_HTTP_Response $response
  *
  * @return Iterator
  */
 public function process_app(WS_Environment $env, $response)
 {
     $uri = $env->request->urn;
     $original_uri = $uri;
     CMS::$original_uri = $uri;
     CMS::$site = CMS::$defsite;
     if (isset(CMS::$sites[CMS::$defsite]['page_main'])) {
         CMS::$page_main = CMS::$sites[CMS::$defsite]['page_main'];
     }
     $_defdata = false;
     if (isset(CMS::$sites[CMS::$defsite])) {
         $_defdata = CMS::$sites[CMS::$defsite];
     }
     if (isset(CMS::$sites)) {
         foreach (CMS::$sites as $site => $data) {
             $_host = isset($data['host']) ? trim($data['host']) : '';
             $_prefix = isset($data['prefix']) ? trim($data['prefix']) : '';
             if ($_host != '' || $_prefix != '') {
                 $_bhost = false;
                 $_bprefix = false;
                 $_uri = $uri;
                 if ($_prefix != '') {
                     if ($m = Core_Regexps::match_with_results('{^/' . $_prefix . '/(.*)$}', $uri)) {
                         $_uri = '/' . $m[1];
                         $_bprefix = true;
                     } else {
                         continue;
                     }
                 }
                 if ($_host != '') {
                     if ($env->request->host == $_host) {
                         $_bhost = true;
                     } else {
                         if ($_host[0] == '{') {
                             if (Core_Regexps::match($_host, $env->request->host)) {
                                 $_bhost = true;
                             } else {
                                 continue;
                             }
                         } else {
                             continue;
                         }
                     }
                 }
                 if ($_bprefix || $_bhost) {
                     CMS::$site = $site;
                     if ($_bprefix) {
                         CMS::$site_prefix = '/' . $_prefix;
                     }
                     $uri = $_uri;
                     $env->request->uri($uri);
                     $_defdata = $data;
                     break;
                 }
             }
         }
     }
     if ($_defdata) {
         if (isset($_defdata['page_main'])) {
             CMS::$page_main = $_defdata['page_main'];
         }
         if (isset($_defdata['page_404'])) {
             CMS::$page_404 = $_defdata['page_404'];
         }
         if (isset($_defdata['layout'])) {
             CMS::$force_layout = $_defdata['layout'];
         }
     }
     if (CMS::$db) {
         $head = CMS::vars()->get('head');
         if (isset($head['meta.title'])) {
             $env->meta->title($head['meta.title']);
         }
         if (isset($head['meta.description'])) {
             $env->meta->description($head['meta.description']);
         }
         if (isset($head['meta.keywords'])) {
             $env->meta->keywords($head['meta.keywords']);
         }
     }
     $curi = $uri;
     if ($m = Core_Regexps::match_with_results('/^([^\\?]+)\\?/', $curi)) {
         $curi = $m[1];
     }
     $use_layout = false;
     // Просмотр всех мапперов зарегистрированных в системе
     foreach (CMS::mappers() as $name => $mapper) {
         // Если срабатывает маппер
         if ($route = $mapper->route($env->request)) {
             CMS::$current_mapper = $mapper;
             CMS::$current_component_name = $name;
             CMS::$current_route = $route;
             try {
                 Core::load('Component.' . $name);
             } catch (Core_ModuleNotFoundException $e) {
                 // hush
             }
             if ($route instanceof Net_HTTP_Response) {
                 return $route;
             }
             // Имя подключаемого модуля
             $controller_module_name = 'Component.' . $name . '.Controller';
             // Имя контроллера по умолчанию
             $controller_name = Core_Strings::replace($controller_module_name, '.', '_');
             // Имя действитя по умолчанию
             $action_name = 'index';
             $do_load_controllers = true;
             if ($route === true) {
                 $route = array('controller' => $controller_name, 'action' => 'index');
             }
             if (is_array($route)) {
                 $_route = WebKit_Controller::Route();
                 $_route->merge($route);
                 $route = $_route;
             }
             if (!isset($route['action'])) {
                 $route['action'] = 'index';
             }
             // Если маппер вернул нестандартное имя контроллера
             if (isset($route['controller'])) {
                 $controller_name = $route['controller'];
             }
             // Если маппер вернул нестандартное имя действия
             if (isset($route['action'])) {
                 $action_name = $route['action'];
             }
             // Если маппер не велел загружать модуль с конроллером (загрузит сам)
             if (isset($route['no_load'])) {
                 $do_load_controllers = false;
             }
             // Загружаем модуль с контроллером
             if ($do_load_controllers) {
                 if (strpos($controller_name, '.') === false && strpos($controller_name, '_') === false) {
                     $controller_name = 'Component.' . $name . '.' . $controller_name;
                 }
                 if (strpos($controller_name, '.') !== false) {
                     $controller_module_name = $controller_name;
                 }
                 Core::autoload($controller_module_name);
             }
             // Получаем экземпляр контроллера
             CMS::$current_controller_name = $controller_name;
             //$controller = Core_Types::reflection_for($controller_name)->newInstance($env, $response);
             $controller = Core::make($controller_name, $env, $response);
             if ($use_layout) {
                 if (!property_exists($controller, 'layout')) {
                     $controller->use_layout($use_layout);
                 } else {
                     if (!$controller->layout) {
                         $controller->use_layout($use_layout);
                     }
                 }
             }
             if (!CMS::$print_version && is_string(CMS::$force_layout)) {
                 $controller->use_layout(CMS::$force_layout);
             }
             CMS::$current_controller = $controller;
             CMS::$current_route = $route;
             // Запускаем контроллер с переданными аргументами
             $rc = $controller->dispatch($route);
             return $rc;
         }
     }
     if (md5($uri) == 'b0b94791138ef54aeb161e403329f827') {
         die('cms');
     }
     return Net_HTTP::not_found();
 }
Example #14
0
File: HTML.php Project: techart/tao
 /**
  * Формирует js confirm вызов
  *
  * @param string $text
  *
  * @return string
  */
 protected function make_confirmation($text)
 {
     return $text ? "confirm('" . Core_Strings::replace($text, "'", "\\'") . "')" : 'true';
 }