Neuron-PHP

Base
in package
implements ICriteria

AbstractYes

Abstract base class for implementing the Criteria pattern.

This class provides the foundation for creating composable criteria objects that can be combined using logical operators (AND, OR, NOT). The Criteria pattern allows for flexible, reusable, and chainable query conditions.

Concrete implementations should define the meetCriteria() method to specify the actual filtering logic. This base class provides the logical composition methods for building complex criteria chains.

The pattern enables:

  • Composable query logic through method chaining
  • Reusable criteria components across different contexts
  • Clear separation of individual criteria concerns
  • Dynamic query building at runtime
Tags
example
class AgeRangeCriteria extends Base
{
    private $minAge, $maxAge;

    public function __construct(int $min, int $max)
    {
        $this->minAge = $min;
        $this->maxAge = $max;
    }

    public function meetCriteria(array $items): array
    {
        return array_filter($items, function($item) {
            return $item->age >= $this->minAge && $item->age <= $this->maxAge;
        });
    }
}

// Usage: $adults = (new AgeRangeCriteria(18, 65))->_and(new ActiveCriteria())->meetCriteria($users);

Table of Contents

Interfaces

ICriteria
Criteria pattern interface for entity filtering and selection.

Properties

$_criteria  : mixed

Methods

_and()  : AndCriteria
Creates an AND combination of this criteria with another criteria.
_not()  : NotCriteria
Creates a NOT (negation) of this criteria.
_or()  : OrCriteria
Creates an OR combination of this criteria with another criteria.

Properties

$_criteria

protected mixed $_criteria

Methods

_and()

Creates an AND combination of this criteria with another criteria.

public _and(ICriteria $otherCriteria) : AndCriteria
Parameters
$otherCriteria : ICriteria

The criteria to combine with using AND logic

Return values
AndCriteria

A new criteria that represents this AND other

_not()

Creates a NOT (negation) of this criteria.

public _not() : NotCriteria
Return values
NotCriteria

A new criteria that represents the negation of this criteria

_or()

Creates an OR combination of this criteria with another criteria.

public _or(ICriteria $otherCriteria) : OrCriteria
Parameters
$otherCriteria : ICriteria

The criteria to combine with using OR logic

Return values
OrCriteria

A new criteria that represents this OR other


        
On this page

Search results