Skip to content

Files

Latest commit

b8aa050 · Sep 27, 2023

History

History
This branch is up to date with DesignPatternsPHP/DesignPatternsPHP:main.

FluentInterface

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 1, 2021
Aug 19, 2019
Sep 27, 2023
Oct 1, 2021

Purpose

To write code that is easy readable just like sentences in a natural language (like English).

Examples

  • Doctrine2's QueryBuilder works something like that example class below
  • PHPUnit uses fluent interfaces to build mock objects

UML Diagram

Alt FluentInterface UML Diagram

Code

You can also find this code on GitHub

Sql.php

.. literalinclude:: Sql.php
   :language: php
   :linenos:

Test

Tests/FluentInterfaceTest.php

.. literalinclude:: Tests/FluentInterfaceTest.php
   :language: php
   :linenos: