Beispiel #1
0
 /**
  * fetch as Arrayy-Object
  *
  * @param bool $reset
  *
  * @return Arrayy|false false on error
  */
 public function fetchArrayy($reset = false)
 {
     if ($reset === true) {
         $this->reset();
     }
     $row = \mysqli_fetch_assoc($this->_result);
     if ($row) {
         return Arrayy::create($this->cast($row));
     }
     return false;
 }
Beispiel #2
0
 /**
  * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular property
  * within that.
  *
  * @param        $property
  * @param        $value
  * @param string $comparisonOp
  *                            'eq' (equals),<br />
  *                            'gt' (greater),<br />
  *                            'gte' || 'ge' (greater or equals),<br />
  *                            'lt' (less),<br />
  *                            'lte' || 'le' (less or equals),<br />
  *                            'ne' (not equals),<br />
  *                            'contains',<br />
  *                            'notContains',<br />
  *                            'newer' (via strtotime),<br />
  *                            'older' (via strtotime),<br />
  *
  * @return Arrayy (Immutable)
  */
 public function filterBy($property, $value, $comparisonOp = null)
 {
     if (!$comparisonOp) {
         $comparisonOp = is_array($value) ? 'contains' : 'eq';
     }
     $ops = array('eq' => function ($item, $prop, $value) {
         return $item[$prop] === $value;
     }, 'gt' => function ($item, $prop, $value) {
         return $item[$prop] > $value;
     }, 'ge' => function ($item, $prop, $value) {
         return $item[$prop] >= $value;
     }, 'gte' => function ($item, $prop, $value) {
         return $item[$prop] >= $value;
     }, 'lt' => function ($item, $prop, $value) {
         return $item[$prop] < $value;
     }, 'le' => function ($item, $prop, $value) {
         return $item[$prop] <= $value;
     }, 'lte' => function ($item, $prop, $value) {
         return $item[$prop] <= $value;
     }, 'ne' => function ($item, $prop, $value) {
         return $item[$prop] !== $value;
     }, 'contains' => function ($item, $prop, $value) {
         return in_array($item[$prop], (array) $value, true);
     }, 'notContains' => function ($item, $prop, $value) {
         return !in_array($item[$prop], (array) $value, true);
     }, 'newer' => function ($item, $prop, $value) {
         return strtotime($item[$prop]) > strtotime($value);
     }, 'older' => function ($item, $prop, $value) {
         return strtotime($item[$prop]) < strtotime($value);
     });
     $result = array_values(array_filter((array) $this->array, function ($item) use($property, $value, $ops, $comparisonOp) {
         $item = (array) $item;
         $itemArrayy = new Arrayy($item);
         $item[$property] = $itemArrayy->get($property, array());
         return $ops[$comparisonOp]($item, $property, $value);
     }));
     return static::create($result);
 }