summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/stdlib/src/Filter
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ipl/stdlib/src/Filter')
-rw-r--r--vendor/ipl/stdlib/src/Filter/All.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/Any.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/Chain.php179
-rw-r--r--vendor/ipl/stdlib/src/Filter/Condition.php84
-rw-r--r--vendor/ipl/stdlib/src/Filter/Equal.php31
-rw-r--r--vendor/ipl/stdlib/src/Filter/GreaterThan.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/GreaterThanOrEqual.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/LessThan.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/LessThanOrEqual.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/Like.php31
-rw-r--r--vendor/ipl/stdlib/src/Filter/MetaData.php20
-rw-r--r--vendor/ipl/stdlib/src/Filter/MetaDataProvider.php15
-rw-r--r--vendor/ipl/stdlib/src/Filter/None.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/Rule.php7
-rw-r--r--vendor/ipl/stdlib/src/Filter/Unequal.php31
-rw-r--r--vendor/ipl/stdlib/src/Filter/Unlike.php31
16 files changed, 478 insertions, 0 deletions
diff --git a/vendor/ipl/stdlib/src/Filter/All.php b/vendor/ipl/stdlib/src/Filter/All.php
new file mode 100644
index 0000000..67b47b6
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/All.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class All extends Chain
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Any.php b/vendor/ipl/stdlib/src/Filter/Any.php
new file mode 100644
index 0000000..5d47ebe
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Any.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class Any extends Chain
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Chain.php b/vendor/ipl/stdlib/src/Filter/Chain.php
new file mode 100644
index 0000000..9422d3a
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Chain.php
@@ -0,0 +1,179 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+use ArrayIterator;
+use Countable;
+use IteratorAggregate;
+use OutOfBoundsException;
+use Traversable;
+
+abstract class Chain implements Rule, MetaDataProvider, IteratorAggregate, Countable
+{
+ use MetaData;
+
+ /** @var array<int, Rule> */
+ protected $rules = [];
+
+ /**
+ * Create a new Chain
+ *
+ * @param Rule ...$rules
+ */
+ public function __construct(Rule ...$rules)
+ {
+ foreach ($rules as $rule) {
+ $this->add($rule);
+ }
+ }
+
+ /**
+ * Clone this chain's meta data and rules
+ */
+ public function __clone()
+ {
+ if ($this->metaData !== null) {
+ $this->metaData = clone $this->metaData;
+ }
+
+ foreach ($this->rules as $i => $rule) {
+ $this->rules[$i] = clone $rule;
+ }
+ }
+
+ /**
+ * Get an iterator this chain's rules
+ *
+ * @return ArrayIterator<int, Rule>
+ */
+ public function getIterator(): Traversable
+ {
+ return new ArrayIterator($this->rules);
+ }
+
+ /**
+ * Add a rule to this chain
+ *
+ * @param Rule $rule
+ *
+ * @return $this
+ */
+ public function add(Rule $rule)
+ {
+ $this->rules[] = $rule;
+
+ return $this;
+ }
+
+ /**
+ * Prepend a rule to an existing rule in this chain
+ *
+ * @param Rule $rule
+ * @param Rule $before
+ *
+ * @throws OutOfBoundsException In case no existing rule is found
+ * @return $this
+ */
+ public function insertBefore(Rule $rule, Rule $before)
+ {
+ $ruleAt = array_search($before, $this->rules, true);
+ if ($ruleAt === false) {
+ throw new OutOfBoundsException('Reference rule not found');
+ }
+
+ array_splice($this->rules, $ruleAt, 0, [$rule]);
+
+ return $this;
+ }
+
+ /**
+ * Append a rule to an existing rule in this chain
+ *
+ * @param Rule $rule
+ * @param Rule $after
+ *
+ * @throws OutOfBoundsException In case no existing rule is found
+ * @return $this
+ */
+ public function insertAfter(Rule $rule, Rule $after)
+ {
+ $ruleAt = array_search($after, $this->rules, true);
+ if ($ruleAt === false) {
+ throw new OutOfBoundsException('Reference rule not found');
+ }
+
+ array_splice($this->rules, $ruleAt + 1, 0, [$rule]);
+
+ return $this;
+ }
+
+ /**
+ * Get whether this chain contains the given rule
+ *
+ * @param Rule $rule
+ *
+ * @return bool
+ */
+ public function has(Rule $rule)
+ {
+ return array_search($rule, $this->rules, true) !== false;
+ }
+
+ /**
+ * Replace a rule with another one in this chain
+ *
+ * @param Rule $rule
+ * @param Rule $replacement
+ *
+ * @throws OutOfBoundsException In case no existing rule is found
+ * @return $this
+ */
+ public function replace(Rule $rule, Rule $replacement)
+ {
+ $ruleAt = array_search($rule, $this->rules, true);
+ if ($ruleAt === false) {
+ throw new OutOfBoundsException('Rule to replace not found');
+ }
+
+ array_splice($this->rules, $ruleAt, 1, [$replacement]);
+
+ return $this;
+ }
+
+ /**
+ * Remove a rule from this chain
+ *
+ * @param Rule $rule
+ *
+ * @return $this
+ */
+ public function remove(Rule $rule)
+ {
+ $ruleAt = array_search($rule, $this->rules, true);
+ if ($ruleAt !== false) {
+ array_splice($this->rules, $ruleAt, 1, []);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Get whether this chain has any rules
+ *
+ * @return bool
+ */
+ public function isEmpty()
+ {
+ return empty($this->rules);
+ }
+
+ /**
+ * Count this chain's rules
+ *
+ * @return int
+ */
+ public function count(): int
+ {
+ return count($this->rules);
+ }
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Condition.php b/vendor/ipl/stdlib/src/Filter/Condition.php
new file mode 100644
index 0000000..cc35610
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Condition.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+abstract class Condition implements Rule, MetaDataProvider
+{
+ use MetaData;
+
+ /** @var string */
+ protected $column;
+
+ /** @var mixed */
+ protected $value;
+
+ /**
+ * Create a new Condition
+ *
+ * @param string $column
+ * @param mixed $value
+ */
+ public function __construct($column, $value)
+ {
+ $this->setColumn($column)
+ ->setValue($value);
+ }
+
+ /**
+ * Clone this condition's meta data
+ */
+ public function __clone()
+ {
+ if ($this->metaData !== null) {
+ $this->metaData = clone $this->metaData;
+ }
+ }
+
+ /**
+ * Set this condition's column
+ *
+ * @param string $column
+ *
+ * @return $this
+ */
+ public function setColumn($column)
+ {
+ $this->column = $column;
+
+ return $this;
+ }
+
+ /**
+ * Get this condition's column
+ *
+ * @return string
+ */
+ public function getColumn()
+ {
+ return $this->column;
+ }
+
+ /**
+ * Set this condition's value
+ *
+ * @param mixed $value
+ *
+ * @return $this
+ */
+ public function setValue($value)
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ /**
+ * Get this condition's value
+ *
+ * @return mixed
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Equal.php b/vendor/ipl/stdlib/src/Filter/Equal.php
new file mode 100644
index 0000000..71da490
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Equal.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class Equal extends Condition
+{
+ /** @var bool */
+ protected $ignoreCase = false;
+
+ /**
+ * Ignore case on both sides of the equation
+ *
+ * @return $this
+ */
+ public function ignoreCase()
+ {
+ $this->ignoreCase = true;
+
+ return $this;
+ }
+
+ /**
+ * Return whether this rule ignores case
+ *
+ * @return bool
+ */
+ public function ignoresCase()
+ {
+ return $this->ignoreCase;
+ }
+}
diff --git a/vendor/ipl/stdlib/src/Filter/GreaterThan.php b/vendor/ipl/stdlib/src/Filter/GreaterThan.php
new file mode 100644
index 0000000..fd8190c
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/GreaterThan.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class GreaterThan extends Condition
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/GreaterThanOrEqual.php b/vendor/ipl/stdlib/src/Filter/GreaterThanOrEqual.php
new file mode 100644
index 0000000..4cd4a73
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/GreaterThanOrEqual.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class GreaterThanOrEqual extends Condition
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/LessThan.php b/vendor/ipl/stdlib/src/Filter/LessThan.php
new file mode 100644
index 0000000..297493f
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/LessThan.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class LessThan extends Condition
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/LessThanOrEqual.php b/vendor/ipl/stdlib/src/Filter/LessThanOrEqual.php
new file mode 100644
index 0000000..ef35974
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/LessThanOrEqual.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class LessThanOrEqual extends Condition
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Like.php b/vendor/ipl/stdlib/src/Filter/Like.php
new file mode 100644
index 0000000..7a06279
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Like.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class Like extends Condition
+{
+ /** @var bool */
+ protected $ignoreCase = false;
+
+ /**
+ * Ignore case on both sides of the equation
+ *
+ * @return $this
+ */
+ public function ignoreCase()
+ {
+ $this->ignoreCase = true;
+
+ return $this;
+ }
+
+ /**
+ * Return whether this rule ignores case
+ *
+ * @return bool
+ */
+ public function ignoresCase()
+ {
+ return $this->ignoreCase;
+ }
+}
diff --git a/vendor/ipl/stdlib/src/Filter/MetaData.php b/vendor/ipl/stdlib/src/Filter/MetaData.php
new file mode 100644
index 0000000..6fe2523
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/MetaData.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+use ipl\Stdlib\Data;
+
+trait MetaData
+{
+ /** @var Data */
+ protected $metaData;
+
+ public function metaData()
+ {
+ if ($this->metaData === null) {
+ $this->metaData = new Data();
+ }
+
+ return $this->metaData;
+ }
+}
diff --git a/vendor/ipl/stdlib/src/Filter/MetaDataProvider.php b/vendor/ipl/stdlib/src/Filter/MetaDataProvider.php
new file mode 100644
index 0000000..ef9557e
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/MetaDataProvider.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+use ipl\Stdlib\Data;
+
+interface MetaDataProvider
+{
+ /**
+ * Get this rule's meta data
+ *
+ * @return Data
+ */
+ public function metaData();
+}
diff --git a/vendor/ipl/stdlib/src/Filter/None.php b/vendor/ipl/stdlib/src/Filter/None.php
new file mode 100644
index 0000000..a1b14f7
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/None.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class None extends Chain
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Rule.php b/vendor/ipl/stdlib/src/Filter/Rule.php
new file mode 100644
index 0000000..dc83c80
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Rule.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+interface Rule
+{
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Unequal.php b/vendor/ipl/stdlib/src/Filter/Unequal.php
new file mode 100644
index 0000000..5e37cbd
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Unequal.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class Unequal extends Condition
+{
+ /** @var bool */
+ protected $ignoreCase = false;
+
+ /**
+ * Ignore case on both sides of the equation
+ *
+ * @return $this
+ */
+ public function ignoreCase()
+ {
+ $this->ignoreCase = true;
+
+ return $this;
+ }
+
+ /**
+ * Return whether this rule ignores case
+ *
+ * @return bool
+ */
+ public function ignoresCase()
+ {
+ return $this->ignoreCase;
+ }
+}
diff --git a/vendor/ipl/stdlib/src/Filter/Unlike.php b/vendor/ipl/stdlib/src/Filter/Unlike.php
new file mode 100644
index 0000000..16b9fb3
--- /dev/null
+++ b/vendor/ipl/stdlib/src/Filter/Unlike.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace ipl\Stdlib\Filter;
+
+class Unlike extends Condition
+{
+ /** @var bool */
+ protected $ignoreCase = false;
+
+ /**
+ * Ignore case on both sides of the equation
+ *
+ * @return $this
+ */
+ public function ignoreCase()
+ {
+ $this->ignoreCase = true;
+
+ return $this;
+ }
+
+ /**
+ * Return whether this rule ignores case
+ *
+ * @return bool
+ */
+ public function ignoresCase()
+ {
+ return $this->ignoreCase;
+ }
+}