@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class THttpUtility |
20 | 20 | { |
21 | - private static $_encodeTable=array('<'=>'<','>'=>'>','"'=>'"'); |
|
22 | - private static $_decodeTable=array('<'=>'<','>'=>'>','"'=>'"'); |
|
23 | - private static $_stripTable=array('<'=>'','>'=>'','"'=>''); |
|
21 | + private static $_encodeTable=array('<'=>'<', '>'=>'>', '"'=>'"'); |
|
22 | + private static $_decodeTable=array('<'=>'<', '>'=>'>', '"'=>'"'); |
|
23 | + private static $_stripTable=array('<'=>'', '>'=>'', '"'=>''); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * HTML-encodes a string. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function htmlEncode($s) |
34 | 34 | { |
35 | - return strtr($s,self::$_encodeTable); |
|
35 | + return strtr($s, self::$_encodeTable); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function htmlDecode($s) |
45 | 45 | { |
46 | - return strtr($s,self::$_decodeTable); |
|
46 | + return strtr($s, self::$_decodeTable); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function htmlStrip($s) |
56 | 56 | { |
57 | - return strtr($s,self::$_stripTable); |
|
57 | + return strtr($s, self::$_stripTable); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * the object and method name as string |
45 | 45 | * @param array The array of arguments to the function call chain |
46 | 46 | */ |
47 | - public function addCall($method,$args) |
|
47 | + public function addCall($method, $args) |
|
48 | 48 | { |
49 | - $this->add(array($method,$args)); |
|
49 | + $this->add(array($method, $args)); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | { |
93 | 93 | $args=func_get_args(); |
94 | 94 | if($this->getCount()===0) |
95 | - return isset($args[0])?$args[0]:null; |
|
95 | + return isset($args[0]) ? $args[0] : null; |
|
96 | 96 | |
97 | 97 | if(!$this->_iterator) |
98 | 98 | { |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | do { |
104 | 104 | $handler=$this->_iterator->current(); |
105 | 105 | $this->_iterator->next(); |
106 | - if(is_array($handler[0])&&$handler[0][0] instanceof IClassBehavior) |
|
107 | - array_splice($handler[1],1,count($args),$args); |
|
106 | + if(is_array($handler[0]) && $handler[0][0] instanceof IClassBehavior) |
|
107 | + array_splice($handler[1], 1, count($args), $args); |
|
108 | 108 | else |
109 | - array_splice($handler[1],0,count($args),$args); |
|
109 | + array_splice($handler[1], 0, count($args), $args); |
|
110 | 110 | $handler[1][]=$this; |
111 | - $result=call_user_func_array($handler[0],$handler[1]); |
|
111 | + $result=call_user_func_array($handler[0], $handler[1]); |
|
112 | 112 | } while($this->_iterator->valid()); |
113 | 113 | else |
114 | - $result = $args[0]; |
|
114 | + $result=$args[0]; |
|
115 | 115 | return $result; |
116 | 116 | } |
117 | 117 | |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | * @param string method name of the unspecified object method |
138 | 138 | * @param array arguments to the unspecified object method |
139 | 139 | */ |
140 | - public function __dycall($method,$args) |
|
140 | + public function __dycall($method, $args) |
|
141 | 141 | { |
142 | 142 | if($this->_method==$method) |
143 | - return call_user_func_array(array($this,'call'),$args); |
|
143 | + return call_user_func_array(array($this, 'call'), $args); |
|
144 | 144 | return null; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | \ No newline at end of file |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | { |
44 | 44 | $this->_owner=$owner; |
45 | 45 | foreach($this->events() as $event=>$handler) |
46 | - $owner->attachEventHandler($event,array($this,$handler)); |
|
46 | + $owner->attachEventHandler($event, array($this, $handler)); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function detach($owner) |
57 | 57 | { |
58 | 58 | foreach($this->events() as $event=>$handler) |
59 | - $owner->detachEventHandler($event,array($this,$handler)); |
|
59 | + $owner->detachEventHandler($event, array($this, $handler)); |
|
60 | 60 | $this->_owner=null; |
61 | 61 | } |
62 | 62 |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $this->loadParameters($config); |
62 | 62 | if($this->_paramFile!==null) |
63 | 63 | { |
64 | - $configFile = null; |
|
64 | + $configFile=null; |
|
65 | 65 | if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_XML && ($cache=$this->getApplication()->getCache())!==null) |
66 | 66 | { |
67 | 67 | $cacheKey='TParameterModule:'.$this->_paramFile; |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | { |
70 | 70 | $configFile=new TXmlDocument; |
71 | 71 | $configFile->loadFromFile($this->_paramFile); |
72 | - $cache->set($cacheKey,$configFile,0,new TFileCacheDependency($this->_paramFile)); |
|
72 | + $cache->set($cacheKey, $configFile, 0, new TFileCacheDependency($this->_paramFile)); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | else |
76 | 76 | { |
77 | 77 | if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
78 | 78 | { |
79 | - $configFile = include $this->_paramFile; |
|
79 | + $configFile=include $this->_paramFile; |
|
80 | 80 | } |
81 | 81 | else |
82 | 82 | { |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | { |
104 | 104 | if(is_array($parameter) && isset($parameter['class'])) |
105 | 105 | { |
106 | - $properties = isset($parameter['properties'])?$parameter['properties']:array(); |
|
107 | - $parameters[$id]=array($parameter['class'],$properties); |
|
106 | + $properties=isset($parameter['properties']) ? $parameter['properties'] : array(); |
|
107 | + $parameters[$id]=array($parameter['class'], $properties); |
|
108 | 108 | } |
109 | 109 | else |
110 | 110 | { |
111 | - $parameters[$id] = $parameter; |
|
111 | + $parameters[$id]=$parameter; |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $parameters[$id]=$value; |
128 | 128 | } |
129 | 129 | else |
130 | - $parameters[$id]=array($type,$properties->toArray()); |
|
130 | + $parameters[$id]=array($type, $properties->toArray()); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | { |
139 | 139 | $component=Prado::createComponent($parameter[0]); |
140 | 140 | foreach($parameter[1] as $name=>$value) |
141 | - $component->setSubProperty($name,$value); |
|
142 | - $appParams->add($id,$component); |
|
141 | + $component->setSubProperty($name, $value); |
|
142 | + $appParams->add($id, $component); |
|
143 | 143 | } |
144 | 144 | else |
145 | - $appParams->add($id,$parameter); |
|
145 | + $appParams->add($id, $parameter); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | { |
165 | 165 | if($this->_initialized) |
166 | 166 | throw new TInvalidOperationException('parametermodule_parameterfile_unchangeable'); |
167 | - else if(($this->_paramFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null || !is_file($this->_paramFile)) |
|
168 | - throw new TConfigurationException('parametermodule_parameterfile_invalid',$value); |
|
167 | + else if(($this->_paramFile=Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt()))===null || !is_file($this->_paramFile)) |
|
168 | + throw new TConfigurationException('parametermodule_parameterfile_invalid', $value); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 |
@@ -71,14 +71,12 @@ discard block |
||
71 | 71 | $configFile->loadFromFile($this->_paramFile); |
72 | 72 | $cache->set($cacheKey,$configFile,0,new TFileCacheDependency($this->_paramFile)); |
73 | 73 | } |
74 | - } |
|
75 | - else |
|
74 | + } else |
|
76 | 75 | { |
77 | 76 | if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
78 | 77 | { |
79 | 78 | $configFile = include $this->_paramFile; |
80 | - } |
|
81 | - else |
|
79 | + } else |
|
82 | 80 | { |
83 | 81 | $configFile=new TXmlDocument; |
84 | 82 | $configFile->loadFromFile($this->_paramFile); |
@@ -105,14 +103,12 @@ discard block |
||
105 | 103 | { |
106 | 104 | $properties = isset($parameter['properties'])?$parameter['properties']:array(); |
107 | 105 | $parameters[$id]=array($parameter['class'],$properties); |
108 | - } |
|
109 | - else |
|
106 | + } else |
|
110 | 107 | { |
111 | 108 | $parameters[$id] = $parameter; |
112 | 109 | } |
113 | 110 | } |
114 | - } |
|
115 | - else if($config instanceof TXmlElement) |
|
111 | + } else if($config instanceof TXmlElement) |
|
116 | 112 | { |
117 | 113 | foreach($config->getElementsByTagName('parameter') as $node) |
118 | 114 | { |
@@ -125,8 +121,7 @@ discard block |
||
125 | 121 | $parameters[$id]=$node; |
126 | 122 | else |
127 | 123 | $parameters[$id]=$value; |
128 | - } |
|
129 | - else |
|
124 | + } else |
|
130 | 125 | $parameters[$id]=array($type,$properties->toArray()); |
131 | 126 | } |
132 | 127 | } |
@@ -140,8 +135,7 @@ discard block |
||
140 | 135 | foreach($parameter[1] as $name=>$value) |
141 | 136 | $component->setSubProperty($name,$value); |
142 | 137 | $appParams->add($id,$component); |
143 | - } |
|
144 | - else |
|
138 | + } else |
|
145 | 139 | $appParams->add($id,$parameter); |
146 | 140 | } |
147 | 141 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | * @return string SQL search condition matching on a set of columns. |
31 | 31 | */ |
32 | 32 | public function getSearchExpression($fields, $keywords) { |
33 | - $columns = array (); |
|
34 | - foreach ($fields as $field) { |
|
35 | - if ($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
|
36 | - $columns[] = $field; |
|
33 | + $columns=array(); |
|
34 | + foreach($fields as $field) { |
|
35 | + if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
|
36 | + $columns[]=$field; |
|
37 | 37 | } |
38 | 38 | return parent :: getSearchExpression($columns, $keywords); |
39 | 39 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @return boolean true if column can be used for LIKE searching. |
43 | 43 | */ |
44 | 44 | protected function isSearchableColumn($column) { |
45 | - $type = strtolower($column->getDbType()); |
|
46 | - return $type === 'character varying' || $type === 'varchar2' || $type === 'character' || $type === 'char' || $type === 'text'; |
|
45 | + $type=strtolower($column->getDbType()); |
|
46 | + return $type==='character varying' || $type==='varchar2' || $type==='character' || $type==='char' || $type==='text'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -72,59 +72,59 @@ discard block |
||
72 | 72 | * @param integer row offset, -1 to ignore offset. |
73 | 73 | * @return string SQL with limit and offset in Oracle way. |
74 | 74 | */ |
75 | - public function applyLimitOffset($sql, $limit = -1, $offset = -1) { |
|
76 | - if ((int) $limit <= 0 && (int) $offset <= 0) |
|
75 | + public function applyLimitOffset($sql, $limit=-1, $offset=-1) { |
|
76 | + if((int) $limit <= 0 && (int) $offset <= 0) |
|
77 | 77 | return $sql; |
78 | 78 | |
79 | - $pradoNUMLIN = 'pradoNUMLIN'; |
|
80 | - $fieldsALIAS = 'xyz'; |
|
79 | + $pradoNUMLIN='pradoNUMLIN'; |
|
80 | + $fieldsALIAS='xyz'; |
|
81 | 81 | |
82 | - $nfimDaSQL = strlen($sql); |
|
83 | - $nfimDoWhere = (strpos($sql, 'ORDER') !== false ? strpos($sql, 'ORDER') : $nfimDaSQL); |
|
84 | - $niniDoSelect = strpos($sql, 'SELECT') + 6; |
|
85 | - $nfimDoSelect = (strpos($sql, 'FROM') !== false ? strpos($sql, 'FROM') : $nfimDaSQL); |
|
82 | + $nfimDaSQL=strlen($sql); |
|
83 | + $nfimDoWhere=(strpos($sql, 'ORDER')!==false ? strpos($sql, 'ORDER') : $nfimDaSQL); |
|
84 | + $niniDoSelect=strpos($sql, 'SELECT') + 6; |
|
85 | + $nfimDoSelect=(strpos($sql, 'FROM')!==false ? strpos($sql, 'FROM') : $nfimDaSQL); |
|
86 | 86 | |
87 | 87 | $WhereInSubSelect=""; |
88 | 88 | if(strpos($sql, 'WHERE')!==false) |
89 | - $WhereInSubSelect = "WHERE " .substr($sql, strpos($sql, 'WHERE')+5, $nfimDoWhere - $niniDoWhere); |
|
89 | + $WhereInSubSelect="WHERE ".substr($sql, strpos($sql, 'WHERE') + 5, $nfimDoWhere - $niniDoWhere); |
|
90 | 90 | |
91 | - $sORDERBY = ''; |
|
92 | - if (stripos($sql, 'ORDER') !== false) { |
|
93 | - $p = stripos($sql, 'ORDER'); |
|
94 | - $sORDERBY = substr($sql, $p +8); |
|
91 | + $sORDERBY=''; |
|
92 | + if(stripos($sql, 'ORDER')!==false) { |
|
93 | + $p=stripos($sql, 'ORDER'); |
|
94 | + $sORDERBY=substr($sql, $p + 8); |
|
95 | 95 | } |
96 | 96 | |
97 | - $fields = substr($sql, 0, $nfimDoSelect); |
|
98 | - $fields = trim(substr($fields, $niniDoSelect)); |
|
99 | - $aliasedFields = ', '; |
|
97 | + $fields=substr($sql, 0, $nfimDoSelect); |
|
98 | + $fields=trim(substr($fields, $niniDoSelect)); |
|
99 | + $aliasedFields=', '; |
|
100 | 100 | |
101 | - if (trim($fields) == '*') { |
|
102 | - $aliasedFields = ", {$fieldsALIAS}.{$fields}"; |
|
103 | - $fields = ''; |
|
104 | - $arr = $this->getTableInfo()->getColumns(); |
|
105 | - foreach ($arr as $field) { |
|
106 | - $fields .= strtolower($field->getColumnName()) . ', '; |
|
101 | + if(trim($fields)=='*') { |
|
102 | + $aliasedFields=", {$fieldsALIAS}.{$fields}"; |
|
103 | + $fields=''; |
|
104 | + $arr=$this->getTableInfo()->getColumns(); |
|
105 | + foreach($arr as $field) { |
|
106 | + $fields.=strtolower($field->getColumnName()).', '; |
|
107 | 107 | } |
108 | - $fields = str_replace('"', '', $fields); |
|
109 | - $fields = trim($fields); |
|
110 | - $fields = substr($fields, 0, strlen($fields) - 1); |
|
108 | + $fields=str_replace('"', '', $fields); |
|
109 | + $fields=trim($fields); |
|
110 | + $fields=substr($fields, 0, strlen($fields) - 1); |
|
111 | 111 | } else { |
112 | - if (strpos($fields, ',') !== false) { |
|
113 | - $arr = $this->getTableInfo()->getColumns(); |
|
114 | - foreach ($arr as $field) { |
|
115 | - $field = strtolower($field); |
|
116 | - $existAS = str_ireplace(' as ', '-as-', $field); |
|
117 | - if (strpos($existAS, '-as-') === false) |
|
118 | - $aliasedFields .= "{$fieldsALIAS}." . trim($field) . ", "; |
|
112 | + if(strpos($fields, ',')!==false) { |
|
113 | + $arr=$this->getTableInfo()->getColumns(); |
|
114 | + foreach($arr as $field) { |
|
115 | + $field=strtolower($field); |
|
116 | + $existAS=str_ireplace(' as ', '-as-', $field); |
|
117 | + if(strpos($existAS, '-as-')===false) |
|
118 | + $aliasedFields.="{$fieldsALIAS}.".trim($field).", "; |
|
119 | 119 | else |
120 | - $aliasedFields .= "{$field}, "; |
|
120 | + $aliasedFields.="{$field}, "; |
|
121 | 121 | } |
122 | - $aliasedFields = trim($aliasedFields); |
|
123 | - $aliasedFields = substr($aliasedFields, 0, strlen($aliasedFields) - 1); |
|
122 | + $aliasedFields=trim($aliasedFields); |
|
123 | + $aliasedFields=substr($aliasedFields, 0, strlen($aliasedFields) - 1); |
|
124 | 124 | } |
125 | 125 | } |
126 | - if ($aliasedFields == ', ') |
|
127 | - $aliasedFields = " , $fieldsALIAS.* "; |
|
126 | + if($aliasedFields==', ') |
|
127 | + $aliasedFields=" , $fieldsALIAS.* "; |
|
128 | 128 | |
129 | 129 | /* ************************ |
130 | 130 | $newSql = " SELECT $fields FROM ". |
@@ -134,17 +134,17 @@ discard block |
||
134 | 134 | ") WHERE {$pradoNUMLIN} >= {$offset} "; |
135 | 135 | |
136 | 136 | ************************* */ |
137 | - $offset=(int)$offset; |
|
138 | - $toReg = $offset + $limit ; |
|
139 | - $fullTableName = $this->getTableInfo()->getTableFullName(); |
|
140 | - if (empty ($sORDERBY)) |
|
137 | + $offset=(int) $offset; |
|
138 | + $toReg=$offset + $limit; |
|
139 | + $fullTableName=$this->getTableInfo()->getTableFullName(); |
|
140 | + if(empty ($sORDERBY)) |
|
141 | 141 | $sORDERBY="ROWNUM"; |
142 | 142 | |
143 | - $newSql = " SELECT $fields FROM " . |
|
144 | - "( " . |
|
145 | - " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) -1 as {$pradoNUMLIN} {$aliasedFields} " . |
|
146 | - " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect" . |
|
147 | - ") nn " . |
|
143 | + $newSql=" SELECT $fields FROM ". |
|
144 | + "( ". |
|
145 | + " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) -1 as {$pradoNUMLIN} {$aliasedFields} ". |
|
146 | + " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect". |
|
147 | + ") nn ". |
|
148 | 148 | " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} < {$toReg} "; |
149 | 149 | //echo $newSql."\n<br>\n"; |
150 | 150 | return $newSql; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | class TOracleTableColumn extends TDbTableColumn |
25 | 25 | { |
26 | 26 | private static $types=array( |
27 | - 'numeric' => array( 'numeric' ) |
|
27 | + 'numeric' => array('numeric') |
|
28 | 28 | // 'integer' => array('bit', 'bit varying', 'real', 'serial', 'int', 'integer'), |
29 | 29 | // 'boolean' => array('boolean'), |
30 | 30 | // 'float' => array('bigint', 'bigserial', 'double precision', 'money', 'numeric') |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function getPHPType() |
38 | 38 | { |
39 | - $dbtype = strtolower($this->getDbType()); |
|
39 | + $dbtype=strtolower($this->getDbType()); |
|
40 | 40 | foreach(self::$types as $type => $dbtypes) |
41 | 41 | { |
42 | 42 | if(in_array($dbtype, $dbtypes)) |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | public function getPHPType() |
37 | 37 | { |
38 | - $dbtype = strtolower($this->getDbType()); |
|
38 | + $dbtype=strtolower($this->getDbType()); |
|
39 | 39 | foreach(self::$types as $type => $dbtypes) |
40 | 40 | { |
41 | 41 | if(in_array($dbtype, $dbtypes)) |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function getSearchExpression($fields, $keywords) |
32 | 32 | { |
33 | - $columns = array(); |
|
33 | + $columns=array(); |
|
34 | 34 | foreach($fields as $field) |
35 | 35 | { |
36 | 36 | if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
37 | - $columns[] = $field; |
|
37 | + $columns[]=$field; |
|
38 | 38 | } |
39 | 39 | return parent::getSearchExpression($columns, $keywords); |
40 | 40 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function isSearchableColumn($column) |
46 | 46 | { |
47 | - $type = strtolower($column->getDbType()); |
|
48 | - return $type === 'character varying' || $type === 'varchar' || |
|
49 | - $type === 'character' || $type === 'char' || $type === 'text'; |
|
47 | + $type=strtolower($column->getDbType()); |
|
48 | + return $type==='character varying' || $type==='varchar' || |
|
49 | + $type==='character' || $type==='char' || $type==='text'; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | $conditions=array(); |
61 | 61 | foreach($words as $word) |
62 | - $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
62 | + $conditions[]=$column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
63 | 63 | return '('.implode(' AND ', $conditions).')'; |
64 | 64 | } |
65 | 65 |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
90 | 90 | { |
91 | - $limit = $limit!==null ? (int)$limit : -1; |
|
92 | - $offset = $offset!==null ? (int)$offset : -1; |
|
93 | - $limitStr = $limit >= 0 ? ' LIMIT '.$limit : ''; |
|
94 | - $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
91 | + $limit=$limit!==null ? (int) $limit : -1; |
|
92 | + $offset=$offset!==null ? (int) $offset : -1; |
|
93 | + $limitStr=$limit >= 0 ? ' LIMIT '.$limit : ''; |
|
94 | + $offsetStr=$offset >= 0 ? ' OFFSET '.$offset : ''; |
|
95 | 95 | return $sql.$limitStr.$offsetStr; |
96 | 96 | } |
97 | 97 | |
@@ -105,18 +105,18 @@ discard block |
||
105 | 105 | $orders=array(); |
106 | 106 | foreach($ordering as $name => $direction) |
107 | 107 | { |
108 | - $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC'; |
|
109 | - if(false !== strpos($name, '(') && false !== strpos($name, ')')) { |
|
108 | + $direction=strtolower($direction)=='desc' ? 'DESC' : 'ASC'; |
|
109 | + if(false!==strpos($name, '(') && false!==strpos($name, ')')) { |
|
110 | 110 | // key is a function (bad practice, but we need to handle it) |
111 | - $key = $name; |
|
111 | + $key=$name; |
|
112 | 112 | } else { |
113 | 113 | // key is a column |
114 | - $key = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
114 | + $key=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
115 | 115 | } |
116 | - $orders[] = $key.' '.$direction; |
|
116 | + $orders[]=$key.' '.$direction; |
|
117 | 117 | } |
118 | 118 | if(count($orders) > 0) |
119 | - $sql .= ' ORDER BY '.implode(', ', $orders); |
|
119 | + $sql.=' ORDER BY '.implode(', ', $orders); |
|
120 | 120 | return $sql; |
121 | 121 | } |
122 | 122 | |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getSearchExpression($fields, $keywords) |
132 | 132 | { |
133 | - if(strlen(trim($keywords)) == 0) return ''; |
|
134 | - $words = preg_split('/\s/u', $keywords); |
|
135 | - $conditions = array(); |
|
133 | + if(strlen(trim($keywords))==0) return ''; |
|
134 | + $words=preg_split('/\s/u', $keywords); |
|
135 | + $conditions=array(); |
|
136 | 136 | foreach($fields as $field) |
137 | 137 | { |
138 | - $column = $this->getTableInfo()->getColumn($field)->getColumnName(); |
|
139 | - $conditions[] = $this->getSearchCondition($column, $words); |
|
138 | + $column=$this->getTableInfo()->getColumn($field)->getColumnName(); |
|
139 | + $conditions[]=$this->getSearchCondition($column, $words); |
|
140 | 140 | } |
141 | 141 | return '('.implode(' OR ', $conditions).')'; |
142 | 142 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | $conditions=array(); |
152 | 152 | foreach($words as $word) |
153 | - $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
153 | + $conditions[]=$column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
154 | 154 | return '('.implode(' AND ', $conditions).')'; |
155 | 155 | } |
156 | 156 | |
@@ -195,102 +195,102 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function getSelectFieldList($data='*') { |
197 | 197 | if(is_scalar($data)) { |
198 | - $tmp = explode(',', $data); |
|
199 | - $result = array(); |
|
198 | + $tmp=explode(',', $data); |
|
199 | + $result=array(); |
|
200 | 200 | foreach($tmp as $v) |
201 | - $result[] = trim($v); |
|
201 | + $result[]=trim($v); |
|
202 | 202 | return $result; |
203 | 203 | } |
204 | 204 | |
205 | - $bHasWildcard = false; |
|
206 | - $result = array(); |
|
205 | + $bHasWildcard=false; |
|
206 | + $result=array(); |
|
207 | 207 | if(is_array($data) || $data instanceof Traversable) { |
208 | - $columns = $this->getTableInfo()->getColumns(); |
|
208 | + $columns=$this->getTableInfo()->getColumns(); |
|
209 | 209 | foreach($data as $key=>$value) { |
210 | 210 | if($key==='*' || $value==='*') { |
211 | - $bHasWildcard = true; |
|
211 | + $bHasWildcard=true; |
|
212 | 212 | continue; |
213 | 213 | } |
214 | 214 | |
215 | 215 | if(strToUpper($key)==='NULL') { |
216 | - $result[] = 'NULL'; |
|
216 | + $result[]='NULL'; |
|
217 | 217 | continue; |
218 | 218 | } |
219 | 219 | |
220 | 220 | if(strpos($key, '(')!==false && strpos($key, ')')!==false) { |
221 | - $result[] = $key; |
|
221 | + $result[]=$key; |
|
222 | 222 | continue; |
223 | 223 | } |
224 | 224 | |
225 | 225 | if(stripos($key, 'AS')!==false) { |
226 | - $result[] = $key; |
|
226 | + $result[]=$key; |
|
227 | 227 | continue; |
228 | 228 | } |
229 | 229 | |
230 | 230 | if(stripos($value, 'AS')!==false) { |
231 | - $result[] = $value; |
|
231 | + $result[]=$value; |
|
232 | 232 | continue; |
233 | 233 | } |
234 | 234 | |
235 | - $v = isset($columns[$value]); |
|
236 | - $k = isset($columns[$key]); |
|
235 | + $v=isset($columns[$value]); |
|
236 | + $k=isset($columns[$key]); |
|
237 | 237 | if(is_integer($key) && $v) { |
238 | - $key = $value; |
|
239 | - $k = $v; |
|
238 | + $key=$value; |
|
239 | + $k=$v; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | if(strToUpper($value)==='NULL') { |
243 | 243 | if($k) |
244 | - $result[] = 'NULL AS ' . $columns[$key]->getColumnName(); |
|
244 | + $result[]='NULL AS '.$columns[$key]->getColumnName(); |
|
245 | 245 | else |
246 | - $result[] = 'NULL' . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
246 | + $result[]='NULL'.(is_string($key) ? (' AS '.(string) $key) : ''); |
|
247 | 247 | continue; |
248 | 248 | } |
249 | 249 | |
250 | 250 | if(strpos($value, '(')!==false && strpos($value, ')')!==false) { |
251 | 251 | if($k) |
252 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
252 | + $result[]=$value.' AS '.$columns[$key]->getColumnName(); |
|
253 | 253 | else |
254 | - $result[] = $value . (is_string($key) ? (' AS ' . (string)$key) : ''); |
|
254 | + $result[]=$value.(is_string($key) ? (' AS '.(string) $key) : ''); |
|
255 | 255 | continue; |
256 | 256 | } |
257 | 257 | |
258 | 258 | if($v && $key==$value) { |
259 | - $result[] = $columns[$value]->getColumnName(); |
|
259 | + $result[]=$columns[$value]->getColumnName(); |
|
260 | 260 | continue; |
261 | 261 | } |
262 | 262 | |
263 | 263 | if($k && $value==null) { |
264 | - $result[] = $columns[$key]->getColumnName(); |
|
264 | + $result[]=$columns[$key]->getColumnName(); |
|
265 | 265 | continue; |
266 | 266 | } |
267 | 267 | |
268 | 268 | if(is_string($key) && $v) { |
269 | - $result[] = $columns[$value]->getColumnName() . ' AS ' . $key; |
|
269 | + $result[]=$columns[$value]->getColumnName().' AS '.$key; |
|
270 | 270 | continue; |
271 | 271 | } |
272 | 272 | |
273 | 273 | if(is_numeric($value) && $k) { |
274 | - $result[] = $value . ' AS ' . $columns[$key]->getColumnName(); |
|
274 | + $result[]=$value.' AS '.$columns[$key]->getColumnName(); |
|
275 | 275 | continue; |
276 | 276 | } |
277 | 277 | |
278 | 278 | if(is_string($value) && $k) { |
279 | - $result[] = $this->getDbConnection()->quoteString($value) . ' AS ' . $columns[$key]->getColumnName(); |
|
279 | + $result[]=$this->getDbConnection()->quoteString($value).' AS '.$columns[$key]->getColumnName(); |
|
280 | 280 | continue; |
281 | 281 | } |
282 | 282 | |
283 | 283 | if(!$v && !$k && is_integer($key)) { |
284 | - $result[] = is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value); |
|
284 | + $result[]=is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value); |
|
285 | 285 | continue; |
286 | 286 | } |
287 | 287 | |
288 | - $result[] = (is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string)$value)) . ' AS ' . $key; |
|
288 | + $result[]=(is_numeric($value) ? $value : $this->getDbConnection()->quoteString((string) $value)).' AS '.$key; |
|
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | - if($data===null || count($result) == 0 || $bHasWildcard) |
|
293 | - $result = $result = array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
292 | + if($data===null || count($result)==0 || $bHasWildcard) |
|
293 | + $result=$result=array_merge($this->getTableInfo()->getColumnNames(), $result); |
|
294 | 294 | |
295 | 295 | return $result; |
296 | 296 | } |
@@ -304,21 +304,21 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1, $select='*') |
306 | 306 | { |
307 | - $table = $this->getTableInfo()->getTableFullName(); |
|
308 | - $fields = implode(', ', $this -> getSelectFieldList($select)); |
|
309 | - $sql = "SELECT {$fields} FROM {$table}"; |
|
307 | + $table=$this->getTableInfo()->getTableFullName(); |
|
308 | + $fields=implode(', ', $this -> getSelectFieldList($select)); |
|
309 | + $sql="SELECT {$fields} FROM {$table}"; |
|
310 | 310 | if(!empty($where)) |
311 | - $sql .= " WHERE {$where}"; |
|
311 | + $sql.=" WHERE {$where}"; |
|
312 | 312 | return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset); |
313 | 313 | } |
314 | 314 | |
315 | - public function applyCriterias($sql, $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
|
315 | + public function applyCriterias($sql, $parameters=array(), $ordering=array(), $limit=-1, $offset=-1) |
|
316 | 316 | { |
317 | 317 | if(count($ordering) > 0) |
318 | - $sql = $this->applyOrdering($sql, $ordering); |
|
319 | - if($limit>=0 || $offset>=0) |
|
320 | - $sql = $this->applyLimitOffset($sql, $limit, $offset); |
|
321 | - $command = $this->createCommand($sql); |
|
318 | + $sql=$this->applyOrdering($sql, $ordering); |
|
319 | + if($limit >= 0 || $offset >= 0) |
|
320 | + $sql=$this->applyLimitOffset($sql, $limit, $offset); |
|
321 | + $command=$this->createCommand($sql); |
|
322 | 322 | $this->bindArrayValues($command, $parameters); |
323 | 323 | return $command; |
324 | 324 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @param array binding parameters. |
330 | 330 | * @return TDbCommand count command. |
331 | 331 | */ |
332 | - public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) |
|
332 | + public function createCountCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1) |
|
333 | 333 | { |
334 | 334 | return $this->createFindCommand($where, $parameters, $ordering, $limit, $offset, 'COUNT(*)'); |
335 | 335 | } |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | * @param array delete parameters. |
343 | 343 | * @return TDbCommand delete command. |
344 | 344 | */ |
345 | - public function createDeleteCommand($where,$parameters=array()) |
|
345 | + public function createDeleteCommand($where, $parameters=array()) |
|
346 | 346 | { |
347 | - $table = $this->getTableInfo()->getTableFullName(); |
|
348 | - if (!empty($where)) |
|
349 | - $where = ' WHERE '.$where; |
|
350 | - $command = $this->createCommand("DELETE FROM {$table}".$where); |
|
347 | + $table=$this->getTableInfo()->getTableFullName(); |
|
348 | + if(!empty($where)) |
|
349 | + $where=' WHERE '.$where; |
|
350 | + $command=$this->createCommand("DELETE FROM {$table}".$where); |
|
351 | 351 | $this->bindArrayValues($command, $parameters); |
352 | 352 | return $command; |
353 | 353 | } |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function createInsertCommand($data) |
364 | 364 | { |
365 | - $table = $this->getTableInfo()->getTableFullName(); |
|
366 | - list($fields, $bindings) = $this->getInsertFieldBindings($data); |
|
367 | - $command = $this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)"); |
|
365 | + $table=$this->getTableInfo()->getTableFullName(); |
|
366 | + list($fields, $bindings)=$this->getInsertFieldBindings($data); |
|
367 | + $command=$this->createCommand("INSERT INTO {$table}({$fields}) VALUES ($bindings)"); |
|
368 | 368 | $this->bindColumnValues($command, $data); |
369 | 369 | return $command; |
370 | 370 | } |
@@ -379,15 +379,15 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function createUpdateCommand($data, $where, $parameters=array()) |
381 | 381 | { |
382 | - $table = $this->getTableInfo()->getTableFullName(); |
|
382 | + $table=$this->getTableInfo()->getTableFullName(); |
|
383 | 383 | if($this->hasIntegerKey($parameters)) |
384 | - $fields = implode(', ', $this->getColumnBindings($data, true)); |
|
384 | + $fields=implode(', ', $this->getColumnBindings($data, true)); |
|
385 | 385 | else |
386 | - $fields = implode(', ', $this->getColumnBindings($data)); |
|
386 | + $fields=implode(', ', $this->getColumnBindings($data)); |
|
387 | 387 | |
388 | - if (!empty($where)) |
|
389 | - $where = ' WHERE '.$where; |
|
390 | - $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where); |
|
388 | + if(!empty($where)) |
|
389 | + $where=' WHERE '.$where; |
|
390 | + $command=$this->createCommand("UPDATE {$table} SET {$fields}".$where); |
|
391 | 391 | $this->bindArrayValues($command, array_merge($data, $parameters)); |
392 | 392 | return $command; |
393 | 393 | } |
@@ -399,13 +399,13 @@ discard block |
||
399 | 399 | */ |
400 | 400 | protected function getInsertFieldBindings($values) |
401 | 401 | { |
402 | - $fields = array(); $bindings=array(); |
|
402 | + $fields=array(); $bindings=array(); |
|
403 | 403 | foreach(array_keys($values) as $name) |
404 | 404 | { |
405 | - $fields[] = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
406 | - $bindings[] = ':'.$name; |
|
405 | + $fields[]=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
406 | + $bindings[]=':'.$name; |
|
407 | 407 | } |
408 | - return array(implode(', ',$fields), implode(', ', $bindings)); |
|
408 | + return array(implode(', ', $fields), implode(', ', $bindings)); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -419,8 +419,8 @@ discard block |
||
419 | 419 | $bindings=array(); |
420 | 420 | foreach(array_keys($values) as $name) |
421 | 421 | { |
422 | - $column = $this->getTableInfo()->getColumn($name)->getColumnName(); |
|
423 | - $bindings[] = $position ? $column.' = ?' : $column.' = :'.$name; |
|
422 | + $column=$this->getTableInfo()->getColumn($name)->getColumnName(); |
|
423 | + $bindings[]=$position ? $column.' = ?' : $column.' = :'.$name; |
|
424 | 424 | } |
425 | 425 | return $bindings; |
426 | 426 | } |
@@ -444,8 +444,8 @@ discard block |
||
444 | 444 | { |
445 | 445 | foreach($values as $name=>$value) |
446 | 446 | { |
447 | - $column = $this->getTableInfo()->getColumn($name); |
|
448 | - if($value === null && $column->getAllowNull()) |
|
447 | + $column=$this->getTableInfo()->getColumn($name); |
|
448 | + if($value===null && $column->getAllowNull()) |
|
449 | 449 | $command->bindValue(':'.$name, null, PDO::PARAM_NULL); |
450 | 450 | else |
451 | 451 | $command->bindValue(':'.$name, $value, $column->getPdoType()); |
@@ -460,15 +460,15 @@ discard block |
||
460 | 460 | { |
461 | 461 | if($this->hasIntegerKey($values)) |
462 | 462 | { |
463 | - $values = array_values($values); |
|
464 | - for($i = 0, $max=count($values); $i<$max; $i++) |
|
465 | - $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
|
463 | + $values=array_values($values); |
|
464 | + for($i=0, $max=count($values); $i < $max; $i++) |
|
465 | + $command->bindValue($i + 1, $values[$i], $this->getPdoType($values[$i])); |
|
466 | 466 | } |
467 | 467 | else |
468 | 468 | { |
469 | 469 | foreach($values as $name=>$value) |
470 | 470 | { |
471 | - $prop = $name[0]===':' ? $name : ':'.$name; |
|
471 | + $prop=$name[0]===':' ? $name : ':'.$name; |
|
472 | 472 | $command->bindValue($prop, $value, $this->getPdoType($value)); |
473 | 473 | } |
474 | 474 | } |
@@ -191,7 +191,6 @@ discard block |
||
191 | 191 | * array('col1' => 'NULL', '*') |
192 | 192 | * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM... |
193 | 193 | * </code> |
194 | - * @param mixed $value |
|
195 | 194 | * @return array of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage |
196 | 195 | * @since 3.1.7 |
197 | 196 | * @todo add support for table aliasing |
@@ -399,7 +398,7 @@ discard block |
||
399 | 398 | /** |
400 | 399 | * Returns a list of insert field name and a list of binding names. |
401 | 400 | * @param object array or object to be inserted. |
402 | - * @return array tuple ($fields, $bindings) |
|
401 | + * @return string[] tuple ($fields, $bindings) |
|
403 | 402 | */ |
404 | 403 | protected function getInsertFieldBindings($values) |
405 | 404 | { |
@@ -467,8 +467,7 @@ |
||
467 | 467 | $values = array_values($values); |
468 | 468 | for($i = 0, $max=count($values); $i<$max; $i++) |
469 | 469 | $command->bindValue($i+1, $values[$i], $this->getPdoType($values[$i])); |
470 | - } |
|
471 | - else |
|
470 | + } else |
|
472 | 471 | { |
473 | 472 | foreach($values as $name=>$value) |
474 | 473 | { |