Ubiquity  2.0.2
php rapid development framework
DocFormater.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class DocFormater {
6  protected $types=["boolean","string","int","mixed","array"];
7  protected $replacements=["types"=>"<span style='font-weight:bold;color: green;'>$1</span>","variables"=>"<span style='font-weight:bold;color: brown;'>$1</span>"];
8  public function __construct(){
9 
10  }
11 
12  public function getReplacement($part){
13  return $this->replacements[$part];
14  }
15 
16  protected function getTypesRegex(){
17  $items=\array_map(function($item){ return "(".$item.")";}, $this->types);
18  return '^('.\implode('|', $items).').*?';
19  }
20 
21  protected function getVariablesRegex(){
22  return '(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)';
23  }
24 
25  protected function _replaceAll($search,$replacement,$subject){
26  return \preg_replace('@'.$search.'@i', $replacement, $subject);
27  }
28 
29  public function replaceTypes($str){
30  return $this->_replaceAll($this->getTypesRegex(), $this->replacements["types"], $str);
31  }
32 
33  public function replaceVariables($str){
34  return $this->_replaceAll($this->getVariablesRegex(), $this->replacements["variables"], $str);
35  }
36 
37  public function replaceAll($str){
38  $str=$this->replaceTypes($str);
39  return $this->replaceVariables($str);
40  }
41 }
_replaceAll($search, $replacement, $subject)
Definition: DocFormater.php:25