コード例 #1
0
ファイル: Collection.php プロジェクト: brokencube/automatorm
 public function __call($name, $args)
 {
     // If we use Model::COUNT_ONLY on empty container, return 0
     if (count($this->container) == 0 && is_numeric($args[1]) && $args[1] & Model::COUNT_ONLY) {
         return 0;
     }
     // Foreign keys
     if ($this->container[0] instanceof Model and !method_exists($this->container[0], $name) and $this->container[0]->_data->externalKeyExists($name)) {
         if (is_numeric($args[1]) && $args[1] & Model::COUNT_ONLY) {
             return Data::groupJoinCount($this, $name, $args[0]);
         }
         return Data::groupJoin($this, $name, $args[0]);
     }
     // Otherwise...
     $list = [];
     foreach ($this->container as $item) {
         $value = call_user_func_array([$item, $name], $args);
         if ($value instanceof Collection) {
             $list = array_merge($list, $value->toArray());
         } else {
             $list[] = $value;
         }
     }
     // Return new list or count depending on options passed
     if (is_numeric($args[1]) && $args[1] & Model::COUNT_ONLY) {
         return count($list);
     } else {
         return new static($list);
     }
 }