Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.87 KB | None | 0 0
  1. <?php
  2. class Manual {
  3.  
  4.     private $smarty;
  5.     private $className = null;
  6.     private $prodClass = null;
  7.  
  8.     public function  __construct()
  9.     {
  10.         $this->smarty = new Smarty;
  11.         $this->smarty->compile_check = true;
  12.         $this->smarty->debugging = false;
  13.         $this->smarty->caching = false;
  14.         $this->smarty->template_dir = './tpl/' . LANGUAGE . '/' . DESIGN . '/manual/';
  15.         $this->smarty->compile_dir = './tpl/' . LANGUAGE . '/' . DESIGN . '/compiled/';
  16.         $this->smarty->config_dir = './configs/';
  17.         $this->smarty->cache_dir = './cache/';
  18.     }
  19.  
  20.     private function getMethods($manual) {
  21.         $methods = $this->prodClass->getMethods();
  22.         $return = null;
  23.  
  24.         if($manual == true) {
  25.             foreach($methods as $method) {
  26.                 $fileExsists = file_exists('./tpl/' . LANGUAGE . '/' . DESIGN . '/manual/' . 'template.'.$this->className.'.tpl');
  27.                 $this->smarty->assign('method', $method->getName());
  28.  
  29.                 $return .= "<a name='".$method->getName()."'><h3>" . $method->getName() . "</h3></a><br />";
  30.                
  31.                 if($fileExsists)
  32.                    $return .= $this->smarty->fetch('template.'.$this->className.'.tpl') . "<br /><br />";
  33.                 else
  34.                    $return .= "Es ist kein Manual f&uuml;r diese Klasse angelegt!<br /><br />";
  35.             }
  36.         }else{
  37.             foreach($methods as $method) {
  38.                 $parametersReturn = null;
  39.                 $parameters = $method->getParameters();
  40.  
  41.                 if($method->isStatic() == true) $return .= "static ";
  42.                 if($method->isPublic() == true) $return .= "public ";
  43.                 if($method->isProtected() == true) $return .= "protected ";
  44.                 if($method->isPrivate() == true) $return .= "private ";
  45.  
  46.                 foreach($parameters as $param) {
  47.                     if($param->isOptional() == true)
  48.                     {
  49.                         $parametersReturn = substr($parametersReturn, 0, -2);
  50.  
  51.                         if($param->isDefaultValueAvailable() == true) {
  52.                             $default = ($param->getDefaultValue()) ? $param->getDefaultValue() : "''";
  53.                             $parametersReturn .= ' [, $' . $param->getName() . ' = ' . $default . '] , ';
  54.                         }else
  55.                             $parametersReturn .= ' [, $' . $param->getName() . ' ] , ';
  56.                     }else{
  57.                         if($param->isDefaultValueAvailable() == true)
  58.                             $parametersReturn .= '$' . $param->getName() . ' = \'' . $param->getDefaultValue() . '\'';
  59.                         else
  60.                             $parametersReturn .= '$' . $param->getName() . ', ';
  61.                     }
  62.                 }
  63.                 $parametersReturn = substr($parametersReturn, 0, -2);
  64.                 $return .= "<a href='#".$method->getName()."'>" . $method->getName() . " ( ".$parametersReturn." )</a> <br />";
  65.             }
  66.         }
  67.         return $return;
  68.     }
  69.  
  70.     private function getVariables() {
  71.         $variablesReturn = null;
  72.         $vars = $this->prodClass->getProperties();
  73.  
  74.         foreach($vars as $var) {
  75.             if($var->isStatic() == true) $variablesReturn .= "static ";
  76.             if($var->isPublic() == true) $variablesReturn .= "public ";
  77.             if($var->isProtected() == true) $variablesReturn .= "protected ";
  78.             if($var->isPrivate() == true) $variablesReturn .= "private ";
  79.  
  80.             $variablesReturn .= $var->getName() . " = '" . @$var->getValue() . "';<br />";
  81.         }
  82.         return $variablesReturn;
  83.     }
  84.  
  85.     private function getConstants() {
  86.         $constantsReturn = null;
  87.         $consts = $this->prodClass->getConstants();
  88.  
  89.         foreach($consts as $name => $constant)
  90.             $constantsReturn .= $name . " = '" . $constant . "';<br />";
  91.         return $constantsReturn;
  92.     }
  93.  
  94.     public function __call($name, $arguments) {
  95.         $output = null;
  96.         $class = null;
  97.        
  98.         $this->className = $arguments[0];
  99.         $this->prodClass = new ReflectionClass($this->className);
  100.  
  101.         if($this->prodClass->isAbstract()) $class .= "abstract, ";
  102.         if($this->prodClass->isFinal()) $class .= "final, ";
  103.         $class = substr($class, 0, -2);
  104.        
  105.         $output .= "<b>Die Klasse <i>" . $this->className . "</i> (ist) <i>" . $class . "</i> und hat folgende Methoden:</b><br /><br />";
  106.         $output .= $this->getMethods(false);
  107.         $output .= "<br /><b>und folgende Variablen:</b><br /><br />";
  108.         $output .= $this->getVariables();
  109.         $output .= "<br /><b>und folgende Konstanten:</b><br /><br />";
  110.         $output .= $this->getConstants();
  111.         $output .= "<br /><b>Manual zu der Klasse:</b><br /><br />";
  112.         $output .= $this->getMethods(true);
  113.         die($output);
  114.     }
  115. }
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement