Example #1
0
 public function __call($name, $arguments)
 {
     global $map;
     $path = false;
     $url = true;
     if (preg_match('/^(?<path>\\w+)_url$/', $name, $matches)) {
         $path = $map->path($matches['path']);
     } else {
         if (preg_match('/^(?<path>\\w+)_path$/', $name, $matches)) {
             $path = $map->path($matches['path']);
             $url = false;
         }
     }
     if ($path === false) {
         $trace = debug_backtrace();
         trigger_error('Undefined method via __call(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
         return null;
     }
     $get_arguments = array_value($arguments, 1, array());
     $arguments = array_value($arguments, 0, array());
     if (!is_array($arguments)) {
         $arguments = array('\\w+' => $arguments);
     }
     $params = array_merge(array_merge(array('module' => coalesce($map->module_for_controller($this->controller), $this->module), 'controller' => $this->controller, 'action' => $this->action, 'format' => $this->render_format), array_value($path, 1, array())), $arguments);
     $path = $path[0];
     foreach ($params as $key => $value) {
         $path = preg_replace("/\\(\\?<{$key}>[^\\)]*\\)/", $value, $path);
     }
     while (preg_match('/\\(\\?<(?<key>\\w+)>[^\\)]*\\)/', $path, $matches)) {
         $path = preg_replace("/\\(\\?<{$matches['key']}>[^\\)]*\\)/", $this->params[$matches['key']], $path);
     }
     if ($url) {
         $path = url($path);
         if ($this->i18n != 'default') {
             $get_arguments = array_merge(array('locale' => $this->i18n), $get_arguments);
         }
         if (count($get_arguments)) {
             $path .= url_query_string($get_arguments);
         }
     }
     return $path;
 }
Example #2
0
function url($url, $params = array())
{
    return REQUEST_BASE . $url . url_query_string($params);
}