Advertisement
d4rky

Queueable class

Apr 26th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2. /**
  3.  * A class that allows multiple method inheritance by queuing different implementations,
  4.  * and running them one after another. Works only for static classes, but it's not really mandatory.
  5.  */
  6.  
  7. abstract class Queueable
  8. {
  9.     protected static $_implementations = array();
  10.  
  11.     protected function __construct() {}
  12.  
  13.     /*
  14.      * Example: Entries::register_method('list', 'Entries_Sortable');
  15.      */
  16.     public static function register_method($method_name, $class_name)
  17.     {
  18.         if(!isset(static::$_implementations[$method_name]))
  19.         {
  20.             static::$_implementations[$method_name] = array();
  21.         }
  22.  
  23.         static::$_implementations[$method_name][] = $class_name;
  24.     }
  25.  
  26.     protected static function call($method_name, $arguments)
  27.     {
  28.         if(isset(static::$_implementations[$method_name]))
  29.         {
  30.             foreach(static::$_implementations[$method_name] as $class)
  31.             {
  32.                 call_user_func_array($class.'::'.$method_name, $arguments);
  33.             }
  34.         }
  35.     }
  36.  
  37.     public static function __callStatic($name, $arguments)
  38.     {
  39.         return static::call($name, $arguments);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement