当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::fromArray方法代码示例

本文整理汇总了PHP中Collection::fromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::fromArray方法的具体用法?PHP Collection::fromArray怎么用?PHP Collection::fromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection::fromArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handler_ajax_read

 function handler_ajax_read($page, $ids, $state)
 {
     S::assert_xsrf_token();
     $ids = explode(',', $ids);
     try {
         $news = Collection::fromArray($ids, 'News');
         $news->read($state == 1);
     } catch (NotAnIdException $e) {
     }
     return PL_JSON;
 }
开发者ID:netixx,项目名称:frankiz,代码行数:11,代码来源:news.php

示例2: select

 /**
  * Main entry point to select fields
  * @param array|Collection $metas metaobjects to be selected
  * @return Collection upated $metas
  * @throws Exception if an error happened
  */
 public function select($metas)
 {
     if (empty($metas)) {
         return;
     }
     if (is_array($metas)) {
         $metas = Collection::fromArray($metas);
     }
     $tobefetched = $this->fields;
     $handlers = $this->handlers();
     foreach ($handlers as $handler => $fields) {
         $intersect = array_intersect($fields, $tobefetched);
         if (!empty($intersect)) {
             $tobefetched = array_diff($tobefetched, $intersect);
             $handler = 'handler_' . $handler;
             $this->{$handler}($metas, $intersect);
         }
     }
     if (!empty($tobefetched)) {
         throw new Exception("Some fields (" . implode(', ', $tobefetched) . ")" . " couldn't be fetched in class " . $this->className());
     }
     if (is_callable($this->callback)) {
         $cb = $this->callback;
         $cb($metas);
     }
     return $metas;
 }
开发者ID:netixx,项目名称:frankiz,代码行数:33,代码来源:select.php

示例3: get_post_ratings

 /**
  * @param $post_id
  *
  * @return Collection
  */
 public function get_post_ratings($post_id)
 {
     $ratings = (array) get_post_meta($post_id, 'wpkb_ratings', true);
     return Collection::fromArray($ratings);
 }
开发者ID:barrykooij,项目名称:wp-knowledge-base,代码行数:10,代码来源:Rater.php

示例4: __call

 public function __call($method, $arguments)
 {
     $className = $this->className;
     $inferedMethod = 'batch' . ucfirst($method);
     if (method_exists($className, $inferedMethod)) {
         // Call $className->batch$method($this->collected, ...)
         array_unshift($arguments, $this->collected);
         $r = forward_static_call_array(array($className, $inferedMethod), $arguments);
         if (!is_array($r)) {
             return $r;
         }
         $c = new Collection($className);
         if (!empty($r)) {
             $c->add($r);
         }
         return $c;
     }
     // If there is no argument, build an array with values from $collected->$method
     if (empty($arguments)) {
         $values = array_map(function ($mixed) use($method) {
             return $mixed->{$method}();
         }, $this->collected);
         // Try magic things with the schema
         $schema = Schema::get($className);
         if ($schema->isScalar($method)) {
             // Return an array of scalar values
             return $values;
         } elseif ($schema->isObject($method)) {
             // Return a collection
             return Collection::fromArray($values, $schema->objectType($method));
         } elseif ($schema->isFlagset($method)) {
             // Return a merged flagset
             $fs = new PlFlagSet();
             foreach ($values as $flags) {
                 foreach ($flags as $flag) {
                     $fs->addFlag($flag);
                 }
             }
             return $fs;
         } elseif ($schema->isCollection($method)) {
             // Return a merged collection
             $col = new Collection();
             foreach ($values as $c) {
                 $col->merge($c);
             }
             return $col;
         }
         throw new Exception("Unknown automatic field {$method} is schema for {$className}");
     }
     throw new Exception("The method {$className}::{$inferedMethod} doesn't exist");
 }
开发者ID:netixx,项目名称:frankiz,代码行数:51,代码来源:collection.php


注:本文中的Collection::fromArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。