- Timestamp:
- 09/17/08 13:55:47 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/php/misc/Hermit/src/Hermit/annote/HermitAnnoteConst.php
r18954 r19426 10 10 const QUERY_SUFFIX = '_QUERY'; 11 11 const FILE_SUFFIX = '_FILE'; 12 const P ATH_SUFFIX = '_PATH';12 const PROCEDURE_SUFFIX = '_PROCEDURE'; 13 13 const DELEGATE_SUFFIX = '_DELEGATE'; 14 14 15 const UNDERSCORE = '_'; 16 const SQL_FILE_EXTENSION = '.sql'; 17 18 const PROCEDURE_NAMES = '/^(proc|call)/i'; 19 const INSERT_NAMES = '/^(insert|create|add)/i'; 20 const UPDATE_NAMES = '/^(update|modify|store)/i'; 21 const DELETE_NAMES = '/^(delete|remove)/i'; 22 15 23 protected $reflector; 16 p rotectedfunction __construct(ReflectionClass $reflector){24 public function __construct(ReflectionClass $reflector){ 17 25 $this->reflector = $reflector; 18 26 } 19 protected static function createFilePath($pathOfClass, $suffix){ 20 return dirname($pathOfClass) . '_' . $suffix . '.sql'; 27 protected static function underscore(){ 28 $args = func_get_args(); 29 $buf = ''; 30 foreach($args as $arg){ 31 $buf .= $arg; 32 $buf .= self::UNDERSCORE; 33 } 34 return substr($buf, 0, -1); 21 35 } 22 36 public function getTable(){ … … 39 53 return $this->reflector->getMethod($name); 40 54 } 41 public function hasSql($name){42 return $this->reflector->hasConstant($name . self::SQL_SUFFIX);55 public function isProcedureMethod(ReflectionMethod $method){ 56 return 1 === preg_match(self::PROCEDURE_NAMES, $method->getName()); 43 57 } 44 public function getSql($name, $instance = null){45 return $this->reflector->getConstant($name . self::SQL_SUFFIX);58 public function isInsertMethod(ReflectionMethod $method){ 59 return 1 === preg_match(self::INSERT_NAMES, $method->getName()); 46 60 } 47 public function hasQuery($name){48 return $this->reflector->hasConstant($name . self::QUERY_SUFFIX);61 public function isUpdateMethod(ReflectionMethod $method){ 62 return 1 === preg_match(self::UPDATE_NAMES, $method->getName()); 49 63 } 50 public function getQuery($name, $instance = null){51 return $this->reflector->getConstant($name . self::QUERY_SUFFIX);64 public function isDeleteMethod(ReflectionMethod $method){ 65 return 1 === preg_match(self::DELETE_NAMES, $method->getName()); 52 66 } 53 public function hasFile($name){ 54 if(!$this->reflector->hasConstant($name . self::FILE_SUFFIX)){ 55 return false; 67 public function getProcedure(ReflectionMethod $method){ 68 $key = $method->getName . self::PROCEDURE_SUFFIX; 69 if($this->reflector->hasConstant($key)){ 70 return $this->reflector->getConstant($key); 56 71 } 57 return file_exists(self::createFilePath($this->reflector->getFileName(), $name));72 return null; 58 73 } 59 public function getFile($name, $instance = null){ 60 $path = self::createFilePath($this->reflector->getFileName(), $name); 61 return file_get_contents($path); 74 public function getSql(ReflectionMethod $method, $suffix = null){ 75 if(is_null($suffix)){ 76 $suffix = ''; 77 } 78 $methodName = $method->getName(); 79 $key1 = $methodName . self::UNDERSCORE . $suffix . self::SQL_SUFFIX; 80 if($this->reflector->hasConstant($key1)){ 81 return $this->reflector->getConstant($key1); 82 } 83 $key2 = $methodName . self::SQL_SUFFIX; 84 if($this->reflector->hasConstant($key2)){ 85 return $this->reflector->getConstant($key2); 86 } 87 88 $fileName = $this->reflector->getFileName(); 89 $className = $this->reflector->getName(); 90 $dirPath = dirname($fileName) . DIRECTORY_SEPARATOR; 91 $key3 = $dirPath . self::underscore($className, $methodName, $suffix) . self::SQL_FILE_EXTENSION; 92 if(file_exists($key3)){ 93 return file_get_contents($key3); 94 } 95 $key4 = $dirPath . self::underscore($className, $methodName) . self::SQL_FILE_EXTENSION; 96 if(file_exists($key4)){ 97 return file_get_contents($key4); 98 } 99 return null; 62 100 } 63 public function hasPath($name){ 64 if(!$this->reflector->hasConstant($name . self::PATH_SUFFIX)){ 65 return false; 101 public function getQuery(ReflectionMethod $method){ 102 $key = $method->getName() . self::QUERY_SUFFIX; 103 if($this->reflector->hasConstant($key)){ 104 return $this->reflector->getConstant($key); 66 105 } 67 return file_exists($this->getPath($name));106 return null; 68 107 } 69 public function getPath($name, $instance = null){ 70 return file_get_contents($this->reflector->getConstant($name . self::PATH_SUFFIX)); 108 public function getFile(ReflectionMethod $method){ 109 $key = $method->getName() . self::FILE_SUFFIX; 110 if($this->reflector->hasConstant($key)){ 111 $path = $this->reflector->getConstant($key); 112 if(file_exists($path)){ 113 return file_get_contents($path); 114 } 115 } 116 return null; 71 117 } 72 public function hasDelegate($name){ 73 return $this->reflector->hasConstant($name . self::DELEGATE_SUFFIX); 74 } 75 public function getDelegate($name, $instance = null){ 118 public function getDelegate(ReflectionMethod $method){ 76 119 return $this->reflector->getConstant($name . self::DELEGATE_SUFFIX); 77 120 } 78 121 } 122
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)