Update Collection classes to be based on Doctrine Collections

This commit is contained in:
Matias Griese
2017-02-15 11:44:14 +02:00
parent 76c870ce04
commit eae222f264
16 changed files with 239 additions and 366 deletions

View File

@@ -16,6 +16,7 @@
"symfony/var-dumper": "~2.8",
"symfony/polyfill-iconv": "~1.0",
"doctrine/cache": "~1.5",
"doctrine/collections": "^1.4",
"filp/whoops": "~2.0",
"matthiasmullie/minify": "^1.3",
"monolog/monolog": "~1.0",

182
composer.lock generated
View File

@@ -4,7 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "4e5b9333d3ac2de823c68c9c8e0f2017",
"hash": "d71bd78770ae90cfdd59960d2829cb75",
"content-hash": "7f68c667c95b191cfd0b6eeef614dc3d",
"packages": [
{
"name": "antoligy/dom-string-iterators",
@@ -48,7 +49,7 @@
}
],
"description": "Composer package for DOMWordsIterator and DOMLettersIterator",
"time": "2015-11-04T17:33:14+00:00"
"time": "2015-11-04 17:33:14"
},
{
"name": "doctrine/cache",
@@ -118,7 +119,74 @@
"cache",
"caching"
],
"time": "2016-10-29T11:16:17+00:00"
"time": "2016-10-29 11:16:17"
},
{
"name": "doctrine/collections",
"version": "v1.4.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/collections.git",
"reference": "1a4fb7e902202c33cce8c55989b945612943c2ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/collections/zipball/1a4fb7e902202c33cce8c55989b945612943c2ba",
"reference": "1a4fb7e902202c33cce8c55989b945612943c2ba",
"shasum": ""
},
"require": {
"php": "^5.6 || ^7.0"
},
"require-dev": {
"doctrine/coding-standard": "~0.1@dev",
"phpunit/phpunit": "^5.7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
},
"autoload": {
"psr-0": {
"Doctrine\\Common\\Collections\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "Collections Abstraction library",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"array",
"collections",
"iterator"
],
"time": "2017-01-03 10:49:41"
},
{
"name": "donatj/phpuseragentparser",
@@ -169,7 +237,7 @@
"user agent",
"useragent"
],
"time": "2017-01-23T19:32:09+00:00"
"time": "2017-01-23 19:32:09"
},
{
"name": "erusev/parsedown",
@@ -255,7 +323,7 @@
"parsedown",
"parser"
],
"time": "2015-11-01T10:19:22+00:00"
"time": "2015-11-01 10:19:22"
},
{
"name": "filp/whoops",
@@ -315,7 +383,7 @@
"whoops",
"zf2"
],
"time": "2016-12-26T16:13:31+00:00"
"time": "2016-12-26 16:13:31"
},
{
"name": "gregwar/cache",
@@ -358,7 +426,7 @@
"file-system",
"system"
],
"time": "2016-09-23T08:16:04+00:00"
"time": "2016-09-23 08:16:04"
},
{
"name": "gregwar/image",
@@ -461,7 +529,7 @@
"php",
"terminal"
],
"time": "2016-04-04T20:24:59+00:00"
"time": "2016-04-04 20:24:59"
},
{
"name": "matthiasmullie/minify",
@@ -518,7 +586,7 @@
"minifier",
"minify"
],
"time": "2017-01-26T15:48:07+00:00"
"time": "2017-01-26 15:48:07"
},
{
"name": "matthiasmullie/path-converter",
@@ -567,7 +635,7 @@
"paths",
"relative"
],
"time": "2017-01-26T08:54:49+00:00"
"time": "2017-01-26 08:54:49"
},
{
"name": "maximebf/debugbar",
@@ -628,7 +696,7 @@
"debug",
"debugbar"
],
"time": "2017-01-05T08:46:19+00:00"
"time": "2017-01-05 08:46:19"
},
{
"name": "monolog/monolog",
@@ -706,7 +774,7 @@
"logging",
"psr-3"
],
"time": "2016-11-26T00:15:39+00:00"
"time": "2016-11-26 00:15:39"
},
{
"name": "pimple/pimple",
@@ -752,7 +820,7 @@
"container",
"dependency injection"
],
"time": "2015-09-11T15:10:35+00:00"
"time": "2015-09-11 15:10:35"
},
{
"name": "psr/log",
@@ -799,7 +867,7 @@
"psr",
"psr-3"
],
"time": "2016-10-10T12:19:37+00:00"
"time": "2016-10-10 12:19:37"
},
{
"name": "rockettheme/toolbox",
@@ -847,7 +915,7 @@
"php",
"rockettheme"
],
"time": "2016-10-06T18:02:45+00:00"
"time": "2016-10-06 18:02:45"
},
{
"name": "seld/cli-prompt",
@@ -895,7 +963,7 @@
"input",
"prompt"
],
"time": "2016-04-18T09:31:41+00:00"
"time": "2016-04-18 09:31:41"
},
{
"name": "symfony/console",
@@ -956,7 +1024,7 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2017-02-06T12:04:06+00:00"
"time": "2017-02-06 12:04:06"
},
{
"name": "symfony/debug",
@@ -1013,7 +1081,7 @@
],
"description": "Symfony Debug Component",
"homepage": "https://symfony.com",
"time": "2016-07-30T07:22:48+00:00"
"time": "2016-07-30 07:22:48"
},
{
"name": "symfony/event-dispatcher",
@@ -1073,7 +1141,7 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2017-01-02T20:30:24+00:00"
"time": "2017-01-02 20:30:24"
},
{
"name": "symfony/polyfill-iconv",
@@ -1132,7 +1200,7 @@
"portable",
"shim"
],
"time": "2016-11-14T01:06:16+00:00"
"time": "2016-11-14 01:06:16"
},
{
"name": "symfony/polyfill-mbstring",
@@ -1191,7 +1259,7 @@
"portable",
"shim"
],
"time": "2016-11-14T01:06:16+00:00"
"time": "2016-11-14 01:06:16"
},
{
"name": "symfony/var-dumper",
@@ -1254,7 +1322,7 @@
"debug",
"dump"
],
"time": "2017-01-24T13:02:12+00:00"
"time": "2017-01-24 13:02:12"
},
{
"name": "symfony/yaml",
@@ -1303,7 +1371,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-01-21T16:40:50+00:00"
"time": "2017-01-21 16:40:50"
},
{
"name": "twig/twig",
@@ -1364,7 +1432,7 @@
"keywords": [
"templating"
],
"time": "2017-01-11T19:36:15+00:00"
"time": "2017-01-11 19:36:15"
}
],
"packages-dev": [
@@ -1425,7 +1493,7 @@
"gherkin",
"parser"
],
"time": "2016-10-30T11:50:56+00:00"
"time": "2016-10-30 11:50:56"
},
{
"name": "codeception/codeception",
@@ -1517,7 +1585,7 @@
"functional testing",
"unit testing"
],
"time": "2017-02-04T02:04:21+00:00"
"time": "2017-02-04 02:04:21"
},
{
"name": "doctrine/instantiator",
@@ -1571,7 +1639,7 @@
"constructor",
"instantiate"
],
"time": "2015-06-14T21:17:01+00:00"
"time": "2015-06-14 21:17:01"
},
{
"name": "facebook/webdriver",
@@ -1620,7 +1688,7 @@
"selenium",
"webdriver"
],
"time": "2017-01-13T15:48:08+00:00"
"time": "2017-01-13 15:48:08"
},
{
"name": "fzaninotto/faker",
@@ -1668,7 +1736,7 @@
"faker",
"fixtures"
],
"time": "2016-04-29T12:21:54+00:00"
"time": "2016-04-29 12:21:54"
},
{
"name": "guzzlehttp/guzzle",
@@ -1730,7 +1798,7 @@
"rest",
"web service"
],
"time": "2016-10-08T15:01:37+00:00"
"time": "2016-10-08 15:01:37"
},
{
"name": "guzzlehttp/promises",
@@ -1781,7 +1849,7 @@
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
"time": "2016-12-20 10:07:11"
},
{
"name": "guzzlehttp/psr7",
@@ -1839,7 +1907,7 @@
"stream",
"uri"
],
"time": "2016-06-24T23:00:38+00:00"
"time": "2016-06-24 23:00:38"
},
{
"name": "phpdocumentor/reflection-common",
@@ -1893,7 +1961,7 @@
"reflection",
"static analysis"
],
"time": "2015-12-27T11:43:31+00:00"
"time": "2015-12-27 11:43:31"
},
{
"name": "phpdocumentor/reflection-docblock",
@@ -1938,7 +2006,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2016-09-30T07:12:33+00:00"
"time": "2016-09-30 07:12:33"
},
{
"name": "phpdocumentor/type-resolver",
@@ -1985,7 +2053,7 @@
"email": "me@mikevanriel.com"
}
],
"time": "2016-11-25T06:54:22+00:00"
"time": "2016-11-25 06:54:22"
},
{
"name": "phpspec/prophecy",
@@ -2048,7 +2116,7 @@
"spy",
"stub"
],
"time": "2016-11-21T14:58:47+00:00"
"time": "2016-11-21 14:58:47"
},
{
"name": "phpunit/php-code-coverage",
@@ -2110,7 +2178,7 @@
"testing",
"xunit"
],
"time": "2015-10-06T15:47:00+00:00"
"time": "2015-10-06 15:47:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -2157,7 +2225,7 @@
"filesystem",
"iterator"
],
"time": "2016-10-03T07:40:28+00:00"
"time": "2016-10-03 07:40:28"
},
{
"name": "phpunit/php-text-template",
@@ -2198,7 +2266,7 @@
"keywords": [
"template"
],
"time": "2015-06-21T13:50:34+00:00"
"time": "2015-06-21 13:50:34"
},
{
"name": "phpunit/php-timer",
@@ -2242,7 +2310,7 @@
"keywords": [
"timer"
],
"time": "2016-05-12T18:03:57+00:00"
"time": "2016-05-12 18:03:57"
},
{
"name": "phpunit/php-token-stream",
@@ -2291,7 +2359,7 @@
"keywords": [
"tokenizer"
],
"time": "2016-11-15T14:06:22+00:00"
"time": "2016-11-15 14:06:22"
},
{
"name": "phpunit/phpunit",
@@ -2363,7 +2431,7 @@
"testing",
"xunit"
],
"time": "2017-02-06T05:18:07+00:00"
"time": "2017-02-06 05:18:07"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -2419,7 +2487,7 @@
"mock",
"xunit"
],
"time": "2015-10-02T06:51:40+00:00"
"time": "2015-10-02 06:51:40"
},
{
"name": "psr/http-message",
@@ -2469,7 +2537,7 @@
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
"time": "2016-08-06 14:39:51"
},
{
"name": "sebastian/comparator",
@@ -2533,7 +2601,7 @@
"compare",
"equality"
],
"time": "2017-01-29T09:50:25+00:00"
"time": "2017-01-29 09:50:25"
},
{
"name": "sebastian/diff",
@@ -2585,7 +2653,7 @@
"keywords": [
"diff"
],
"time": "2015-12-08T07:14:41+00:00"
"time": "2015-12-08 07:14:41"
},
{
"name": "sebastian/environment",
@@ -2635,7 +2703,7 @@
"environment",
"hhvm"
],
"time": "2016-08-18T05:49:44+00:00"
"time": "2016-08-18 05:49:44"
},
{
"name": "sebastian/exporter",
@@ -2702,7 +2770,7 @@
"export",
"exporter"
],
"time": "2016-06-17T09:04:28+00:00"
"time": "2016-06-17 09:04:28"
},
{
"name": "sebastian/global-state",
@@ -2753,7 +2821,7 @@
"keywords": [
"global state"
],
"time": "2015-10-12T03:26:01+00:00"
"time": "2015-10-12 03:26:01"
},
{
"name": "sebastian/recursion-context",
@@ -2806,7 +2874,7 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2015-11-11T19:50:13+00:00"
"time": "2015-11-11 19:50:13"
},
{
"name": "sebastian/version",
@@ -2841,7 +2909,7 @@
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2015-06-21T13:59:46+00:00"
"time": "2015-06-21 13:59:46"
},
{
"name": "symfony/browser-kit",
@@ -2898,7 +2966,7 @@
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com",
"time": "2017-01-31T21:49:23+00:00"
"time": "2017-01-31 21:49:23"
},
{
"name": "symfony/css-selector",
@@ -2951,7 +3019,7 @@
],
"description": "Symfony CssSelector Component",
"homepage": "https://symfony.com",
"time": "2017-01-02T20:32:22+00:00"
"time": "2017-01-02 20:32:22"
},
{
"name": "symfony/dom-crawler",
@@ -3007,7 +3075,7 @@
],
"description": "Symfony DomCrawler Component",
"homepage": "https://symfony.com",
"time": "2017-01-21T17:14:11+00:00"
"time": "2017-01-21 17:14:11"
},
{
"name": "symfony/finder",
@@ -3056,7 +3124,7 @@
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com",
"time": "2017-01-02T20:32:22+00:00"
"time": "2017-01-02 20:32:22"
},
{
"name": "symfony/process",
@@ -3105,7 +3173,7 @@
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2017-02-03T12:11:38+00:00"
"time": "2017-02-03 12:11:38"
},
{
"name": "webmozart/assert",
@@ -3155,7 +3223,7 @@
"check",
"validate"
],
"time": "2016-11-23T20:04:58+00:00"
"time": "2016-11-23 20:04:58"
}
],
"aliases": [

View File

@@ -1,59 +0,0 @@
<?php
namespace Grav\Common\Collection;
use RocketTheme\Toolbox\ArrayTraits\ArrayAccess;
use RocketTheme\Toolbox\ArrayTraits\Countable;
class AbstractCollection implements CollectionInterface
{
use ArrayAccess, Countable;
/**
* @var array
*/
protected $items = [];
/**
* @param array $variables
* @return static
*/
public static function __set_state(array $variables)
{
$instance = new static();
$instance->items = $variables['items'];
return $instance;
}
/**
* Add item to the list.
*
* @param mixed $item
* @param string $key
* @return $this
*/
public function add($item, $key = null)
{
$this->offsetSet($key, $item);
return $this;
}
/**
* Remove item from the list.
*
* @param $key
*/
public function remove($key)
{
$this->offsetUnset($key);
}
/**
* @return \ArrayIterator
*/
public function getIterator()
{
return new \ArrayIterator($this->items);
}
}

View File

@@ -1,15 +0,0 @@
<?php
namespace Grav\Common\Object;
use Grav\Common\Collection\CollectionInterface;
interface ObjectCollectionInterface extends CollectionInterface
{
/**
*
* Create a clone from this collection.
*
* @return static
*/
public function getClone();
}

View File

@@ -1,29 +0,0 @@
<?php
namespace Grav\Common\Collection;
use RocketTheme\Toolbox\ArrayTraits\ArrayAccess;
trait CloneCollectionTrait
{
use ArrayAccess;
public function __clone()
{
foreach ($this as $key => $value) {
if (is_object($value)) {
$this->offsetSet($key, clone $value);
}
}
}
/**
*
* Create a clone from this collection.
*
* @return static
*/
public function getClone()
{
return clone $this;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Grav\Common\Collection;
use Doctrine\Common\Collections\ArrayCollection;
class Collection extends ArrayCollection implements CollectionInterface
{
/**
* Reverse the order of the items.
*
* @return static
*/
public function reverse()
{
return $this->createFrom(array_reverse($this->toArray()));
}
/**
* Shuffle items.
*
* @return static
*/
public function shuffle()
{
$keys = $this->getKeys();
shuffle($keys);
return $this->createFrom(array_replace(array_flip($keys), $this->toArray()));
}
}

View File

@@ -1,21 +1,21 @@
<?php
namespace Grav\Common\Collection;
interface CollectionInterface extends \IteratorAggregate, \ArrayAccess, \Countable
use Doctrine\Common\Collections\Collection;
interface CollectionInterface extends Collection
{
/**
* Add item to the list.
* Reverse the order of the items.
*
* @param mixed $item
* @param string $key
* @return $this
* @return static
*/
public function add($item, $key = null);
public function reverse();
/**
* Remove item from the list.
* Shuffle items.
*
* @param $key
* @return static
*/
public function remove($key);
public function shuffle();
}

View File

@@ -3,23 +3,30 @@ namespace Grav\Common\Collection;
interface ObjectCollectionInterface extends CollectionInterface
{
/**
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
*/
public function copy();
/**
* @param string $property Object property to be fetched.
* @return array Values of the property.
*/
public function get($property);
public function getProperty($property);
/**
* @param string $property Object property to be updated.
* @param string $value New value.
* @return $this
*/
public function set($property, $value);
public function setProperty($property, $value);
/**
* @param string $name Method name.
* @param array $arguments List of arguments passed to the function.
* @return array Return values.
*/
public function __call($name, array $arguments);
public function call($name, array $arguments);
}

View File

@@ -1,62 +1,33 @@
<?php
namespace Grav\Common\Collection;
use RocketTheme\Toolbox\ArrayTraits\ArrayAccess;
trait ObjectCollectionTrait
{
use ArrayAccess;
/**
* @var string
*/
protected $keyProperty = null;
/**
* Add item to the list.
* Create a copy from this collection by cloning all objects in the collection.
*
* @param object $object
* @param string $key
* @return $this
* @return static
*/
public function add($object, $key = null)
public function copy()
{
$objKey = $key ?: $this->getObjectKey($object);
$this->offsetSet(is_null($objKey) ? $key : $objKey, $object);
return $this;
}
/**
* Remove item from the list.
*
* @param string|object $key
* @return $this
*/
public function remove($key)
{
if (is_object($key)) {
$key = $this->getObjectKey($key);
if (is_null($key)) {
return $this;
}
$list = [];
foreach ($this as $key => $value) {
$list[$key] = is_object($value) ? clone $value : $value;
}
$this->offsetUnset($key);
return $this;
return $this->createFrom($list);
}
/**
* @param string $property Object property to be fetched.
* @return array Values of the property.
* @return array Key/Value pairs of the properties.
*/
public function get($property)
public function getProperty($property)
{
$list = [];
foreach ($this as $id => $object) {
$key = $this->getObjectKey($object);
$list[is_null($key) ? $id : $key] = $this->getObjectValue($object, $property);
foreach ($this as $id => $element) {
$list[$id] = isset($element->{$property}) ? $element->{$property} : null;
}
return $list;
@@ -65,63 +36,27 @@ trait ObjectCollectionTrait
/**
* @param string $property Object property to be updated.
* @param string $value New value.
* @return $this
*/
public function set($property, $value)
public function setProperty($property, $value)
{
foreach ($this as $object) {
$object->{$property} = $value;
foreach ($this as $element) {
$element->{$property} = $value;
}
return $this;
}
/**
* @param string $name Method name.
* @param string $method Method name.
* @param array $arguments List of arguments passed to the function.
* @return array Return values.
*/
public function __call($name, array $arguments)
public function call($method, array $arguments)
{
$list = [];
foreach ($this as $id => $object) {
$key = $this->getObjectKey($object);
$list[is_null($key) ? $id : $key] = $this->getObjectCallResult($object, $name, $arguments);
foreach ($this as $id => $element) {
$list[$id] = method_exists($element, $method) ? call_user_func_array([$element, $method], $arguments) : null;
}
return $list;
}
/**
* @param object $object
* @return string|null
*/
protected function getObjectKey($object)
{
$keyProperty = $this->keyProperty;
return $keyProperty && isset($object->{$keyProperty}) ? (string) $object->{$keyProperty} : null;
}
/**
* @param object $object
* @param string $property
* @return mixed
*/
protected function getObjectValue($object, $property)
{
return isset($object->{$property}) ? $object->{$property} : null;
}
/**
* @param object $object
* @param string $name;
* @param array $arguments
* @return mixed
*/
protected function getObjectCallResult($object, $name, $arguments)
{
return method_exists($object, $name) ? call_user_func_array([$object, $name], $arguments) : null;
}
}

View File

@@ -1,84 +0,0 @@
<?php
namespace Grav\Common\Collection;
use RocketTheme\Toolbox\ArrayTraits\ArrayAccess;
trait SortingCollectionTrait
{
use ArrayAccess;
/**
* Reverse the order of the items.
*
* @return $this
*/
public function reverse()
{
$this->items = array_reverse($this->items);
return $this;
}
/**
* Shuffle items.
*
* @return $this
*/
public function shuffle()
{
$keys = array_keys($this->items);
shuffle($keys);
$this->items = array_replace(array_flip($keys), $this->items);
return $this;
}
/**
* Sort collection by values using a user-defined comparison function.
*
* @param callable $callback
* @return $this
*/
public function sort(callable $callback)
{
uasort($this->items, $callback);
return $this;
}
/**
* Sort collection by keys.
*
* @return $this
*/
public function ksort($sort_flags = SORT_REGULAR)
{
ksort($this->items, $sort_flags);
return $this;
}
/**
* Sort collection by keys in reverse order.
*
* @return $this
*/
public function krsort($sort_flags = SORT_REGULAR)
{
krsort($this->items, $sort_flags);
return $this;
}
/**
* Sort collection by keys using a user-defined comparison function.
*
* @return $this
*/
public function uksort(callable $key_compare_func)
{
uksort($this->items, $key_compare_func);
return $this;
}}

View File

@@ -26,6 +26,12 @@ abstract class AbstractObject implements ObjectInterface
*/
static protected $storage;
/**
* If you don't have global storage, override this in extending class.
* @var ObjectFinderInterface
*/
static protected $finder;
/**
* Default properties for the object.
* @var array
@@ -61,6 +67,22 @@ abstract class AbstractObject implements ObjectInterface
protected $initialized = false;
/**
* @param StorageInterface $storage
*/
static public function setStorage(StorageInterface $storage)
{
static::$storage = $storage;
}
/**
* @param ObjectFinderInterface $finder
*/
static public function setFinder(ObjectFinderInterface $finder)
{
static::$finder = $finder;
}
/**
* Returns the global instance to the object.
*
@@ -148,6 +170,14 @@ abstract class AbstractObject implements ObjectInterface
return new $collectionClass($results);
}
/**
* @return ObjectFinderInterface
*/
static public function search()
{
return static::$finder;
}
/**
* Removes all or selected instances from the object cache.
*

View File

@@ -90,8 +90,6 @@ abstract class AbstractObjectFinder implements ObjectFinderInterface
/**
* Set limit to the query.
*
* If this function isn't used, RokClub will use threads per page configuration setting.
*
* @param int $limit
*
* @return $this
@@ -130,7 +128,7 @@ abstract class AbstractObjectFinder implements ObjectFinderInterface
}
if ($direction) {
$this->query[] = ['order', $field, (int)$direction];
$this->query['order'][] = [$field, (int)$direction];
}
return $this;
@@ -160,17 +158,17 @@ abstract class AbstractObjectFinder implements ObjectFinderInterface
case '<':
case '<=':
$this->checkOperator($value);
$this->query[] = ['where', $field, $operation, $value];
$this->query['where'][] = [$field, $operation, $value];
break;
case '==':
case '!=':
$this->checkEqOperator($value);
$this->query[] = ['where', $field, $operation, $value];
$this->query['where'][] = [$field, $operation, $value];
break;
case 'BETWEEN':
case 'NOT BETWEEN':
$this->checkBetweenOperator($value);
$this->query[] = ['where', $field, $operation, array_values($value)];
$this->query['where'][] = [$field, $operation, array_values($value)];
break;
case 'IN':
if (is_null($value) || (is_array($value) && empty($value))) {
@@ -178,7 +176,7 @@ abstract class AbstractObjectFinder implements ObjectFinderInterface
$this->skip = true;
} else {
$this->checkInOperator($value);
$this->query[] = ['where', $field, $operation, array_values((array)$value)];
$this->query['where'][] = [$field, $operation, array_values((array)$value)];
}
break;
case 'NOT IN':
@@ -186,7 +184,7 @@ abstract class AbstractObjectFinder implements ObjectFinderInterface
// NOT IN (nothing): optimized away.
} else {
$this->checkInOperator($value);
$this->query[] = ['where', $field, $operation, array_values((array)$value)];
$this->query['where'][] = [$field, $operation, array_values((array)$value)];
}
break;
default:
@@ -216,7 +214,7 @@ abstract class AbstractObjectFinder implements ObjectFinderInterface
$this->start($start)->limit($limit);
$this->prepare();
$results = (array) $this->storage->find($this->query);
$results = (array) $this->storage->find($this->query, $this->start, $this->limit);
$this->query = $query;

View File

@@ -1,20 +1,11 @@
<?php
namespace Grav\Common\Object;
use Grav\Common\Collection\AbstractCollection;
use Grav\Common\Collection\Collection;
use Grav\Common\Collection\ObjectCollectionInterface;
use Grav\Common\Collection\ObjectCollectionTrait;
class ObjectCollection extends AbstractCollection implements ObjectCollectionInterface
class ObjectCollection extends Collection implements ObjectCollectionInterface
{
use ObjectCollectionTrait;
/**
* Collection constructor.
* @param array|AbstractObject[] $items
*/
public function __construct(array $items)
{
$this->items = $items;
}
}

View File

@@ -30,8 +30,6 @@ interface ObjectFinderInterface
/**
* Set limit to the query.
*
* If this function isn't used, RokClub will use threads per page configuration setting.
*
* @param int $limit
*
* @return $this

View File

@@ -13,7 +13,7 @@ interface StorageInterface
/**
* @param AbstractObject $object
* @return string|int Id
* @return string Id
*/
public function save(AbstractObject $object);
@@ -24,7 +24,7 @@ interface StorageInterface
public function delete(AbstractObject $object);
/**
* @param array|int[]|string[] $list
* @param array|string[] $list
* @return array
*/
public function loadList(array $list);
@@ -37,7 +37,9 @@ interface StorageInterface
/**
* @param array $query
* @return array|int[]|string[]
* @param int $start
* @param int $limit
* @return array|string[]
*/
public function find(array $query);
public function find(array $query, $start, $limit);
}

View File

@@ -33,7 +33,7 @@ class Group extends Data
*
* @param string $groupname
*
* @return object
* @return bool
*/
public static function groupExists($groupname)
{