示例#1
0
文件: SQL.php 项目: 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;
 }
示例#2
0
文件: Rest.php 项目: 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);
 }
示例#3
0
 public function test_shift()
 {
     $arr = array('key1' => 'value1', 'key2' => 'value2');
     $this->assertEquals(Core_Arrays::shift($arr), 'value1');
     $this->assertEquals($arr, array('key2' => 'value2'));
 }
示例#4
0
 /**
  * @return WebKit_Controller_AbstractController
  */
 public function after_filter()
 {
     $args = func_get_args();
     return $this->register_filter('after', Core_Arrays::shift($args), $args);
 }