[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/AkReflection/ -> AkReflectionFunction.php (source)

   1  <?php
   2  require_once (AK_LIB_DIR.DS.'AkReflection.php');
   3  require_once (AK_LIB_DIR.DS.'AkReflection'.DS.'AkReflectionDocBlock.php');
   4  
   5  class AkReflectionFunction extends AkReflection
   6  {
   7      var $_definition;
   8      var $_docBlock;
   9      var $methods = array();
  10      var $properties = array();
  11      
  12      
  13      
  14      function AkReflectionFunction($method_definition)
  15      {
  16          if (is_array($method_definition)) {
  17              if (@$method_definition['type'] == 'function') {
  18                  $this->_definition = $method_definition;
  19              } else {
  20                  return;
  21              }
  22          } else if (is_string($method_definition)) {
  23              $this->_parse($method_definition);
  24              foreach ($this->definitions as $def) {
  25                  if ($def['type'] == 'function') {
  26                      $this->_definition = $def;
  27                      break;
  28                  }
  29              }
  30              $this->definitions = array();
  31              $this->tokens = array();
  32          } else {
  33              return;
  34          }
  35          $this->_docBlock = &new AkReflectionDocBlock($this->_definition['docBlock']);
  36          $this->_parse($this->_definition['code']);
  37          $this->_parseDefinitions();
  38          
  39      }
  40      
  41      
  42      function getDefaultOptions()
  43      {
  44          return isset($this->_definition['default_options'])?$this->_definition['default_options']:false;
  45      }
  46      
  47      function getAvailableOptions()
  48      {
  49          return isset($this->_definition['available_options'])?$this->_definition['available_options']:false;
  50      }
  51      function getName()
  52      {
  53          return isset($this->_definition['name'])?$this->_definition['name']:false;
  54      }
  55      function setTag($tag,$value)
  56      {
  57          if (!is_object($this->_docBlock)) {
  58              $this->_docBlock = new AkReflectionDocBlock('');
  59          }
  60          $this->_docBlock->setTag($tag,$value);
  61      }
  62      function getTag($tag)
  63      {
  64          return $this->_docBlock->getTag($tag);
  65      }
  66      function getParams()
  67      {
  68          return isset($this->_definition['params'])?$this->_definition['params']:false;
  69      }
  70      function toString($indent=0,$methodName = null)
  71      {
  72          $docBlock = &$this->_docBlock;
  73          if ($docBlock->changed) {
  74              $string = $this->_definition['toString'];
  75              $orgDocBlock = trim($docBlock->original);
  76              if (!empty($orgDocBlock)) {
  77                  $string = str_replace($orgDocBlock,$docBlock->toString(),$string);
  78              } else {
  79                  $string = $docBlock->toString()."\n".$string;
  80              }
  81          } else {
  82              $string=isset($this->_definition['toString'])?$this->_definition['toString']:null;
  83          }
  84          if ($indent>0) {
  85              $lines = split("\n",$string);
  86              foreach ($lines as $idx=>$line) {
  87                  $lines[$idx] = str_repeat(' ',$indent).$line;
  88              }
  89              $string = implode("\n",$lines);
  90          } 
  91          if ($methodName!=null) {
  92              $string = preg_replace('/function(.*?)('.$this->getName().')(.*?)\(/','function\\1'.$methodName.'\\3(',$string);
  93          }
  94          return $string;
  95          
  96      }
  97      function returnByReference()
  98      {
  99          return isset($this->_definition['returnByReference'])?$this->_definition['returnByReference']:false;
 100      }
 101      
 102      function &getDocBlock()
 103      {
 104          return $this->_docBlock;
 105      }
 106      function _parseDefinitions()
 107      {
 108          foreach($this->definitions as $definition) {
 109              switch ($definition['type']) {
 110                  case 'function':
 111                      $this->methods[] = new AkReflectionMethod($definition);
 112                      break;
 113              }
 114          }
 115      }
 116      
 117  
 118  }
 119  ?>


Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6