@@ -20,18 +20,18 @@ |
||
20 | 20 | { |
21 | 21 | private $_statement; |
22 | 22 | private $_preparedStatement; |
23 | - private $_parameterPrefix = 'param'; |
|
23 | + private $_parameterPrefix='param'; |
|
24 | 24 | private $_commandText; |
25 | 25 | |
26 | 26 | public function __construct($statement, $sqlString) |
27 | 27 | { |
28 | - $this->_statement = $statement; |
|
29 | - $this->_commandText = $sqlString; |
|
28 | + $this->_statement=$statement; |
|
29 | + $this->_commandText=$sqlString; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function prepare() |
33 | 33 | { |
34 | - $this->_preparedStatement = new TPreparedStatement(); |
|
34 | + $this->_preparedStatement=new TPreparedStatement(); |
|
35 | 35 | $this->_preparedStatement->setPreparedSql($this->_commandText); |
36 | 36 | if($this->_statement->parameterMap()!==null) |
37 | 37 | $this->createParametersForTextCommand(); |
@@ -22,33 +22,33 @@ |
||
22 | 22 | private $_parameterNames; |
23 | 23 | private $_parameterValues; |
24 | 24 | |
25 | - public function getPreparedSql(){ return $this->_sqlString; } |
|
26 | - public function setPreparedSql($value){ $this->_sqlString = $value; } |
|
25 | + public function getPreparedSql() { return $this->_sqlString; } |
|
26 | + public function setPreparedSql($value) { $this->_sqlString=$value; } |
|
27 | 27 | |
28 | - public function getParameterNames($needed = true) |
|
28 | + public function getParameterNames($needed=true) |
|
29 | 29 | { |
30 | - if (!$this->_parameterNames and $needed) |
|
31 | - $this->_parameterNames = new TList; |
|
30 | + if(!$this->_parameterNames and $needed) |
|
31 | + $this->_parameterNames=new TList; |
|
32 | 32 | return $this->_parameterNames; |
33 | 33 | } |
34 | 34 | |
35 | - public function setParameterNames($value){ $this->_parameterNames = $value; } |
|
35 | + public function setParameterNames($value) { $this->_parameterNames=$value; } |
|
36 | 36 | |
37 | - public function getParameterValues($needed = true) |
|
37 | + public function getParameterValues($needed=true) |
|
38 | 38 | { |
39 | - if (!$this->_parameterValues and $needed) |
|
39 | + if(!$this->_parameterValues and $needed) |
|
40 | 40 | $this->_parameterValues=new TMap; |
41 | 41 | return $this->_parameterValues; |
42 | 42 | } |
43 | 43 | |
44 | - public function setParameterValues($value){ $this->_parameterValues = $value; } |
|
44 | + public function setParameterValues($value) { $this->_parameterValues=$value; } |
|
45 | 45 | |
46 | 46 | public function __sleep() |
47 | 47 | { |
48 | - $exprops = array(); $cn = __CLASS__; |
|
49 | - if (!$this->_parameterNames or !$this->_parameterNames->getCount()) $exprops[] = "\0$cn\0_parameterNames"; |
|
50 | - if (!$this->_parameterValues or !$this->_parameterValues->getCount()) $exprops[] = "\0$cn\0_parameterValues"; |
|
51 | - return array_diff(parent::__sleep(),$exprops); |
|
48 | + $exprops=array(); $cn=__CLASS__; |
|
49 | + if(!$this->_parameterNames or !$this->_parameterNames->getCount()) $exprops[]="\0$cn\0_parameterNames"; |
|
50 | + if(!$this->_parameterValues or !$this->_parameterValues->getCount()) $exprops[]="\0$cn\0_parameterValues"; |
|
51 | + return array_diff(parent::__sleep(), $exprops); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 |
@@ -22,8 +22,8 @@ |
||
22 | 22 | |
23 | 23 | public function buildPreparedStatement($statement, $sqlString) |
24 | 24 | { |
25 | - $factory = new TPreparedStatementFactory($statement, $sqlString); |
|
26 | - $this->_preparedStatement = $factory->prepare(); |
|
25 | + $factory=new TPreparedStatementFactory($statement, $sqlString); |
|
26 | + $this->_preparedStatement=$factory->prepare(); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function getPreparedStatement($parameter=null) |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function registerTypeHandler(TSqlMapTypeHandler $handler) |
49 | 49 | { |
50 | - $this->_typeHandlers[$handler->getType()] = $handler; |
|
50 | + $this->_typeHandlers[$handler->getType()]=$handler; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | switch(strtolower($type)) |
91 | 91 | { |
92 | 92 | case 'integer': case 'int': |
93 | - $type = 'integer'; break; |
|
93 | + $type='integer'; break; |
|
94 | 94 | case 'float': case 'double': case 'decimal': |
95 | - $type = 'float'; break; |
|
95 | + $type='float'; break; |
|
96 | 96 | case 'boolean': case 'bool': |
97 | - $type = 'boolean'; break; |
|
97 | + $type='boolean'; break; |
|
98 | 98 | case 'string' : |
99 | - $type = 'string'; break; |
|
99 | + $type='string'; break; |
|
100 | 100 | default: |
101 | 101 | return $value; |
102 | 102 | } |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | array_shift($args); |
23 | 23 | $n=count($args); |
24 | 24 | $tokens=array(); |
25 | - for($i=0;$i<$n;++$i) |
|
25 | + for($i=0; $i < $n; ++$i) |
|
26 | 26 | { |
27 | 27 | if($args[$i] instanceof SimpleXmlElement) |
28 | 28 | $tokens['{'.$i.'}']=$this->implodeNode($args[$i]); |
29 | 29 | else |
30 | 30 | $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]); |
31 | 31 | } |
32 | - parent::__construct(strtr($errorMessage,$tokens)); |
|
32 | + parent::__construct(strtr($errorMessage, $tokens)); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | { |
41 | 41 | $attributes=array(); |
42 | 42 | foreach($node->attributes() as $k=>$v) |
43 | - $attributes[]=$k.'="'.(string)$v.'"'; |
|
44 | - return '<'.$node->getName().' '.implode(' ',$attributes).'>'; |
|
43 | + $attributes[]=$k.'="'.(string) $v.'"'; |
|
44 | + return '<'.$node->getName().' '.implode(' ', $attributes).'>'; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | public function __construct($cacheModel=null) |
28 | 28 | { |
29 | - $this->_cacheModel = $cacheModel; |
|
29 | + $this->_cacheModel=$cacheModel; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | protected function getBaseKeyKeyName() |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | |
37 | 37 | protected function getBaseKey() |
38 | 38 | { |
39 | - $cache = $this->getCache(); |
|
40 | - $keyname = $this->getBaseKeyKeyName(); |
|
41 | - $basekey = $cache->get($keyname); |
|
42 | - if (!$basekey) |
|
39 | + $cache=$this->getCache(); |
|
40 | + $keyname=$this->getBaseKeyKeyName(); |
|
41 | + $basekey=$cache->get($keyname); |
|
42 | + if(!$basekey) |
|
43 | 43 | { |
44 | - $basekey = DxUtil::generateRandomHash(8); |
|
45 | - $cache->set($keyname,$basekey); |
|
44 | + $basekey=DxUtil::generateRandomHash(8); |
|
45 | + $cache->set($keyname, $basekey); |
|
46 | 46 | } |
47 | 47 | return $basekey; |
48 | 48 | } |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | |
65 | 65 | public function get($key) |
66 | 66 | { |
67 | - $result = $this->getCache()->get($this->getCacheKey($key)); |
|
68 | - return $result === false ? null : $result; |
|
67 | + $result=$this->getCache()->get($this->getCacheKey($key)); |
|
68 | + return $result===false ? null : $result; |
|
69 | 69 | } |
70 | 70 | |
71 | - public function set($key, $value,$expire=0,$dependency=null) |
|
71 | + public function set($key, $value, $expire=0, $dependency=null) |
|
72 | 72 | { |
73 | - $this->getCache()->set($this->getCacheKey($key), $value, $expire,$dependency); |
|
73 | + $this->getCache()->set($this->getCacheKey($key), $value, $expire, $dependency); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | protected function getCache() |
77 | 77 | { |
78 | - if (!$this->_cache) |
|
79 | - $this->_cache = Prado::getApplication()->getCache(); |
|
78 | + if(!$this->_cache) |
|
79 | + $this->_cache=Prado::getApplication()->getCache(); |
|
80 | 80 | return $this->_cache; |
81 | 81 | } |
82 | 82 | |
83 | - public function add($id,$value,$expire=0,$dependency=null) |
|
83 | + public function add($id, $value, $expire=0, $dependency=null) |
|
84 | 84 | { |
85 | 85 | throw new TSqlMapException('sqlmap_use_set_to_store_cache'); |
86 | 86 | } |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class TSimpleDynamicParser |
21 | 21 | { |
22 | - const PARAMETER_TOKEN_REGEXP = '/\$([^\$]+)\$/'; |
|
23 | - const DYNAMIC_TOKEN = '`!`'; |
|
22 | + const PARAMETER_TOKEN_REGEXP='/\$([^\$]+)\$/'; |
|
23 | + const DYNAMIC_TOKEN='`!`'; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Parse the sql text for dynamic place holders of the form $name$. |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function parse($sqlText) |
31 | 31 | { |
32 | - $matches = array(); |
|
33 | - $mappings = array(); |
|
32 | + $matches=array(); |
|
33 | + $mappings=array(); |
|
34 | 34 | preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches); |
35 | - for($i = 0, $k=count($matches[1]); $i<$k; $i++) |
|
35 | + for($i=0, $k=count($matches[1]); $i < $k; $i++) |
|
36 | 36 | { |
37 | - $mappings[] = $matches[1][$i]; |
|
38 | - $sqlText = str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText); |
|
37 | + $mappings[]=$matches[1][$i]; |
|
38 | + $sqlText=str_replace($matches[0][$i], self::DYNAMIC_TOKEN, $sqlText); |
|
39 | 39 | } |
40 | 40 | return array('sql'=>$sqlText, 'parameters'=>$mappings); |
41 | 41 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Regular expression for parsing inline parameter maps. |
27 | 27 | */ |
28 | - const PARAMETER_TOKEN_REGEXP = '/#([^#]+)#/'; |
|
28 | + const PARAMETER_TOKEN_REGEXP='/#([^#]+)#/'; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Parse the sql text for inline parameters. |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function parse($sqlText, $scope) |
37 | 37 | { |
38 | - $matches = array(); |
|
39 | - $mappings = array(); |
|
38 | + $matches=array(); |
|
39 | + $mappings=array(); |
|
40 | 40 | preg_match_all(self::PARAMETER_TOKEN_REGEXP, $sqlText, $matches); |
41 | 41 | |
42 | - for($i = 0, $k=count($matches[1]); $i<$k; $i++) |
|
42 | + for($i=0, $k=count($matches[1]); $i < $k; $i++) |
|
43 | 43 | { |
44 | - $mappings[] = $this->parseMapping($matches[1][$i], $scope); |
|
45 | - $sqlText = str_replace($matches[0][$i], '?', $sqlText); |
|
44 | + $mappings[]=$this->parseMapping($matches[1][$i], $scope); |
|
45 | + $sqlText=str_replace($matches[0][$i], '?', $sqlText); |
|
46 | 46 | } |
47 | 47 | return array('sql'=>$sqlText, 'parameters'=>$mappings); |
48 | 48 | } |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | */ |
56 | 56 | protected function parseMapping($token, $scope) |
57 | 57 | { |
58 | - $mapping = new TParameterProperty; |
|
59 | - $properties = explode(',', $token); |
|
58 | + $mapping=new TParameterProperty; |
|
59 | + $properties=explode(',', $token); |
|
60 | 60 | $mapping->setProperty(trim(array_shift($properties))); |
61 | 61 | foreach($properties as $property) |
62 | 62 | { |
63 | - $prop = explode('=',$property); |
|
64 | - $name = trim($prop[0]); $value=trim($prop[1]); |
|
63 | + $prop=explode('=', $property); |
|
64 | + $name=trim($prop[0]); $value=trim($prop[1]); |
|
65 | 65 | if($mapping->canSetProperty($name)) |
66 | 66 | $mapping->{'set'.$name}($value); |
67 | 67 | else |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | if($this->_file===null) |
120 | 120 | $this->_file=$this->getApplication()->getRuntimePath().'/sqlite.cache'; |
121 | 121 | $error=''; |
122 | - if(($this->_db=new SQLiteDatabase($this->_file,0666,$error))===false) |
|
123 | - throw new TConfigurationException('sqlitecache_connection_failed',$error); |
|
122 | + if(($this->_db=new SQLiteDatabase($this->_file, 0666, $error))===false) |
|
123 | + throw new TConfigurationException('sqlitecache_connection_failed', $error); |
|
124 | 124 | if(@$this->_db->query('DELETE FROM '.self::CACHE_TABLE.' WHERE expire<>0 AND expire<'.time())===false) |
125 | 125 | { |
126 | 126 | if($this->_db->query('CREATE TABLE '.self::CACHE_TABLE.' (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)')===false) |
127 | - throw new TConfigurationException('sqlitecache_table_creation_failed',sqlite_error_string(sqlite_last_error())); |
|
127 | + throw new TConfigurationException('sqlitecache_table_creation_failed', sqlite_error_string(sqlite_last_error())); |
|
128 | 128 | } |
129 | 129 | $this->_initialized=true; |
130 | 130 | parent::init($config); |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | { |
148 | 148 | if($this->_initialized) |
149 | 149 | throw new TInvalidOperationException('sqlitecache_dbfile_unchangeable'); |
150 | - else if(($this->_file=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null) |
|
151 | - throw new TConfigurationException('sqlitecache_dbfile_invalid',$value); |
|
150 | + else if(($this->_file=Prado::getPathOfNamespace($value, self::DB_FILE_EXT))===null) |
|
151 | + throw new TConfigurationException('sqlitecache_dbfile_invalid', $value); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
176 | 176 | * @return boolean true if the value is successfully stored into cache, false otherwise |
177 | 177 | */ |
178 | - protected function setValue($key,$value,$expire) |
|
178 | + protected function setValue($key, $value, $expire) |
|
179 | 179 | { |
180 | - $expire=($expire<=0)?0:time()+$expire; |
|
180 | + $expire=($expire <= 0) ? 0 : time() + $expire; |
|
181 | 181 | $sql='REPLACE INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(serialize($value)).'\','.$expire.')'; |
182 | 182 | return $this->_db->query($sql)!==false; |
183 | 183 | } |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
192 | 192 | * @return boolean true if the value is successfully stored into cache, false otherwise |
193 | 193 | */ |
194 | - protected function addValue($key,$value,$expire) |
|
194 | + protected function addValue($key, $value, $expire) |
|
195 | 195 | { |
196 | - $expire=($expire<=0)?0:time()+$expire; |
|
196 | + $expire=($expire <= 0) ? 0 : time() + $expire; |
|
197 | 197 | $sql='INSERT INTO '.self::CACHE_TABLE.' VALUES(\''.$key.'\',\''.sqlite_escape_string(serialize($value)).'\','.$expire.')'; |
198 | 198 | return @$this->_db->query($sql)!==false; |
199 | 199 | } |