Kod klas jest jeszcze w fazie beta, więc zamieszczam przykład ich użycia.
Co myślicie o takim rozszerzaniu metod i pól klas?
  1. <?php
  2. class fooBar
  3. {
  4. public function test( $text )
  5. {
  6. echo $text."n";
  7. }
  8. }
  9.  
  10. class fooBar1Extention extends oeExtention 
  11. {
  12. public function test( oeExtendable $extendable, $text )
  13. {
  14. return oeResponse::give(OE_ORIGINAL)->with('Noting to lose.');
  15. // Returns original method with first parameter:
  16. // 'Noting to lose.'
  17. }
  18. }
  19.  
  20. class fooBar2Extention extends oeExtention 
  21. {
  22. public function test( oeExtendable $extendable, $text )
  23. {
  24. if( is_numeric($text) )
  25. {
  26. echo '['.$text.']';
  27. return oeResponse::give(OE_SKIP)->with(null);
  28. // Returns null, and not skipping call original method.
  29. // You can use that too:
  30. // return null;
  31. // for not creating oeResponse object and faster compilation.
  32. }
  33. return oeResponse::give(OE_ORIGINAL);
  34. // Returns result of original method. You can use that too:
  35. // return false;
  36. // as alternative method.
  37. }
  38. }
  39.  
  40. class fooBar3Extention extends oeExtention
  41. {
  42. public function test( oeExtendable $extendable, $text )
  43. {
  44. if( is_numeric($text) )
  45. {
  46. return oeResponse::give(OE_ORIGINAL);
  47. // Returns result of original method.
  48. }
  49. return oeResponse::give(OE_ORIGINAL)->with('I dont work with non numeric values.');
  50. // Returns original method with first parameter:
  51. // 'I dont work with numeric values.'
  52. }
  53. }
  54.  
  55. $foo = oeExtendable::instance( new fooBar() );
  56. $foo->test(13);
  57. $foo->test('Hello World!');
  58.  
  59. echo "___FOOBAR1___n";
  60. $foo->__extend( new fooBar1Extention() );
  61. $foo->test(13);
  62. $foo->test('Hello World!');
  63.  
  64. echo "___FOOBAR2___n";
  65. $foo->__extend( new fooBar2Extention() );
  66. $foo->test(13);
  67. $foo->test('Hello World!');
  68.  
  69. echo "___FOOBAR3___n";
  70. $foo->__extend( new fooBar3Extention() );
  71. $foo->test(13);
  72. $foo->test('Hello World!');
  73. ?>
Co daje w rezultacie wyświetlenie:
Cytat
13
Hello World!
___FOOBAR1___
Noting to lose.
Noting to lose.
___FOOBAR2___
[13]Hello World!
___FOOBAR3___
13
I dont work with numeric values.