Advertisement
fruffl

Adapter Pattern

Nov 28th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.48 KB | None | 0 0
  1.     class foo EXTENDS \ILLI\Base\aBase
  2.     {
  3.         private $a;
  4.         public function setAdapter($trigger, $target, $instance)
  5.         {
  6.             $config             = new \ILLI\Base\Component\Delegate\sConfigConstructMethod;
  7.             $config->Context        = $instance;
  8.             $config->functionName       = $target;
  9.            
  10.             $adapter            = new \ILLI\Base\Component\Delegate\Hook\sConcreteAdapter;
  11.             $adapter->triggerMethodName = get_called_class().'::'.$trigger;
  12.             $adapter->Delegate      = new \ILLI\Base\Component\Delegate\Method($config);
  13.            
  14.             $this->tAdapterHook_register($adapter);
  15.            
  16.             $this->a = TRUE;
  17.             return $this;
  18.         }
  19.        
  20.         public function baz($__hello)
  21.         {
  22.             if(TRUE === $this->a)
  23.                 return $this->tAdapterHook_emit(__METHOD__, ['__world' => $__hello]); // strict parameters!
  24.                
  25.             var_dump(__METHOD__);
  26.             var_dump($__hello);
  27.            
  28.             return $this;
  29.         }
  30.     }
  31.    
  32.     class delTarget
  33.     {
  34.         public function target($__world)
  35.         {
  36.             var_dump(__METHOD__);
  37.             var_dump($__world.' World!');
  38.         }
  39.     }
  40.    
  41.     $foo = new foo;
  42.     $foo->baz('Hello')
  43.     ->setAdapter('baz', 'target', new delTarget)
  44.     ->baz('Hi');
  45.    
  46.     var_dump($foo);
  47.  
  48. Output:
  49. string(29) "localhost\illiFW\dev\foo::baz"
  50. string(5) "Hello"
  51. string(38) "localhost\illiFW\dev\delTarget::target"
  52. string(9) "Hi World!"
  53. object(localhost\illiFW\dev\foo)#18 (12) {
  54.  ["a"]=>
  55.   bool(true)
  56.   ["__runtimeConfig":protected]=>
  57.   &array(0) {
  58.   }
  59.   ["__defaultConfig":protected]=>
  60.   array(0) {
  61.   }
  62.   ["__autoConfig":protected]=>
  63.   array(0) {
  64.   }
  65.   ["__methodFilters":protected]=>
  66.   array(0) {
  67.   }
  68.   ["__tBase_autoConfig":"ILLI\Base\aBase":private]=>
  69.   array(0) {
  70.   }
  71.   ["__tBase_initConfig":"ILLI\Base\aBase":private]=>
  72.   array(1) {
  73.     ["__init"]=>
  74.     bool(true)
  75.   }
  76.   ["__tBase_defaultConfig":"ILLI\Base\aBase":private]=>
  77.   array(0) {
  78.   }
  79.   ["__tBase_runtimeConfig":"ILLI\Base\aBase":private]=>
  80.   &array(0) {
  81.   }
  82.   ["__tAdapterHook_hook":protected]=>
  83.   array(1) {
  84.     ["localhost\illiFW\dev\foo::baz"]=>
  85.     object(ILLI\Base\Component\Delegate\Hook\sConcreteAdapter)#32 (4) {
  86.      ["__tStructure_MemberFields":protected]=>
  87.       array(2) {
  88.         [0]=>
  89.         string(17) "triggerMethodName"
  90.         [1]=>
  91.         string(8) "Delegate"
  92.       }
  93.       ["__tStructure_MemberProperties":protected]=>
  94.       array(2) {
  95.         ["triggerMethodName"]=>
  96.         array(5) {
  97.           ["init"]=>
  98.           NULL
  99.           ["contains"]=>
  100.           string(29) "localhost\illiFW\dev\foo::baz"
  101.           ["isTouched"]=>
  102.           bool(true)
  103.           ["flag"]=>
  104.           int(4)
  105.           ["typeOf"]=>
  106.           array(1) {
  107.             [0]=>
  108.             string(6) "string"
  109.           }
  110.         }
  111.         ["Delegate"]=>
  112.         array(5) {
  113.           ["init"]=>
  114.           NULL
  115.           ["contains"]=>
  116.           object(ILLI\Base\Component\Delegate\Method)#38 (3) {
  117.            ["__sInvokable":protected]=>
  118.             object(ILLI\Base\Component\Delegate\sConfigConstructMethod)#26 (4) {
  119.              ["__tStructure_MemberFields":protected]=>
  120.               array(9) {
  121.                 [0]=>
  122.                 string(9) "className"
  123.                 [1]=>
  124.                 string(12) "functionName"
  125.                 [2]=>
  126.                 string(15) "strictArguments"
  127.                 [3]=>
  128.                 string(16) "defaultArguments"
  129.                 [4]=>
  130.                 string(7) "Context"
  131.                 [5]=>
  132.                 string(18) "ContextConstructor"
  133.                 [6]=>
  134.                 string(16) "contextArguments"
  135.                 [7]=>
  136.                 string(10) "methodName"
  137.                 [8]=>
  138.                 string(11) "methodArray"
  139.               }
  140.               ["__tStructure_MemberProperties":protected]=>
  141.               array(9) {
  142.                 ["className"]=>
  143.                 array(5) {
  144.                   ["init"]=>
  145.                   NULL
  146.                   ["contains"]=>
  147.                   string(30) "localhost\illiFW\dev\delTarget"
  148.                   ["isTouched"]=>
  149.                   bool(true)
  150.                   ["flag"]=>
  151.                   int(4)
  152.                   ["typeOf"]=>
  153.                   array(1) {
  154.                     [0]=>
  155.                     string(6) "string"
  156.                   }
  157.                 }
  158.                 ["functionName"]=>
  159.                 array(5) {
  160.                   ["init"]=>
  161.                   NULL
  162.                   ["contains"]=>
  163.                   string(6) "target"
  164.                   ["isTouched"]=>
  165.                   bool(true)
  166.                   ["flag"]=>
  167.                   int(4)
  168.                   ["typeOf"]=>
  169.                   array(1) {
  170.                     [0]=>
  171.                     string(6) "string"
  172.                   }
  173.                 }
  174.                 ["strictArguments"]=>
  175.                 array(5) {
  176.                   ["init"]=>
  177.                   bool(true)
  178.                   ["contains"]=>
  179.                   bool(true)
  180.                   ["isTouched"]=>
  181.                   bool(false)
  182.                   ["flag"]=>
  183.                   int(0)
  184.                   ["typeOf"]=>
  185.                   array(1) {
  186.                     [0]=>
  187.                     string(7) "boolean"
  188.                   }
  189.                 }
  190.                 ["defaultArguments"]=>
  191.                 array(5) {
  192.                   ["init"]=>
  193.                   array(0) {
  194.                   }
  195.                   ["contains"]=>
  196.                   array(0) {
  197.                   }
  198.                   ["isTouched"]=>
  199.                   bool(false)
  200.                   ["flag"]=>
  201.                   int(0)
  202.                   ["typeOf"]=>
  203.                   array(1) {
  204.                     [0]=>
  205.                     string(5) "array"
  206.                   }
  207.                 }
  208.                 ["Context"]=>
  209.                 array(5) {
  210.                   ["init"]=>
  211.                   NULL
  212.                   ["contains"]=>
  213.                   object(localhost\illiFW\dev\delTarget)#19 (0) {
  214.                  }
  215.                   ["isTouched"]=>
  216.                   bool(true)
  217.                   ["flag"]=>
  218.                   int(0)
  219.                   ["typeOf"]=>
  220.                   array(1) {
  221.                     [0]=>
  222.                     string(6) "object"
  223.                   }
  224.                 }
  225.                 ["ContextConstructor"]=>
  226.                 array(5) {
  227.                   ["init"]=>
  228.                   NULL
  229.                   ["contains"]=>
  230.                   NULL
  231.                   ["isTouched"]=>
  232.                   bool(false)
  233.                   ["flag"]=>
  234.                   int(0)
  235.                   ["typeOf"]=>
  236.                   array(1) {
  237.                     [0]=>
  238.                     string(39) "ILLI\Base\Component\Invoke\sConstructor"
  239.                   }
  240.                 }
  241.                 ["contextArguments"]=>
  242.                 array(5) {
  243.                   ["init"]=>
  244.                   array(0) {
  245.                   }
  246.                   ["contains"]=>
  247.                   array(0) {
  248.                   }
  249.                   ["isTouched"]=>
  250.                   bool(false)
  251.                   ["flag"]=>
  252.                   int(0)
  253.                   ["typeOf"]=>
  254.                   array(1) {
  255.                     [0]=>
  256.                     string(5) "array"
  257.                   }
  258.                 }
  259.                 ["methodName"]=>
  260.                 array(6) {
  261.                   ["init"]=>
  262.                   NULL
  263.                   ["contains"]=>
  264.                   NULL
  265.                   ["isTouched"]=>
  266.                   bool(false)
  267.                   ["flag"]=>
  268.                   int(10)
  269.                   ["typeOf"]=>
  270.                   array(1) {
  271.                     [0]=>
  272.                     string(6) "string"
  273.                   }
  274.                   ["onGet"]=>
  275.                   array(1) {
  276.                     [0]=>
  277.                     object(Closure)#29 (1) {
  278.                      ["this"]=>
  279.                       *RECURSION*
  280.                     }
  281.                   }
  282.                 }
  283.                 ["methodArray"]=>
  284.                 array(6) {
  285.                   ["init"]=>
  286.                   array(0) {
  287.                   }
  288.                   ["contains"]=>
  289.                   array(0) {
  290.                   }
  291.                   ["isTouched"]=>
  292.                   bool(false)
  293.                   ["flag"]=>
  294.                   int(10)
  295.                   ["typeOf"]=>
  296.                   array(1) {
  297.                     [0]=>
  298.                     string(5) "array"
  299.                   }
  300.                   ["onGet"]=>
  301.                   array(1) {
  302.                     [0]=>
  303.                     object(Closure)#30 (1) {
  304.                      ["this"]=>
  305.                       *RECURSION*
  306.                     }
  307.                   }
  308.                 }
  309.               }
  310.               ["__tStructure_Locked":protected]=>
  311.               bool(false)
  312.               ["__tStructure_MemberFieldValid":protected]=>
  313.               bool(false)
  314.             }
  315.             ["__parameters":protected]=>
  316.             array(1) {
  317.               ["__world"]=>
  318.               string(2) "Hi"
  319.             }
  320.             ["__result":protected]=>
  321.             NULL
  322.           }
  323.           ["isTouched"]=>
  324.           bool(true)
  325.           ["flag"]=>
  326.           int(4)
  327.           ["typeOf"]=>
  328.           array(1) {
  329.             [0]=>
  330.             string(44) "ILLI\Base\Component\Delegate\aMethodDelegate"
  331.           }
  332.         }
  333.       }
  334.       ["__tStructure_Locked":protected]=>
  335.       bool(false)
  336.       ["__tStructure_MemberFieldValid":protected]=>
  337.       bool(false)
  338.     }
  339.   }
  340.   ["__tSignalHook_hook":protected]=>
  341.   array(0) {
  342.   }
  343.   ["__tSignalHook_results":protected]=>
  344.   array(0) {
  345.   }
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement