Criterias are classes used to hold and apply query condition when retrieving data from the database through a Repository.
Without using a Criteria class, you can add your query conditions to a Repository or to a Model as scope, but with Criterias, your query conditions can be shared across multiple Models and Repositories. It allows you to define the query condition once and use it anywhere in the App.
Every Container MAY have its own Criterias. However, shared Criterias SHOULD be created in the Ship layer.
A Criteria MUST not contain any extra code, if it needs data, the data SHOULD be passed to it from the Actions or the Task. It SHOULD not run (call) any Task for data.
All Criterias MUST extend from
Every Criteria SHOULD have an
A simple query condition example
"where user_id = $id", this can be named "This User Criteria", and used with all Models which have relations with the User Model.
Example: a shared Criteria
Criteria accepting data input:
Example: Passing data from
For more information about the Criteria read this.