Find file History
Type Name Latest commit message Commit time
Failed to load latest commit information.
Responsible PHP7 Chain Of Responsibilities Sep 22, 2016
Tests Replaced with strict assertions Sep 29, 2018
uml Added Behavioral pattern UMLs Jul 31, 2014
Handler.php PHP7 Chain Of Responsibilities Sep 22, 2016
README.rst [pl translation] Behavioral. Jun 28, 2017


Chain Of Responsibilities


To build a chain of objects to handle a call in sequential order. If one object cannot handle a call, it delegates the call to the next in the chain and so forth.


  • logging framework, where each chain element decides autonomously what to do with a log message
  • a Spam filter
  • Caching: first object is an instance of e.g. a Memcached Interface, if that "misses" it delegates the call to the database interface
  • Yii Framework: CFilterChain is a chain of controller action filters. the executing point is passed from one filter to the next along the chain, and only if all filters say "yes", the action can be invoked at last.

UML Diagram

Alt ChainOfResponsibility UML Diagram


You can also find this code on GitHub


.. literalinclude:: Handler.php
   :language: php


.. literalinclude:: Responsible/HttpInMemoryCacheHandler.php
   :language: php


.. literalinclude:: Responsible/SlowDatabaseHandler.php
   :language: php



.. literalinclude:: Tests/ChainTest.php
   :language: php