Ubiquity  2.0.0
php rapid development framework
Introspection.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ubiquity\utils;
4 
5 class Introspection {
6 
7  public static function getClassCode($classname){
8  $r = new \ReflectionClass($classname);
9  $lines = file($r->getFileName());
10  return $lines;
11  }
12 
13  public static function getLoadedViews(\ReflectionMethod $r,$lines){
14  $matches=[];
15  $code=self::getMethodCode($r,$lines);
16  \preg_match_all('@(?:.*?)\$this\->loadView\([\'\"](.+?)[\'\"](?:.*?)@s', $code,$matches);
17  if (isset($matches[1])) {
18  return $matches[1];
19  }
20  return [];
21  }
22 
23  public static function getMethodCode(\ReflectionMethod $r,$lines){
24  $str="";
25  $count=\sizeof($lines);
26  $sLine=$r->getStartLine();$eLine=$r->getEndLine();
27  if($sLine==$eLine)
28  return $lines[$sLine];
29  for($l = $sLine; $l < min($eLine,$count); $l++) {
30  $str .= $lines[$l];
31  }
32  return $str;
33  }
34 
35  public static function closure_dump(\Closure $c) {
36  $str = 'function (';
37  $r = new \ReflectionFunction($c);
38  $params = array();
39  foreach($r->getParameters() as $p) {
40  $s = '';
41  if($p->isArray()) {
42  $s .= 'array ';
43  } else if($p->getClass()) {
44  $s .= $p->getClass()->name . ' ';
45  }
46  if($p->isPassedByReference()){
47  $s .= '&';
48  }
49  $s .= '$' . $p->name;
50  if($p->isOptional()) {
51  $s .= ' = ' . \var_export($p->getDefaultValue(), TRUE);
52  }
53  $params []= $s;
54  }
55  $str .= \implode(', ', $params);
56  $str .= '){' . PHP_EOL;
57  $lines = file($r->getFileName());
58  $sLine=$r->getStartLine();$eLine=$r->getEndLine();
59  for($l = $sLine; $l < $eLine; $l++) {
60  $str .= $lines[$l];
61  }
62  return $str;
63  }
64 }
static getMethodCode(\ReflectionMethod $r, $lines)
static closure_dump(\Closure $c)
static getClassCode($classname)
static getLoadedViews(\ReflectionMethod $r, $lines)