Skip to content

Feature: Useful Common Code

phlogisticfugu edited this page Aug 24, 2014 · 3 revisions

Squirt provides a number of helper class in Squirt\Common.

SquirtableInterface

This interface should be used in classes to mark them as squirt-compatible. Note that Squirt does not enforce this interface, it merely looks for a static factory method. Rather, this interface will help in your own code so that PHP checks for proper method signature declarations.

SquirtableTrait

This trait assists in defining the "simple" static factory method which just calls the constructor method with all parameters. When writing your own classes from scratch, use this trait and make the __construct(array $params) method protected for maximum flexibility/compatibility.

SquirtableLoggingInterface and SquirtableLoggingTrait

This interface and trait work similarly to the above, only these help to facilitate the injection of a PSR Log logger instance. Note that if you use these, there is no need to also use the SquirtableInterface and SquirtableTrait.

SquirtUtil

This class contains static methods useful in reading and validating values passed into your functions in associative parameter arrays. These methods all encapsulate a pattern which is idiomatic to squirt. For details refer to the source code and unit tests

Container

This class is used internally by Squirt, but can be used to provide a simple squirt-compatible class which just stores all of its parameters as key/value pairs, and which then makes those accessible in an array-like manner.