nyroFwk  0.2
nReflection.class.php
Go to the documentation of this file.
1 <?php
10 class nReflection extends ReflectionClass {
11 
17  public function __construct($elt='object') {
18  if (is_object($elt))
19  $this->rebuild(get_class($elt));
20  else if ($elt)
21  $this->rebuild($elt);
22  }
23 
30  public function rebuild($name) {
31  try {
32  parent::__construct($name);
33  return true;
34  } catch(Exception $e) {
35  return false;
36  }
37  }
38 
45  public function newInstanceCfg(config $cfg) {
46  return parent::newInstance($cfg);
47  }
48 
55  public function isSubclassOf($className) {
56  return parent::isSubclassOf(new nReflection($className));
57  }
58 
64  public function getPublicProperties() {
65  $publicProps = array();
66 
67  $props = $this->getProperties();
68  foreach($props as $p) {
69  if ($p->isPublic())
70  $publicProps[] = $p->getName();
71  }
72 
73  return $publicProps;
74  }
75 
84  public static function getParentsClass($className) {
85  return class_parents($className);
86  }
87 
97  public static function callMethod($object, $function, $args=array()) {
98  $ref = new nReflection($object);
99  if ($ref->hasMethod($function)
100  && ($meth = $ref->getMethod($function))
101  && $meth->isPublic()) {
102  if (!is_array($args)) {
103  if (!empty($args))
104  $args = array($args);
105  else
106  $args = array();
107  }
108  return $meth->invokeArgs($object, $args);
109  }
110  throw new nException('Method not callable');
111  }
112 
113 }
static getParentsClass($className)
newInstanceCfg(config $cfg)
static callMethod($object, $function, $args=array())
__construct($elt='object')
isSubclassOf($className)
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13