5.3. Symbol Clauses

A clause is a container for multiple symbols. There are three clauses available in the framework. You can iterate through the clause using a foreach block.

5.3.1. Xyster_Data_Junction

The Junction was mentioned previously as containing multiple Xyster_Data_Criterion objects. It is unique among the Clause classes in that it can hold other Junction objects.

<?php
$junction = Xyster_Data_Junction::all(Xyster_Data_Expression::eq('foo', 'bar'),
    Xyster_Data_Expression::neq('abc', 123));
echo count($junction); // prints 2
foreach( $junction as $criterion ) {
    echo $criterion . "\n";
}

5.3.2. Xyster_Data_Field_Clause

The Field Clause can contain any Xyster_Data_Field object. This includes regular fields, aggregate fields, and grouped fields (since aggregate and group fields inherit from the first).

If no parameter is passed to the constructor of the object, it is created with no elements. You can then add fields to it manually.

<?php
require_once 'Xyster/Data/Field/Clause.php';
$clause = new Xyster_Data_Field_Clause();
$clause->add(Xyster_Data_Field::named('foo'))
    ->add(Xyster_Data_Field::named('bar'));

You can also pass a Xyster_Data_Field object or another Field Clause into the constructor to have those items automatically added.

<?php
// merging with $clause from our example above
$clause2 = new Xyster_Data_Field_Clause($clause);
echo count($clause2); // prints 2

You can add or remove fields from a Field Clause using the add and remove methods. You can also copy all the items from one clause into another using the merge method.

5.3.3. Xyster_Data_Sort_Clause

The Sort Clause can contain any Xyster_Data_Sort object.

If no parameter is passed to the constructor of the object, it is created with no elements. You can then add sorts to it manually.

<?php
require_once 'Xyster/Data/Sort/Clause.php';
$clause = new Xyster_Data_Sort_Clause();
$clause->add(Xyster_Data_Sort::asc('foo'))
    ->add(Xyster_Data_Sort::desc('bar'));

You can also pass a Xyster_Data_Sort object or another Sort Clause into the constructor to have those items automatically added.

<?php
// merging with $clause from our example above
$clause2 = new Xyster_Data_Sort_Clause($clause);
echo count($clause2); // prints 2

You can add or remove sorts from a Sort Clause using the add and remove methods. You can also copy all the items from one clause into another using the merge method.