本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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");
}