Source for file PresenterComponentReflection.php

Documentation is available at PresenterComponentReflection.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette\Application
  11. 11:  */
  12. 12:  
  13. 13:  
  14. 14:  
  15. 15: /**
  16. 16:  * Helpers for Presenter & PresenterComponent.
  17. 17:  *
  18. 18:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  19. 19:  * @package    Nette\Application
  20. 20:  * @ignore internal
  21. 21:  */
  22. 22: class PresenterComponentReflection extends ClassReflection
  23. 23: {
  24. 24:     /** @var array getPersistentParams cache */
  25. 25:     private static $ppCache array();
  26. 26:  
  27. 27:     /** @var array getPersistentComponents cache */
  28. 28:     private static $pcCache array();
  29. 29:  
  30. 30:     /** @var array isMethodCallable cache */
  31. 31:     private static $mcCache array();
  32. 32:  
  33. 33:  
  34. 34:  
  35. 35:     /**
  36. 36:      * @return array of persistent parameters.
  37. 37:      */
  38. 38:     public function getPersistentParams($class NULL)
  39. 39:     {
  40. 40:         $class $class === NULL $this->getName($class// TODO
  41. 41:         $params self::$ppCache[$class];
  42. 42:         if ($params !== NULLreturn $params;
  43. 43:         $params array();
  44. 44:         if (is_subclass_of($class'PresenterComponent')) {
  45. 45:             // $class::getPersistentParams() in PHP 5.3
  46. 46:             $defaults get_class_vars($class);
  47. 47:             foreach (call_user_func(array($class'getPersistentParams')$classas $name => $meta{
  48. 48:                 if (is_string($meta)) $name $meta;
  49. 49:                 $params[$namearray(
  50. 50:                     'def' => $defaults[$name],
  51. 51:                     'since' => $class,
  52. 52:                 );
  53. 53:             }
  54. 54:             $params $this->getPersistentParams(get_parent_class($class)) $params// TODO
  55. 55:         }
  56. 56:         return $params;
  57. 57:     }
  58. 58:  
  59. 59:  
  60. 60:  
  61. 61:     /**
  62. 62:      * @return array of persistent components.
  63. 63:      */
  64. 64:     public function getPersistentComponents()
  65. 65:     {
  66. 66:         $class $this->getName();
  67. 67:         $components self::$pcCache[$class];
  68. 68:         if ($components !== NULLreturn $components;
  69. 69:         $components array();
  70. 70:         if (is_subclass_of($class'Presenter')) {
  71. 71:             // $class::getPersistentComponents() in PHP 5.3
  72. 72:             foreach (call_user_func(array($class'getPersistentComponents')$classas $name => $meta{
  73. 73:                 if (is_string($meta)) $name $meta;
  74. 74:                 $components[$namearray('since' => $class);
  75. 75:             }
  76. 76:             $components self::getPersistentComponents(get_parent_class($class)) $components;
  77. 77:         }
  78. 78:         return $components;
  79. 79:     }
  80. 80:  
  81. 81:  
  82. 82:  
  83. 83:     /**
  84. 84:      * Is a method callable? It means class is instantiable and method has
  85. 85:      * public visibility, is non-static and non-abstract.
  86. 86:      * @param  string  method name
  87. 87:      * @return bool 
  88. 88:      */
  89. 89:     public function hasCallableMethod($method)
  90. 90:     {
  91. 91:         $class $this->getName();
  92. 92:         $cache self::$mcCache[strtolower($class ':' $method)];
  93. 93:         if ($cache === NULLtry {
  94. 94:             $cache FALSE;
  95. 95:             $rm MethodReflection::from($class$method);
  96. 96:             $cache $this->isInstantiable(&& $rm->isPublic(&& !$rm->isAbstract(&& !$rm->isStatic();
  97. 97:         catch (ReflectionException $e{
  98. 98:         }
  99. 99:         return $cache;
  100. 100:     }
  101. 101: