@@ -54,6 +54,7 @@ |
||
54 | 54 | * @param string parent node id |
55 | 55 | * @param string new node id |
56 | 56 | * @param mixed node value |
57 | + * @param string $node |
|
57 | 58 | */ |
58 | 59 | public function add($parent, $node, $object = '') |
59 | 60 | { |
@@ -31,22 +31,22 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var array object graph as tree |
33 | 33 | */ |
34 | - private $_tree = []; |
|
34 | + private $_tree=[]; |
|
35 | 35 | /** |
36 | 36 | * @var array tree node values |
37 | 37 | */ |
38 | - private $_entries = []; |
|
38 | + private $_entries=[]; |
|
39 | 39 | /** |
40 | 40 | * @var array resulting object collection |
41 | 41 | */ |
42 | - private $_list = []; |
|
42 | + private $_list=[]; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @return boolean true if the graph is empty |
46 | 46 | */ |
47 | 47 | public function isEmpty() |
48 | 48 | { |
49 | - return count($this->_entries) == 0; |
|
49 | + return count($this->_entries)==0; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,27 +55,27 @@ discard block |
||
55 | 55 | * @param string new node id |
56 | 56 | * @param mixed node value |
57 | 57 | */ |
58 | - public function add($parent, $node, $object = '') |
|
58 | + public function add($parent, $node, $object='') |
|
59 | 59 | { |
60 | - if(isset($this->_entries[$parent]) && ($this->_entries[$parent] !== null) |
|
61 | - && isset($this->_entries[$node]) && ($this->_entries[$node] !== null)) |
|
60 | + if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null) |
|
61 | + && isset($this->_entries[$node]) && ($this->_entries[$node]!==null)) |
|
62 | 62 | { |
63 | - $this->_entries[$node] = $object; |
|
63 | + $this->_entries[$node]=$object; |
|
64 | 64 | return; |
65 | 65 | } |
66 | - $this->_entries[$node] = $object; |
|
66 | + $this->_entries[$node]=$object; |
|
67 | 67 | if(empty($parent)) |
68 | 68 | { |
69 | 69 | if(isset($this->_entries[$node])) |
70 | 70 | return; |
71 | - $this->_tree[$node] = []; |
|
71 | + $this->_tree[$node]=[]; |
|
72 | 72 | } |
73 | - $found = $this->addNode($this->_tree, $parent, $node); |
|
73 | + $found=$this->addNode($this->_tree, $parent, $node); |
|
74 | 74 | if(!$found && !empty($parent)) |
75 | 75 | { |
76 | - $this->_tree[$parent] = []; |
|
77 | - if(!isset($this->_entries[$parent]) || $object !== '') |
|
78 | - $this->_entries[$parent] = $object; |
|
76 | + $this->_tree[$parent]=[]; |
|
77 | + if(!isset($this->_entries[$parent]) || $object!=='') |
|
78 | + $this->_entries[$parent]=$object; |
|
79 | 79 | $this->addNode($this->_tree, $parent, $node); |
80 | 80 | } |
81 | 81 | } |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | */ |
90 | 90 | protected function addNode(&$childs, $parent, $node) |
91 | 91 | { |
92 | - $found = false; |
|
92 | + $found=false; |
|
93 | 93 | reset($childs); |
94 | - for($i = 0, $k = count($childs); $i < $k; $i++) |
|
94 | + for($i=0, $k=count($childs); $i < $k; $i++) |
|
95 | 95 | { |
96 | - $key = key($childs); |
|
96 | + $key=key($childs); |
|
97 | 97 | next($childs); |
98 | - if($key == $parent) |
|
98 | + if($key==$parent) |
|
99 | 99 | { |
100 | - $found = true; |
|
101 | - $childs[$key][$node] = []; |
|
100 | + $found=true; |
|
101 | + $childs[$key][$node]=[]; |
|
102 | 102 | } |
103 | 103 | else |
104 | 104 | { |
105 | - $found = $found || $this->addNode($childs[$key], $parent, $node); |
|
105 | + $found=$found || $this->addNode($childs[$key], $parent, $node); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | return $found; |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | */ |
125 | 125 | protected function hasChildren(&$nodes) |
126 | 126 | { |
127 | - $hasChildren = false; |
|
127 | + $hasChildren=false; |
|
128 | 128 | foreach($nodes as $node) |
129 | - if(count($node) != 0) |
|
129 | + if(count($node)!=0) |
|
130 | 130 | return true; |
131 | 131 | return $hasChildren; |
132 | 132 | } |
@@ -138,14 +138,14 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function collectChildren($parent, &$nodes) |
140 | 140 | { |
141 | - $noChildren = !$this->hasChildren($nodes); |
|
142 | - $childs = []; |
|
143 | - for(reset($nodes); $key = key($nodes);) |
|
141 | + $noChildren=!$this->hasChildren($nodes); |
|
142 | + $childs=[]; |
|
143 | + for(reset($nodes); $key=key($nodes);) |
|
144 | 144 | { |
145 | 145 | next($nodes); |
146 | 146 | if($noChildren) |
147 | 147 | { |
148 | - $childs[] = $key; |
|
148 | + $childs[]=$key; |
|
149 | 149 | unset($nodes[$key]); |
150 | 150 | } |
151 | 151 | else |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | if(empty($parent) || empty($this->_entries[$parent])) |
166 | 166 | return; |
167 | 167 | |
168 | - $parentObject = $this->_entries[$parent]['object']; |
|
169 | - $property = $this->_entries[$nodes[0]]['property']; |
|
168 | + $parentObject=$this->_entries[$parent]['object']; |
|
169 | + $property=$this->_entries[$nodes[0]]['property']; |
|
170 | 170 | |
171 | - $list = TPropertyAccess::get($parentObject, $property); |
|
171 | + $list=TPropertyAccess::get($parentObject, $property); |
|
172 | 172 | |
173 | 173 | foreach($nodes as $node) |
174 | 174 | { |
175 | 175 | if($list instanceof TList) |
176 | - $parentObject->{$property}[] = $this->_entries[$node]['object']; |
|
176 | + $parentObject->{$property}[]=$this->_entries[$node]['object']; |
|
177 | 177 | elseif(is_array($list)) |
178 | - $list[] = $this->_entries[$node]['object']; |
|
178 | + $list[]=$this->_entries[$node]['object']; |
|
179 | 179 | else |
180 | 180 | throw new TSqlMapExecutionException( |
181 | 181 | 'sqlmap_property_must_be_list'); |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | if(is_array($list)) |
185 | 185 | TPropertyAccess::set($parentObject, $property, $list); |
186 | 186 | |
187 | - if($this->_entries[$parent]['property'] === null) |
|
188 | - $this->_list[] = $parentObject; |
|
187 | + if($this->_entries[$parent]['property']===null) |
|
188 | + $this->_list[]=$parentObject; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | |
199 | 199 | public function __sleep() |
200 | 200 | { |
201 | - $exprops = []; $cn = __CLASS__; |
|
202 | - if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; |
|
203 | - if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; |
|
204 | - if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; |
|
201 | + $exprops=[]; $cn=__CLASS__; |
|
202 | + if(!count($this->_tree)) $exprops[]="\0$cn\0_tree"; |
|
203 | + if(!count($this->_entries)) $exprops[]="\0$cn\0_entries"; |
|
204 | + if(!count($this->_list)) $exprops[]="\0$cn\0_list"; |
|
205 | 205 | return array_diff(parent::__sleep(), $exprops); |
206 | 206 | } |
207 | 207 | } |
208 | 208 | \ No newline at end of file |
@@ -36,6 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | private $_manager; |
38 | 38 | |
39 | + /** |
|
40 | + * @param TSqlMapManager $manager |
|
41 | + */ |
|
39 | 42 | public function __construct($manager) |
40 | 43 | { |
41 | 44 | $this->_manager = $manager; |
@@ -125,7 +128,7 @@ discard block |
||
125 | 128 | * @param mixed The object used to set the parameters in the SQL. |
126 | 129 | * @param integer The maximum number of objects to store in each page. |
127 | 130 | * @param integer The number of the page to initially load into the list. |
128 | - * @return TPagedList A PaginatedList of beans containing the rows. |
|
131 | + * @return TSqlMapPagedList A PaginatedList of beans containing the rows. |
|
129 | 132 | */ |
130 | 133 | public function queryForPagedList($statementName, $parameter = null, $pageSize = 10, $page = 0) |
131 | 134 | { |
@@ -146,7 +149,7 @@ discard block |
||
146 | 149 | * @param mixed The object used to set the parameters in the SQL. |
147 | 150 | * @param integer The maximum number of objects to store in each page. |
148 | 151 | * @param integer The number of the page to initially load into the list. |
149 | - * @return TPagedList A PaginatedList of beans containing the rows. |
|
152 | + * @return TSqlMapPagedList A PaginatedList of beans containing the rows. |
|
150 | 153 | */ |
151 | 154 | public function queryForPagedListWithRowDelegate($statementName, $delegate, $parameter = null, $pageSize = 10, $page = 0) |
152 | 155 | { |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | public function __construct($manager) |
40 | 40 | { |
41 | - $this->_manager = $manager; |
|
41 | + $this->_manager=$manager; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * @param mixed An object of the type to be returned. |
70 | 70 | * @return object A single result object populated with the result set data. |
71 | 71 | */ |
72 | - public function queryForObject($statementName, $parameter = null, $result = null) |
|
72 | + public function queryForObject($statementName, $parameter=null, $result=null) |
|
73 | 73 | { |
74 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
74 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
75 | 75 | return $statement->executeQueryForObject($this->getDbConnection(), $parameter, $result); |
76 | 76 | } |
77 | 77 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param int The maximum number of rows to return. |
91 | 91 | * @return TList A List of result objects. |
92 | 92 | */ |
93 | - public function queryForList($statementName, $parameter = null, $result = null, $skip = -1, $max = -1) |
|
93 | + public function queryForList($statementName, $parameter=null, $result=null, $skip=-1, $max=-1) |
|
94 | 94 | { |
95 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
95 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
96 | 96 | return $statement->executeQueryForList($this->getDbConnection(), $parameter, $result, $skip, $max); |
97 | 97 | } |
98 | 98 | |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @param int The maximum number of rows to return. |
112 | 112 | * @return TList A List of result objects. |
113 | 113 | */ |
114 | - public function queryWithRowDelegate($statementName, $delegate, $parameter = null, $result = null, $skip = -1, $max = -1) |
|
114 | + public function queryWithRowDelegate($statementName, $delegate, $parameter=null, $result=null, $skip=-1, $max=-1) |
|
115 | 115 | { |
116 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
116 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
117 | 117 | return $statement->executeQueryForList($this->getDbConnection(), $parameter, $result, $skip, $max, $delegate); |
118 | 118 | } |
119 | 119 | |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * @param integer The number of the page to initially load into the list. |
128 | 128 | * @return TPagedList A PaginatedList of beans containing the rows. |
129 | 129 | */ |
130 | - public function queryForPagedList($statementName, $parameter = null, $pageSize = 10, $page = 0) |
|
130 | + public function queryForPagedList($statementName, $parameter=null, $pageSize=10, $page=0) |
|
131 | 131 | { |
132 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
132 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
133 | 133 | return new TSqlMapPagedList($statement, $parameter, $pageSize, null, $page); |
134 | 134 | } |
135 | 135 | |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param integer The number of the page to initially load into the list. |
149 | 149 | * @return TPagedList A PaginatedList of beans containing the rows. |
150 | 150 | */ |
151 | - public function queryForPagedListWithRowDelegate($statementName, $delegate, $parameter = null, $pageSize = 10, $page = 0) |
|
151 | + public function queryForPagedListWithRowDelegate($statementName, $delegate, $parameter=null, $pageSize=10, $page=0) |
|
152 | 152 | { |
153 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
153 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
154 | 154 | return new TSqlMapPagedList($statement, $parameter, $pageSize, $delegate, $page); |
155 | 155 | } |
156 | 156 | |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | * @param string The property of the result object to be used as the value. |
168 | 168 | * @return TMap Array object containing the rows keyed by keyProperty. |
169 | 169 | */ |
170 | - public function queryForMap($statementName, $parameter = null, $keyProperty = null, $valueProperty = null, $skip = -1, $max = -1) |
|
170 | + public function queryForMap($statementName, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1) |
|
171 | 171 | { |
172 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
172 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
173 | 173 | return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max); |
174 | 174 | } |
175 | 175 | |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | * @param string The property of the result object to be used as the value. |
187 | 187 | * @return TMap Array object containing the rows keyed by keyProperty. |
188 | 188 | */ |
189 | - public function queryForMapWithRowDelegate($statementName, $delegate, $parameter = null, $keyProperty = null, $valueProperty = null, $skip = -1, $max = -1) |
|
189 | + public function queryForMapWithRowDelegate($statementName, $delegate, $parameter=null, $keyProperty=null, $valueProperty=null, $skip=-1, $max=-1) |
|
190 | 190 | { |
191 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
191 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
192 | 192 | return $statement->executeQueryForMap($this->getDbConnection(), $parameter, $keyProperty, $valueProperty, $skip, $max, $delegate); |
193 | 193 | } |
194 | 194 | |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * This might be automatically generated by the RDBMS, |
209 | 209 | * or selected from a sequence table or other source. |
210 | 210 | */ |
211 | - public function insert($statementName, $parameter = null) |
|
211 | + public function insert($statementName, $parameter=null) |
|
212 | 212 | { |
213 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
213 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
214 | 214 | return $statement->executeInsert($this->getDbConnection(), $parameter); |
215 | 215 | } |
216 | 216 | |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | * @param mixed The parameter object. |
228 | 228 | * @return integer The number of rows effected. |
229 | 229 | */ |
230 | - public function update($statementName, $parameter = null) |
|
230 | + public function update($statementName, $parameter=null) |
|
231 | 231 | { |
232 | - $statement = $this->getSqlMapManager()->getMappedStatement($statementName); |
|
232 | + $statement=$this->getSqlMapManager()->getMappedStatement($statementName); |
|
233 | 233 | return $statement->executeUpdate($this->getDbConnection(), $parameter); |
234 | 234 | } |
235 | 235 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param mixed The parameter object. |
240 | 240 | * @return integer The number of rows effected. |
241 | 241 | */ |
242 | - public function delete($statementName, $parameter = null) |
|
242 | + public function delete($statementName, $parameter=null) |
|
243 | 243 | { |
244 | 244 | return $this->update($statementName, $parameter); |
245 | 245 | } |
@@ -61,6 +61,7 @@ discard block |
||
61 | 61 | * Constructor, create a new SqlMap manager. |
62 | 62 | * @param TDbConnection database connection |
63 | 63 | * @param string configuration file. |
64 | + * @param \Prado\Data\TDbConnection $connection |
|
64 | 65 | */ |
65 | 66 | public function __construct($connection = null) |
66 | 67 | { |
@@ -74,6 +75,7 @@ discard block |
||
74 | 75 | |
75 | 76 | /** |
76 | 77 | * @param TDbConnection default database connection |
78 | + * @param \Prado\Data\TDbConnection $conn |
|
77 | 79 | */ |
78 | 80 | public function setDbConnection($conn) |
79 | 81 | { |
@@ -111,6 +113,7 @@ discard block |
||
111 | 113 | /** |
112 | 114 | * Loads and parses the SqlMap configuration file. |
113 | 115 | * @param string xml configuration file. |
116 | + * @param string $file |
|
114 | 117 | */ |
115 | 118 | public function configureXml($file) |
116 | 119 | { |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | * @param TDbConnection database connection |
63 | 63 | * @param string configuration file. |
64 | 64 | */ |
65 | - public function __construct($connection = null) |
|
65 | + public function __construct($connection=null) |
|
66 | 66 | { |
67 | - $this->_connection = $connection; |
|
67 | + $this->_connection=$connection; |
|
68 | 68 | |
69 | - $this->_mappedStatements = new TMap; |
|
70 | - $this->_resultMaps = new TMap; |
|
71 | - $this->_parameterMaps = new TMap; |
|
72 | - $this->_cacheModels = new TMap; |
|
69 | + $this->_mappedStatements=new TMap; |
|
70 | + $this->_resultMaps=new TMap; |
|
71 | + $this->_parameterMaps=new TMap; |
|
72 | + $this->_cacheModels=new TMap; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function setDbConnection($conn) |
79 | 79 | { |
80 | - $this->_connection = $conn; |
|
80 | + $this->_connection=$conn; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getTypeHandlers() |
95 | 95 | { |
96 | - if($this->_typeHandlers === null) |
|
97 | - $this->_typeHandlers = new TSqlMapTypeHandlerRegistry(); |
|
96 | + if($this->_typeHandlers===null) |
|
97 | + $this->_typeHandlers=new TSqlMapTypeHandlerRegistry(); |
|
98 | 98 | return $this->_typeHandlers; |
99 | 99 | } |
100 | 100 | |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getSqlmapGateway() |
105 | 105 | { |
106 | - if($this->_gateway === null) |
|
107 | - $this->_gateway = $this->createSqlMapGateway(); |
|
106 | + if($this->_gateway===null) |
|
107 | + $this->_gateway=$this->createSqlMapGateway(); |
|
108 | 108 | return $this->_gateway; |
109 | 109 | } |
110 | 110 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function configureXml($file) |
116 | 116 | { |
117 | - $config = new TSqlMapXmlConfiguration($this); |
|
117 | + $config=new TSqlMapXmlConfiguration($this); |
|
118 | 118 | $config->configure($file); |
119 | 119 | } |
120 | 120 | |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function getCacheDependencies() |
126 | 126 | { |
127 | - if($this->_cacheDependencies === null) |
|
128 | - $this->_cacheDependencies = new TChainedCacheDependency(); |
|
127 | + if($this->_cacheDependencies===null) |
|
128 | + $this->_cacheDependencies=new TChainedCacheDependency(); |
|
129 | 129 | |
130 | 130 | return $this->_cacheDependencies; |
131 | 131 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function getMappedStatement($name) |
158 | 158 | { |
159 | - if($this->_mappedStatements->contains($name) == false) |
|
159 | + if($this->_mappedStatements->contains($name)==false) |
|
160 | 160 | throw new TSqlMapUndefinedException('sqlmap_contains_no_statement', $name); |
161 | 161 | return $this->_mappedStatements[$name]; |
162 | 162 | } |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function addMappedStatement(IMappedStatement $statement) |
171 | 171 | { |
172 | - $key = $statement->getID(); |
|
173 | - if($this->_mappedStatements->contains($key) == true) |
|
172 | + $key=$statement->getID(); |
|
173 | + if($this->_mappedStatements->contains($key)==true) |
|
174 | 174 | throw new TSqlMapDuplicateException('sqlmap_already_contains_statement', $key); |
175 | 175 | $this->_mappedStatements->add($key, $statement); |
176 | 176 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function getResultMap($name) |
193 | 193 | { |
194 | - if($this->_resultMaps->contains($name) == false) |
|
194 | + if($this->_resultMaps->contains($name)==false) |
|
195 | 195 | throw new TSqlMapUndefinedException('sqlmap_contains_no_result_map', $name); |
196 | 196 | return $this->_resultMaps[$name]; |
197 | 197 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function addResultMap(TResultMap $result) |
204 | 204 | { |
205 | - $key = $result->getID(); |
|
206 | - if($this->_resultMaps->contains($key) == true) |
|
205 | + $key=$result->getID(); |
|
206 | + if($this->_resultMaps->contains($key)==true) |
|
207 | 207 | throw new TSqlMapDuplicateException('sqlmap_already_contains_result_map', $key); |
208 | 208 | $this->_resultMaps->add($key, $result); |
209 | 209 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function getParameterMap($name) |
225 | 225 | { |
226 | - if($this->_parameterMaps->contains($name) == false) |
|
226 | + if($this->_parameterMaps->contains($name)==false) |
|
227 | 227 | throw new TSqlMapUndefinedException('sqlmap_contains_no_parameter_map', $name); |
228 | 228 | return $this->_parameterMaps[$name]; |
229 | 229 | } |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function addParameterMap(TParameterMap $parameter) |
236 | 236 | { |
237 | - $key = $parameter->getID(); |
|
238 | - if($this->_parameterMaps->contains($key) == true) |
|
237 | + $key=$parameter->getID(); |
|
238 | + if($this->_parameterMaps->contains($key)==true) |
|
239 | 239 | throw new TSqlMapDuplicateException('sqlmap_already_contains_parameter_map', $key); |
240 | 240 | $this->_parameterMaps->add($key, $parameter); |
241 | 241 | } |
@@ -165,6 +165,7 @@ discard block |
||
165 | 165 | * placeholders, this will be the 1-indexed position of the parameter. |
166 | 166 | * @param mixed The value to bind to the parameter |
167 | 167 | * @param int SQL data type of the parameter |
168 | + * @param string $name |
|
168 | 169 | * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php |
169 | 170 | */ |
170 | 171 | public function bindValue($name, $value, $dataType = null) |
@@ -268,7 +269,7 @@ discard block |
||
268 | 269 | * Executes the SQL statement and returns the value of the first column in the first row of data. |
269 | 270 | * This is a convenient method of {@link query} when only a single scalar |
270 | 271 | * value is needed (e.g. obtaining the count of the records). |
271 | - * @return mixed the value of the first column in the first row of the query result. False is returned if there is no value. |
|
272 | + * @return string the value of the first column in the first row of the query result. False is returned if there is no value. |
|
272 | 273 | * @throws TDbException execution failed |
273 | 274 | */ |
274 | 275 | public function queryScalar() |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | class TDbCommand extends \Prado\TComponent |
46 | 46 | { |
47 | 47 | private $_connection; |
48 | - private $_text = ''; |
|
48 | + private $_text=''; |
|
49 | 49 | private $_statement; |
50 | 50 | |
51 | 51 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function __construct(TDbConnection $connection, $text) |
57 | 57 | { |
58 | - $this->_connection = $connection; |
|
58 | + $this->_connection=$connection; |
|
59 | 59 | $this->setText($text); |
60 | 60 | } |
61 | 61 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function setText($value) |
84 | 84 | { |
85 | - $this->_text = $value; |
|
85 | + $this->_text=$value; |
|
86 | 86 | $this->cancel(); |
87 | 87 | } |
88 | 88 | |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function prepare() |
114 | 114 | { |
115 | - if($this->_statement == null) |
|
115 | + if($this->_statement==null) |
|
116 | 116 | { |
117 | 117 | try |
118 | 118 | { |
119 | - $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
|
119 | + $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText()); |
|
120 | 120 | } |
121 | 121 | catch(Exception $e) |
122 | 122 | { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function cancel() |
132 | 132 | { |
133 | - $this->_statement = null; |
|
133 | + $this->_statement=null; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * @param int length of the data type |
147 | 147 | * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php |
148 | 148 | */ |
149 | - public function bindParameter($name, &$value, $dataType = null, $length = null) |
|
149 | + public function bindParameter($name, &$value, $dataType=null, $length=null) |
|
150 | 150 | { |
151 | 151 | $this->prepare(); |
152 | - if($dataType === null) |
|
152 | + if($dataType===null) |
|
153 | 153 | $this->_statement->bindParam($name, $value); |
154 | - elseif($length === null) |
|
154 | + elseif($length===null) |
|
155 | 155 | $this->_statement->bindParam($name, $value, $dataType); |
156 | 156 | else |
157 | 157 | $this->_statement->bindParam($name, $value, $dataType, $length); |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | * @param int SQL data type of the parameter |
168 | 168 | * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php |
169 | 169 | */ |
170 | - public function bindValue($name, $value, $dataType = null) |
|
170 | + public function bindValue($name, $value, $dataType=null) |
|
171 | 171 | { |
172 | 172 | $this->prepare(); |
173 | - if($dataType === null) |
|
173 | + if($dataType===null) |
|
174 | 174 | $this->_statement->bindValue($name, $value); |
175 | 175 | else |
176 | 176 | $this->_statement->bindValue($name, $value, $dataType); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | if($this->_statement instanceof PDOStatement) |
229 | 229 | $this->_statement->execute(); |
230 | 230 | else |
231 | - $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
231 | + $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
232 | 232 | return new TDbDataReader($this); |
233 | 233 | } |
234 | 234 | catch(Exception $e) |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @return array the first row of the query result, false if no result. |
246 | 246 | * @throws TDbException execution failed |
247 | 247 | */ |
248 | - public function queryRow($fetchAssociative = true) |
|
248 | + public function queryRow($fetchAssociative=true) |
|
249 | 249 | { |
250 | 250 | try |
251 | 251 | { |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | if($this->_statement instanceof PDOStatement) |
254 | 254 | $this->_statement->execute(); |
255 | 255 | else |
256 | - $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
257 | - $result = $this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
|
256 | + $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
257 | + $result=$this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
|
258 | 258 | $this->_statement->closeCursor(); |
259 | 259 | return $result; |
260 | 260 | } |
@@ -279,10 +279,10 @@ discard block |
||
279 | 279 | if($this->_statement instanceof PDOStatement) |
280 | 280 | $this->_statement->execute(); |
281 | 281 | else |
282 | - $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
|
283 | - $result = $this->_statement->fetchColumn(); |
|
282 | + $this->_statement=$this->getConnection()->getPdoInstance()->query($this->getText()); |
|
283 | + $result=$this->_statement->fetchColumn(); |
|
284 | 284 | $this->_statement->closeCursor(); |
285 | - if(is_resource($result) && get_resource_type($result) === 'stream') |
|
285 | + if(is_resource($result) && get_resource_type($result)==='stream') |
|
286 | 286 | return stream_get_contents($result); |
287 | 287 | else |
288 | 288 | return $result; |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function queryColumn() |
305 | 305 | { |
306 | - $rows = $this->query()->readAll(); |
|
307 | - $column = []; |
|
306 | + $rows=$this->query()->readAll(); |
|
307 | + $column=[]; |
|
308 | 308 | foreach($rows as $row) |
309 | - $column[] = current($row); |
|
309 | + $column[]=current($row); |
|
310 | 310 | return $column; |
311 | 311 | } |
312 | 312 | } |
@@ -117,8 +117,7 @@ discard block |
||
117 | 117 | try |
118 | 118 | { |
119 | 119 | $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
120 | - } |
|
121 | - catch(Exception $e) |
|
120 | + } catch(Exception $e) |
|
122 | 121 | { |
123 | 122 | throw new TDbException('dbcommand_prepare_failed', $e->getMessage(), $this->getText()); |
124 | 123 | } |
@@ -193,11 +192,9 @@ discard block |
||
193 | 192 | { |
194 | 193 | $this->_statement->execute(); |
195 | 194 | return $this->_statement->rowCount(); |
196 | - } |
|
197 | - else |
|
195 | + } else |
|
198 | 196 | return $this->getConnection()->getPdoInstance()->exec($this->getText()); |
199 | - } |
|
200 | - catch(Exception $e) |
|
197 | + } catch(Exception $e) |
|
201 | 198 | { |
202 | 199 | throw new TDbException('dbcommand_execute_failed', $e->getMessage(), $this->getDebugStatementText()); |
203 | 200 | } |
@@ -230,8 +227,7 @@ discard block |
||
230 | 227 | else |
231 | 228 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
232 | 229 | return new TDbDataReader($this); |
233 | - } |
|
234 | - catch(Exception $e) |
|
230 | + } catch(Exception $e) |
|
235 | 231 | { |
236 | 232 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
237 | 233 | } |
@@ -257,8 +253,7 @@ discard block |
||
257 | 253 | $result = $this->_statement->fetch($fetchAssociative ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); |
258 | 254 | $this->_statement->closeCursor(); |
259 | 255 | return $result; |
260 | - } |
|
261 | - catch(Exception $e) |
|
256 | + } catch(Exception $e) |
|
262 | 257 | { |
263 | 258 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
264 | 259 | } |
@@ -286,8 +281,7 @@ discard block |
||
286 | 281 | return stream_get_contents($result); |
287 | 282 | else |
288 | 283 | return $result; |
289 | - } |
|
290 | - catch(Exception $e) |
|
284 | + } catch(Exception $e) |
|
291 | 285 | { |
292 | 286 | throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText()); |
293 | 287 | } |
@@ -118,6 +118,7 @@ discard block |
||
118 | 118 | * It terminates the application immediately after the error is displayed. |
119 | 119 | * @param mixed sender of the event |
120 | 120 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
121 | + * @param null|\Prado\TApplication $sender |
|
121 | 122 | */ |
122 | 123 | public function handleError($sender, $param) |
123 | 124 | { |
@@ -187,6 +188,7 @@ discard block |
||
187 | 188 | * mode will be displayed to the client user. |
188 | 189 | * @param integer response status code |
189 | 190 | * @param Exception exception instance |
191 | + * @param integer $statusCode |
|
190 | 192 | */ |
191 | 193 | protected function handleExternalError($statusCode, $exception) |
192 | 194 | { |
@@ -383,6 +385,9 @@ discard block |
||
383 | 385 | return $result; |
384 | 386 | } |
385 | 387 | |
388 | + /** |
|
389 | + * @return string |
|
390 | + */ |
|
386 | 391 | private function getExactTraceAsString($exception) |
387 | 392 | { |
388 | 393 | if($exception instanceof TPhpFatalErrorException && |
@@ -410,6 +415,9 @@ discard block |
||
410 | 415 | return $exception->getTraceAsString(); |
411 | 416 | } |
412 | 417 | |
418 | + /** |
|
419 | + * @param string $pattern |
|
420 | + */ |
|
413 | 421 | private function getPropertyAccessTrace($trace, $pattern) |
414 | 422 | { |
415 | 423 | $result = null; |
@@ -442,6 +450,9 @@ discard block |
||
442 | 450 | return $source; |
443 | 451 | } |
444 | 452 | |
453 | + /** |
|
454 | + * @param string $message |
|
455 | + */ |
|
445 | 456 | private function addLink($message) { |
446 | 457 | if (null !== ($class = $this->getErrorClassNameSpace($message))) { |
447 | 458 | return str_replace($class['name'], '<a href="' . $class['url'] . '" target="_blank">' . $class['name'] . '</a>', $message); |
@@ -57,19 +57,19 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * error template file basename |
59 | 59 | */ |
60 | - const ERROR_FILE_NAME = 'error'; |
|
60 | + const ERROR_FILE_NAME='error'; |
|
61 | 61 | /** |
62 | 62 | * exception template file basename |
63 | 63 | */ |
64 | - const EXCEPTION_FILE_NAME = 'exception'; |
|
64 | + const EXCEPTION_FILE_NAME='exception'; |
|
65 | 65 | /** |
66 | 66 | * number of lines before and after the error line to be displayed in case of an exception |
67 | 67 | */ |
68 | - const SOURCE_LINES = 12; |
|
68 | + const SOURCE_LINES=12; |
|
69 | 69 | /** |
70 | 70 | * number of prado internal function calls to be dropped from stack traces on fatal errors |
71 | 71 | */ |
72 | - const FATAL_ERROR_TRACE_DROP_LINES = 5; |
|
72 | + const FATAL_ERROR_TRACE_DROP_LINES=5; |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @var string error template directory |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function getErrorTemplatePath() |
93 | 93 | { |
94 | - if($this->_templatePath === null) |
|
95 | - $this->_templatePath = Prado::getFrameworkPath() . '/Exceptions/templates'; |
|
94 | + if($this->_templatePath===null) |
|
95 | + $this->_templatePath=Prado::getFrameworkPath().'/Exceptions/templates'; |
|
96 | 96 | return $this->_templatePath; |
97 | 97 | } |
98 | 98 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function setErrorTemplatePath($value) |
106 | 106 | { |
107 | - if(($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) |
|
108 | - $this->_templatePath = $templatePath; |
|
107 | + if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) |
|
108 | + $this->_templatePath=$templatePath; |
|
109 | 109 | else |
110 | 110 | throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
111 | 111 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function handleError($sender, $param) |
123 | 123 | { |
124 | - static $handling = false; |
|
124 | + static $handling=false; |
|
125 | 125 | // We need to restore error and exception handlers, |
126 | 126 | // because within error and exception handlers, new errors and exceptions |
127 | 127 | // cannot be handled properly by PHP |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | $this->handleRecursiveError($param); |
133 | 133 | else |
134 | 134 | { |
135 | - $handling = true; |
|
136 | - if(($response = $this->getResponse()) !== null) |
|
135 | + $handling=true; |
|
136 | + if(($response=$this->getResponse())!==null) |
|
137 | 137 | $response->clear(); |
138 | 138 | if(!headers_sent()) |
139 | 139 | header('Content-Type: text/html; charset=UTF-8'); |
140 | 140 | if($param instanceof THttpException) |
141 | 141 | $this->handleExternalError($param->getStatusCode(), $param); |
142 | - elseif($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
142 | + elseif($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
143 | 143 | $this->displayException($param); |
144 | 144 | else |
145 | 145 | $this->handleExternalError(500, $param); |
@@ -153,30 +153,30 @@ discard block |
||
153 | 153 | * @return string |
154 | 154 | * @since 3.1.6 |
155 | 155 | */ |
156 | - protected static function hideSecurityRelated($value, $exception = null) |
|
156 | + protected static function hideSecurityRelated($value, $exception=null) |
|
157 | 157 | { |
158 | - $aRpl = []; |
|
159 | - if($exception !== null && $exception instanceof \Exception) |
|
158 | + $aRpl=[]; |
|
159 | + if($exception!==null && $exception instanceof \Exception) |
|
160 | 160 | { |
161 | 161 | if($exception instanceof TPhpFatalErrorException && |
162 | 162 | function_exists('xdebug_get_function_stack')) |
163 | 163 | { |
164 | - $aTrace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
164 | + $aTrace=array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
165 | 165 | } else { |
166 | - $aTrace = $exception->getTrace(); |
|
166 | + $aTrace=$exception->getTrace(); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | foreach($aTrace as $item) |
170 | 170 | { |
171 | 171 | if(isset($item['file'])) |
172 | - $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
172 | + $aRpl[dirname($item['file']).DIRECTORY_SEPARATOR]='<hidden>'.DIRECTORY_SEPARATOR; |
|
173 | 173 | } |
174 | 174 | } |
175 | - $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
|
176 | - $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
|
177 | - $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
|
175 | + $aRpl[$_SERVER['DOCUMENT_ROOT']]='${DocumentRoot}'; |
|
176 | + $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])]='${DocumentRoot}'; |
|
177 | + $aRpl[PRADO_DIR.DIRECTORY_SEPARATOR]='${PradoFramework}'.DIRECTORY_SEPARATOR; |
|
178 | 178 | if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
179 | - $aRpl = array_reverse($aRpl, true); |
|
179 | + $aRpl=array_reverse($aRpl, true); |
|
180 | 180 | |
181 | 181 | return str_replace(array_keys($aRpl), $aRpl, $value); |
182 | 182 | } |
@@ -193,21 +193,21 @@ discard block |
||
193 | 193 | if(!($exception instanceof THttpException)) |
194 | 194 | error_log($exception->__toString()); |
195 | 195 | |
196 | - $content = $this->getErrorTemplate($statusCode, $exception); |
|
196 | + $content=$this->getErrorTemplate($statusCode, $exception); |
|
197 | 197 | |
198 | - $serverAdmin = isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:''; |
|
198 | + $serverAdmin=isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : ''; |
|
199 | 199 | |
200 | - $isDebug = $this->getApplication()->getMode() === TApplicationMode::Debug; |
|
200 | + $isDebug=$this->getApplication()->getMode()===TApplicationMode::Debug; |
|
201 | 201 | |
202 | - $errorMessage = $exception->getMessage(); |
|
202 | + $errorMessage=$exception->getMessage(); |
|
203 | 203 | if($isDebug) |
204 | - $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
204 | + $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
205 | 205 | else |
206 | 206 | { |
207 | - $version = ''; |
|
208 | - $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
|
207 | + $version=''; |
|
208 | + $errorMessage=self::hideSecurityRelated($errorMessage, $exception); |
|
209 | 209 | } |
210 | - $tokens = [ |
|
210 | + $tokens=[ |
|
211 | 211 | '%%StatusCode%%' => "$statusCode", |
212 | 212 | '%%ErrorMessage%%' => htmlspecialchars($errorMessage), |
213 | 213 | '%%ServerAdmin%%' => $serverAdmin, |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | */ |
230 | 230 | protected function handleRecursiveError($exception) |
231 | 231 | { |
232 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
232 | + if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
233 | 233 | { |
234 | 234 | echo "<html><head><title>Recursive Error</title></head>\n"; |
235 | 235 | echo "<body><h1>Recursive Error</h1>\n"; |
236 | - echo "<pre>" . $exception->__toString() . "</pre>\n"; |
|
236 | + echo "<pre>".$exception->__toString()."</pre>\n"; |
|
237 | 237 | echo "</body></html>"; |
238 | 238 | } |
239 | 239 | else |
240 | 240 | { |
241 | - error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
|
241 | + error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
|
242 | 242 | header('HTTP/1.0 500 Internal Error'); |
243 | 243 | } |
244 | 244 | } |
@@ -252,53 +252,53 @@ discard block |
||
252 | 252 | */ |
253 | 253 | protected function displayException($exception) |
254 | 254 | { |
255 | - if(php_sapi_name() === 'cli') |
|
255 | + if(php_sapi_name()==='cli') |
|
256 | 256 | { |
257 | - echo $exception->getMessage() . "\n"; |
|
257 | + echo $exception->getMessage()."\n"; |
|
258 | 258 | echo $this->getExactTraceAsString($exception); |
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
262 | 262 | if($exception instanceof TTemplateException) |
263 | 263 | { |
264 | - $fileName = $exception->getTemplateFile(); |
|
265 | - $lines = empty($fileName)?explode("\n", $exception->getTemplateSource()):@file($fileName); |
|
266 | - $source = $this->getSourceCode($lines, $exception->getLineNumber()); |
|
267 | - if($fileName === '') |
|
268 | - $fileName = '---embedded template---'; |
|
269 | - $errorLine = $exception->getLineNumber(); |
|
264 | + $fileName=$exception->getTemplateFile(); |
|
265 | + $lines=empty($fileName) ?explode("\n", $exception->getTemplateSource()) : @file($fileName); |
|
266 | + $source=$this->getSourceCode($lines, $exception->getLineNumber()); |
|
267 | + if($fileName==='') |
|
268 | + $fileName='---embedded template---'; |
|
269 | + $errorLine=$exception->getLineNumber(); |
|
270 | 270 | } |
271 | 271 | else |
272 | 272 | { |
273 | - if(($trace = $this->getExactTrace($exception)) !== null) |
|
273 | + if(($trace=$this->getExactTrace($exception))!==null) |
|
274 | 274 | { |
275 | - $fileName = $trace['file']; |
|
276 | - $errorLine = $trace['line']; |
|
275 | + $fileName=$trace['file']; |
|
276 | + $errorLine=$trace['line']; |
|
277 | 277 | } |
278 | 278 | else |
279 | 279 | { |
280 | - $fileName = $exception->getFile(); |
|
281 | - $errorLine = $exception->getLine(); |
|
280 | + $fileName=$exception->getFile(); |
|
281 | + $errorLine=$exception->getLine(); |
|
282 | 282 | } |
283 | - $source = $this->getSourceCode(@file($fileName), $errorLine); |
|
283 | + $source=$this->getSourceCode(@file($fileName), $errorLine); |
|
284 | 284 | } |
285 | 285 | |
286 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
287 | - $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
286 | + if($this->getApplication()->getMode()===TApplicationMode::Debug) |
|
287 | + $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
288 | 288 | else |
289 | - $version = ''; |
|
289 | + $version=''; |
|
290 | 290 | |
291 | - $tokens = [ |
|
291 | + $tokens=[ |
|
292 | 292 | '%%ErrorType%%' => get_class($exception), |
293 | 293 | '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), |
294 | - '%%SourceFile%%' => htmlspecialchars($fileName) . ' (' . $errorLine . ')', |
|
294 | + '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')', |
|
295 | 295 | '%%SourceCode%%' => $source, |
296 | 296 | '%%StackTrace%%' => htmlspecialchars($this->getExactTraceAsString($exception)), |
297 | 297 | '%%Version%%' => $version, |
298 | 298 | '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
299 | 299 | ]; |
300 | 300 | |
301 | - $content = $this->getExceptionTemplate($exception); |
|
301 | + $content=$this->getExceptionTemplate($exception); |
|
302 | 302 | |
303 | 303 | echo strtr($content, $tokens); |
304 | 304 | } |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | */ |
313 | 313 | protected function getExceptionTemplate($exception) |
314 | 314 | { |
315 | - $lang = Prado::getPreferredLanguage(); |
|
316 | - $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '-' . $lang . '.html'; |
|
315 | + $lang=Prado::getPreferredLanguage(); |
|
316 | + $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html'; |
|
317 | 317 | if(!is_file($exceptionFile)) |
318 | - $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '.html'; |
|
319 | - if(($content = @file_get_contents($exceptionFile)) === false) |
|
318 | + $exceptionFile=Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
319 | + if(($content=@file_get_contents($exceptionFile))===false) |
|
320 | 320 | die("Unable to open exception template file '$exceptionFile'."); |
321 | 321 | return $content; |
322 | 322 | } |
@@ -339,45 +339,45 @@ discard block |
||
339 | 339 | */ |
340 | 340 | protected function getErrorTemplate($statusCode, $exception) |
341 | 341 | { |
342 | - $base = $this->getErrorTemplatePath() . DIRECTORY_SEPARATOR . self::ERROR_FILE_NAME; |
|
343 | - $lang = Prado::getPreferredLanguage(); |
|
342 | + $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
|
343 | + $lang=Prado::getPreferredLanguage(); |
|
344 | 344 | if(is_file("$base$statusCode-$lang.html")) |
345 | - $errorFile = "$base$statusCode-$lang.html"; |
|
345 | + $errorFile="$base$statusCode-$lang.html"; |
|
346 | 346 | elseif(is_file("$base$statusCode.html")) |
347 | - $errorFile = "$base$statusCode.html"; |
|
347 | + $errorFile="$base$statusCode.html"; |
|
348 | 348 | elseif(is_file("$base-$lang.html")) |
349 | - $errorFile = "$base-$lang.html"; |
|
349 | + $errorFile="$base-$lang.html"; |
|
350 | 350 | else |
351 | - $errorFile = "$base.html"; |
|
352 | - if(($content = @file_get_contents($errorFile)) === false) |
|
351 | + $errorFile="$base.html"; |
|
352 | + if(($content=@file_get_contents($errorFile))===false) |
|
353 | 353 | die("Unable to open error template file '$errorFile'."); |
354 | 354 | return $content; |
355 | 355 | } |
356 | 356 | |
357 | 357 | private function getExactTrace($exception) |
358 | 358 | { |
359 | - $result = null; |
|
359 | + $result=null; |
|
360 | 360 | if($exception instanceof TPhpFatalErrorException && |
361 | 361 | function_exists('xdebug_get_function_stack')) |
362 | 362 | { |
363 | - $trace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
363 | + $trace=array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
364 | 364 | } else { |
365 | - $trace = $exception->getTrace(); |
|
365 | + $trace=$exception->getTrace(); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | // if PHP exception, we want to show the 2nd stack level context |
369 | 369 | // because the 1st stack level is of little use (it's in error handler) |
370 | 370 | if($exception instanceof TPhpErrorException) { |
371 | 371 | if(isset($trace[0]['file'])) |
372 | - $result = $trace[0]; |
|
372 | + $result=$trace[0]; |
|
373 | 373 | elseif(isset($trace[1])) |
374 | - $result = $trace[1]; |
|
374 | + $result=$trace[1]; |
|
375 | 375 | } elseif($exception instanceof TInvalidOperationException) { |
376 | 376 | // in case of getter or setter error, find out the exact file and row |
377 | - if(($result = $this->getPropertyAccessTrace($trace, '__get')) === null) |
|
378 | - $result = $this->getPropertyAccessTrace($trace, '__set'); |
|
377 | + if(($result=$this->getPropertyAccessTrace($trace, '__get'))===null) |
|
378 | + $result=$this->getPropertyAccessTrace($trace, '__set'); |
|
379 | 379 | } |
380 | - if($result !== null && strpos($result['file'], ': eval()\'d code') !== false) |
|
380 | + if($result!==null && strpos($result['file'], ': eval()\'d code')!==false) |
|
381 | 381 | return null; |
382 | 382 | |
383 | 383 | return $result; |
@@ -388,19 +388,19 @@ discard block |
||
388 | 388 | if($exception instanceof TPhpFatalErrorException && |
389 | 389 | function_exists('xdebug_get_function_stack')) |
390 | 390 | { |
391 | - $trace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
392 | - $txt = ''; |
|
393 | - $row = 0; |
|
391 | + $trace=array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
392 | + $txt=''; |
|
393 | + $row=0; |
|
394 | 394 | |
395 | 395 | // try to mimic Exception::getTraceAsString() |
396 | 396 | foreach($trace as $line) |
397 | 397 | { |
398 | 398 | if(array_key_exists('function', $line)) |
399 | - $func = $line['function'] . '(' . implode(',', $line['params']) . ')'; |
|
399 | + $func=$line['function'].'('.implode(',', $line['params']).')'; |
|
400 | 400 | else |
401 | - $func = 'unknown'; |
|
401 | + $func='unknown'; |
|
402 | 402 | |
403 | - $txt .= '#' . $row . ' ' . $line['file'] . '(' . $line['line'] . '): ' . $func . "\n"; |
|
403 | + $txt.='#'.$row.' '.$line['file'].'('.$line['line'].'): '.$func."\n"; |
|
404 | 404 | $row++; |
405 | 405 | } |
406 | 406 | |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | |
413 | 413 | private function getPropertyAccessTrace($trace, $pattern) |
414 | 414 | { |
415 | - $result = null; |
|
415 | + $result=null; |
|
416 | 416 | foreach($trace as $t) |
417 | 417 | { |
418 | - if(isset($t['function']) && $t['function'] === $pattern) |
|
419 | - $result = $t; |
|
418 | + if(isset($t['function']) && $t['function']===$pattern) |
|
419 | + $result=$t; |
|
420 | 420 | else |
421 | 421 | break; |
422 | 422 | } |
@@ -425,44 +425,44 @@ discard block |
||
425 | 425 | |
426 | 426 | private function getSourceCode($lines, $errorLine) |
427 | 427 | { |
428 | - $beginLine = $errorLine - self::SOURCE_LINES >= 0?$errorLine - self::SOURCE_LINES:0; |
|
429 | - $endLine = $errorLine + self::SOURCE_LINES <= count($lines)?$errorLine + self::SOURCE_LINES:count($lines); |
|
428 | + $beginLine=$errorLine - self::SOURCE_LINES >= 0 ? $errorLine - self::SOURCE_LINES : 0; |
|
429 | + $endLine=$errorLine + self::SOURCE_LINES <= count($lines) ? $errorLine + self::SOURCE_LINES : count($lines); |
|
430 | 430 | |
431 | - $source = ''; |
|
432 | - for($i = $beginLine;$i < $endLine;++$i) |
|
431 | + $source=''; |
|
432 | + for($i=$beginLine; $i < $endLine; ++$i) |
|
433 | 433 | { |
434 | - if($i === $errorLine - 1) |
|
434 | + if($i===$errorLine - 1) |
|
435 | 435 | { |
436 | - $line = htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
437 | - $source .= "<div class=\"error\">" . $line . "</div>"; |
|
436 | + $line=htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
437 | + $source.="<div class=\"error\">".$line."</div>"; |
|
438 | 438 | } |
439 | 439 | else |
440 | - $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
440 | + $source.=htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
441 | 441 | } |
442 | 442 | return $source; |
443 | 443 | } |
444 | 444 | |
445 | 445 | private function addLink($message) { |
446 | - if (null !== ($class = $this->getErrorClassNameSpace($message))) { |
|
447 | - return str_replace($class['name'], '<a href="' . $class['url'] . '" target="_blank">' . $class['name'] . '</a>', $message); |
|
446 | + if(null!==($class=$this->getErrorClassNameSpace($message))) { |
|
447 | + return str_replace($class['name'], '<a href="'.$class['url'].'" target="_blank">'.$class['name'].'</a>', $message); |
|
448 | 448 | } |
449 | 449 | return $message; |
450 | 450 | } |
451 | 451 | |
452 | 452 | private function getErrorClassNameSpace($message) { |
453 | - $matches = []; |
|
453 | + $matches=[]; |
|
454 | 454 | preg_match('/\b(T[A-Z]\w+)\b/', $message, $matches); |
455 | - if (is_array($matches) && count($matches) > 0) { |
|
456 | - $class = $matches[0]; |
|
455 | + if(is_array($matches) && count($matches) > 0) { |
|
456 | + $class=$matches[0]; |
|
457 | 457 | try { |
458 | - $function = new \ReflectionClass($class); |
|
458 | + $function=new \ReflectionClass($class); |
|
459 | 459 | } |
460 | - catch (\Exception $e) { |
|
460 | + catch(\Exception $e) { |
|
461 | 461 | return null; |
462 | 462 | } |
463 | - $classname = $function->getNamespaceName(); |
|
463 | + $classname=$function->getNamespaceName(); |
|
464 | 464 | return [ |
465 | - 'url' => 'http://pradosoft.github.io/docs/manual/class-' . str_replace('\\', '.', (string) $classname) . '.' . $class . '.html', |
|
465 | + 'url' => 'http://pradosoft.github.io/docs/manual/class-'.str_replace('\\', '.', (string) $classname).'.'.$class.'.html', |
|
466 | 466 | 'name' => $class, |
467 | 467 | ]; |
468 | 468 | } |
@@ -235,8 +235,7 @@ discard block |
||
235 | 235 | echo "<body><h1>Recursive Error</h1>\n"; |
236 | 236 | echo "<pre>" . $exception->__toString() . "</pre>\n"; |
237 | 237 | echo "</body></html>"; |
238 | - } |
|
239 | - else |
|
238 | + } else |
|
240 | 239 | { |
241 | 240 | error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
242 | 241 | header('HTTP/1.0 500 Internal Error'); |
@@ -267,15 +266,13 @@ discard block |
||
267 | 266 | if($fileName === '') |
268 | 267 | $fileName = '---embedded template---'; |
269 | 268 | $errorLine = $exception->getLineNumber(); |
270 | - } |
|
271 | - else |
|
269 | + } else |
|
272 | 270 | { |
273 | 271 | if(($trace = $this->getExactTrace($exception)) !== null) |
274 | 272 | { |
275 | 273 | $fileName = $trace['file']; |
276 | 274 | $errorLine = $trace['line']; |
277 | - } |
|
278 | - else |
|
275 | + } else |
|
279 | 276 | { |
280 | 277 | $fileName = $exception->getFile(); |
281 | 278 | $errorLine = $exception->getLine(); |
@@ -435,8 +432,7 @@ discard block |
||
435 | 432 | { |
436 | 433 | $line = htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
437 | 434 | $source .= "<div class=\"error\">" . $line . "</div>"; |
438 | - } |
|
439 | - else |
|
435 | + } else |
|
440 | 436 | $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
441 | 437 | } |
442 | 438 | return $source; |
@@ -456,8 +452,7 @@ discard block |
||
456 | 452 | $class = $matches[0]; |
457 | 453 | try { |
458 | 454 | $function = new \ReflectionClass($class); |
459 | - } |
|
460 | - catch (\Exception $e) { |
|
455 | + } catch (\Exception $e) { |
|
461 | 456 | return null; |
462 | 457 | } |
463 | 458 | $classname = $function->getNamespaceName(); |
@@ -90,6 +90,7 @@ discard block |
||
90 | 90 | * Initialize a new DateFormat. |
91 | 91 | * @param mixed either, null, a CultureInfo instance, |
92 | 92 | * a DateTimeFormatInfo instance, or a locale. |
93 | + * @param string $formatInfo |
|
93 | 94 | * @return DateFormat instance |
94 | 95 | */ |
95 | 96 | public function __construct($formatInfo = null) |
@@ -109,6 +110,7 @@ discard block |
||
109 | 110 | /** |
110 | 111 | * Format a date according to the pattern. |
111 | 112 | * @param mixed the time as integer or string in strtotime format. |
113 | + * @param string $time |
|
112 | 114 | * @return string formatted date time. |
113 | 115 | */ |
114 | 116 | public function format($time, $pattern = 'F', $charset = 'UTF-8') |
@@ -181,6 +183,7 @@ discard block |
||
181 | 183 | * DateTimeFormatInfo::formatDateTime |
182 | 184 | * See the tutorial documentation for futher details on the patterns. |
183 | 185 | * @param mixed a pattern. |
186 | + * @param string $pattern |
|
184 | 187 | * @return string a pattern. |
185 | 188 | * @see DateTimeFormatInfo::formatDateTime() |
186 | 189 | */ |
@@ -271,6 +274,7 @@ discard block |
||
271 | 274 | * Any substrings, starting and ending with a single quote (') |
272 | 275 | * will be treated as a single token. |
273 | 276 | * @param string pattern. |
277 | + * @param string $pattern |
|
274 | 278 | * @return array string tokens in an array. |
275 | 279 | */ |
276 | 280 | protected function getTokens($pattern) |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | use Exception; |
24 | 24 | use Prado\Prado; |
25 | 25 | |
26 | -require_once(dirname(__FILE__) . '/DateTimeFormatInfo.php'); |
|
26 | +require_once(dirname(__FILE__).'/DateTimeFormatInfo.php'); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Get the encoding utilities |
30 | 30 | */ |
31 | -require_once(dirname(__FILE__) . '/util.php'); |
|
31 | +require_once(dirname(__FILE__).'/util.php'); |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * DateFormat class. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * A list of tokens and their function call. |
55 | 55 | * @var array |
56 | 56 | */ |
57 | - protected $tokens = [ |
|
57 | + protected $tokens=[ |
|
58 | 58 | 'G' => 'Era', |
59 | 59 | 'y' => 'Year', |
60 | 60 | 'M' => 'Month', |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * A list of methods, to be used by the token function calls. |
79 | 79 | * @var array |
80 | 80 | */ |
81 | - protected $methods = []; |
|
81 | + protected $methods=[]; |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * The DateTimeFormatInfo, containing culture specific patterns and names. |
@@ -92,18 +92,18 @@ discard block |
||
92 | 92 | * a DateTimeFormatInfo instance, or a locale. |
93 | 93 | * @return DateFormat instance |
94 | 94 | */ |
95 | - public function __construct($formatInfo = null) |
|
95 | + public function __construct($formatInfo=null) |
|
96 | 96 | { |
97 | - if($formatInfo === null) |
|
98 | - $this->formatInfo = DateTimeFormatInfo::getInvariantInfo(); |
|
97 | + if($formatInfo===null) |
|
98 | + $this->formatInfo=DateTimeFormatInfo::getInvariantInfo(); |
|
99 | 99 | elseif($formatInfo instanceof CultureInfo) |
100 | - $this->formatInfo = $formatInfo->DateTimeFormat; |
|
100 | + $this->formatInfo=$formatInfo->DateTimeFormat; |
|
101 | 101 | elseif($formatInfo instanceof DateTimeFormatInfo) |
102 | - $this->formatInfo = $formatInfo; |
|
102 | + $this->formatInfo=$formatInfo; |
|
103 | 103 | else |
104 | - $this->formatInfo = DateTimeFormatInfo::getInstance($formatInfo); |
|
104 | + $this->formatInfo=DateTimeFormatInfo::getInstance($formatInfo); |
|
105 | 105 | |
106 | - $this->methods = get_class_methods($this); |
|
106 | + $this->methods=get_class_methods($this); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,50 +111,50 @@ discard block |
||
111 | 111 | * @param mixed the time as integer or string in strtotime format. |
112 | 112 | * @return string formatted date time. |
113 | 113 | */ |
114 | - public function format($time, $pattern = 'F', $charset = 'UTF-8') |
|
114 | + public function format($time, $pattern='F', $charset='UTF-8') |
|
115 | 115 | { |
116 | - if (is_numeric($time)) //assumes unix epoch |
|
117 | - $time = floatval($time); |
|
116 | + if(is_numeric($time)) //assumes unix epoch |
|
117 | + $time=floatval($time); |
|
118 | 118 | elseif(is_string($time)) |
119 | - $time = @strtotime($time); |
|
119 | + $time=@strtotime($time); |
|
120 | 120 | |
121 | - if($pattern === null) |
|
122 | - $pattern = 'F'; |
|
121 | + if($pattern===null) |
|
122 | + $pattern='F'; |
|
123 | 123 | |
124 | - $date = new \DateTime; |
|
124 | + $date=new \DateTime; |
|
125 | 125 | $date->setTimestamp($time); |
126 | 126 | |
127 | - $pattern = $this->getPattern($pattern); |
|
127 | + $pattern=$this->getPattern($pattern); |
|
128 | 128 | |
129 | - $tokens = $this->getTokens($pattern); |
|
129 | + $tokens=$this->getTokens($pattern); |
|
130 | 130 | |
131 | - for($i = 0, $k = count($tokens); $i < $k; ++$i) |
|
131 | + for($i=0, $k=count($tokens); $i < $k; ++$i) |
|
132 | 132 | { |
133 | - $pattern = $tokens[$i]; |
|
134 | - if($pattern{0} == "'" |
|
135 | - && $pattern{strlen($pattern) - 1} == "'") |
|
133 | + $pattern=$tokens[$i]; |
|
134 | + if($pattern{0}=="'" |
|
135 | + && $pattern{strlen($pattern) - 1}=="'") |
|
136 | 136 | { |
137 | - $sub = preg_replace('/(^\')|(\'$)/', '', $pattern); |
|
138 | - $tokens[$i] = str_replace('``````', '\'', $sub); |
|
137 | + $sub=preg_replace('/(^\')|(\'$)/', '', $pattern); |
|
138 | + $tokens[$i]=str_replace('``````', '\'', $sub); |
|
139 | 139 | } |
140 | - elseif($pattern == '``````') |
|
140 | + elseif($pattern=='``````') |
|
141 | 141 | { |
142 | - $tokens[$i] = '\''; |
|
142 | + $tokens[$i]='\''; |
|
143 | 143 | } |
144 | 144 | else |
145 | 145 | { |
146 | - $function = $this->getFunctionName($pattern); |
|
147 | - if($function != null) |
|
146 | + $function=$this->getFunctionName($pattern); |
|
147 | + if($function!=null) |
|
148 | 148 | { |
149 | - $fName = 'get' . $function; |
|
149 | + $fName='get'.$function; |
|
150 | 150 | if(in_array($fName, $this->methods)) |
151 | 151 | { |
152 | - $rs = $this->$fName($date, $pattern); |
|
153 | - $tokens[$i] = $rs; |
|
152 | + $rs=$this->$fName($date, $pattern); |
|
153 | + $tokens[$i]=$rs; |
|
154 | 154 | } |
155 | 155 | else |
156 | 156 | throw new |
157 | - Exception('function ' . $function . ' not found.'); |
|
157 | + Exception('function '.$function.' not found.'); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function getPattern($pattern) |
188 | 188 | { |
189 | - if(is_array($pattern) && count($pattern) == 2) |
|
189 | + if(is_array($pattern) && count($pattern)==2) |
|
190 | 190 | { |
191 | 191 | return $this->formatInfo->formatDateTime( |
192 | 192 | $this->getPattern($pattern[0]), |
@@ -275,36 +275,36 @@ discard block |
||
275 | 275 | */ |
276 | 276 | protected function getTokens($pattern) |
277 | 277 | { |
278 | - $char = null; |
|
279 | - $tokens = []; |
|
280 | - $token = null; |
|
278 | + $char=null; |
|
279 | + $tokens=[]; |
|
280 | + $token=null; |
|
281 | 281 | |
282 | - $text = false; |
|
283 | - $pattern = preg_replace("/''/", '``````', $pattern); |
|
282 | + $text=false; |
|
283 | + $pattern=preg_replace("/''/", '``````', $pattern); |
|
284 | 284 | |
285 | - for($i = 0; $i < strlen($pattern); $i++) |
|
285 | + for($i=0; $i < strlen($pattern); $i++) |
|
286 | 286 | { |
287 | - if($char == null || $pattern{$i} == $char || $text) |
|
287 | + if($char==null || $pattern{$i}==$char || $text) |
|
288 | 288 | { |
289 | - $token .= $pattern{$i}; |
|
289 | + $token.=$pattern{$i}; |
|
290 | 290 | } |
291 | 291 | else |
292 | 292 | { |
293 | - $tokens[] = str_replace("", "'", $token); |
|
294 | - $token = $pattern{$i}; |
|
293 | + $tokens[]=str_replace("", "'", $token); |
|
294 | + $token=$pattern{$i}; |
|
295 | 295 | } |
296 | 296 | |
297 | - if($pattern{$i} == "'" && $text == false) |
|
298 | - $text = true; |
|
299 | - elseif($text && $pattern{$i} == "'" && $char == "'") |
|
300 | - $text = true; |
|
301 | - elseif($text && $char != "'" && $pattern{$i} == "'") |
|
302 | - $text = false; |
|
297 | + if($pattern{$i}=="'" && $text==false) |
|
298 | + $text=true; |
|
299 | + elseif($text && $pattern{$i}=="'" && $char=="'") |
|
300 | + $text=true; |
|
301 | + elseif($text && $char!="'" && $pattern{$i}=="'") |
|
302 | + $text=false; |
|
303 | 303 | |
304 | - $char = $pattern{$i}; |
|
304 | + $char=$pattern{$i}; |
|
305 | 305 | |
306 | 306 | } |
307 | - $tokens[] = $token; |
|
307 | + $tokens[]=$token; |
|
308 | 308 | return $tokens; |
309 | 309 | } |
310 | 310 | |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param string a pattern. |
317 | 317 | * @return string year |
318 | 318 | */ |
319 | - protected function getYear($date, $pattern = 'yyyy') |
|
319 | + protected function getYear($date, $pattern='yyyy') |
|
320 | 320 | { |
321 | 321 | switch($pattern) |
322 | 322 | { |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @param string a pattern. |
340 | 340 | * @return string month name |
341 | 341 | */ |
342 | - protected function getMonth($date, $pattern = 'M') |
|
342 | + protected function getMonth($date, $pattern='M') |
|
343 | 343 | { |
344 | 344 | switch($pattern) |
345 | 345 | { |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | * @param string a pattern. |
367 | 367 | * @return string day of the week. |
368 | 368 | */ |
369 | - protected function getDayInWeek($date, $pattern = 'EEEE') |
|
369 | + protected function getDayInWeek($date, $pattern='EEEE') |
|
370 | 370 | { |
371 | - $day = $date->format('w'); |
|
371 | + $day=$date->format('w'); |
|
372 | 372 | switch($pattern) |
373 | 373 | { |
374 | 374 | case 'E': |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * @param string a pattern. |
392 | 392 | * @return string day of the month |
393 | 393 | */ |
394 | - protected function getDay($date, $pattern = 'd') |
|
394 | + protected function getDay($date, $pattern='d') |
|
395 | 395 | { |
396 | 396 | switch($pattern) |
397 | 397 | { |
@@ -412,12 +412,12 @@ discard block |
||
412 | 412 | * @param string a pattern. |
413 | 413 | * @return string era |
414 | 414 | */ |
415 | - protected function getEra($date, $pattern = 'G') |
|
415 | + protected function getEra($date, $pattern='G') |
|
416 | 416 | { |
417 | - if($pattern != 'G') |
|
417 | + if($pattern!='G') |
|
418 | 418 | throw new Exception('The pattern for era is "G".'); |
419 | 419 | |
420 | - $year = $date->format('Y'); |
|
420 | + $year=$date->format('Y'); |
|
421 | 421 | if($year > 0) |
422 | 422 | return $this->formatInfo->getEra(1); |
423 | 423 | else |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @param string a pattern. |
432 | 432 | * @return string hours in 24 hour format. |
433 | 433 | */ |
434 | - protected function getHour24($date, $pattern = 'H') |
|
434 | + protected function getHour24($date, $pattern='H') |
|
435 | 435 | { |
436 | 436 | switch($pattern) |
437 | 437 | { |
@@ -450,13 +450,13 @@ discard block |
||
450 | 450 | * @param string a pattern. |
451 | 451 | * @return string AM or PM designator |
452 | 452 | */ |
453 | - protected function getAMPM($date, $pattern = 'a') |
|
453 | + protected function getAMPM($date, $pattern='a') |
|
454 | 454 | { |
455 | - if($pattern != 'a') |
|
455 | + if($pattern!='a') |
|
456 | 456 | throw new Exception('The pattern for AM/PM marker is "a".'); |
457 | 457 | |
458 | - $hour = $date->format('G'); |
|
459 | - $ampm = (int)($hour / 12); |
|
458 | + $hour=$date->format('G'); |
|
459 | + $ampm=(int) ($hour / 12); |
|
460 | 460 | return $this->formatInfo->AMPMMarkers[$ampm]; |
461 | 461 | } |
462 | 462 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * @param string a pattern. |
468 | 468 | * @return string hours in 12 hour format. |
469 | 469 | */ |
470 | - protected function getHour12($date, $pattern = 'h') |
|
470 | + protected function getHour12($date, $pattern='h') |
|
471 | 471 | { |
472 | 472 | switch($pattern) |
473 | 473 | { |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @param string a pattern. |
488 | 488 | * @return string minutes. |
489 | 489 | */ |
490 | - protected function getMinutes($date, $pattern = 'm') |
|
490 | + protected function getMinutes($date, $pattern='m') |
|
491 | 491 | { |
492 | 492 | switch($pattern) |
493 | 493 | { |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * @param string a pattern. |
508 | 508 | * @return string seconds |
509 | 509 | */ |
510 | - protected function getSeconds($date, $pattern = 's') |
|
510 | + protected function getSeconds($date, $pattern='s') |
|
511 | 511 | { |
512 | 512 | switch($pattern) |
513 | 513 | { |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | * @param string a pattern. |
528 | 528 | * @return string time zone |
529 | 529 | */ |
530 | - protected function getTimeZone($date, $pattern = 'z') |
|
530 | + protected function getTimeZone($date, $pattern='z') |
|
531 | 531 | { |
532 | - if($pattern != 'z') |
|
532 | + if($pattern!='z') |
|
533 | 533 | throw new Exception('The pattern for time zone is "z".'); |
534 | 534 | |
535 | 535 | return $date->format('T'); |
@@ -541,9 +541,9 @@ discard block |
||
541 | 541 | * @param string a pattern. |
542 | 542 | * @return int hours in AM/PM format. |
543 | 543 | */ |
544 | - protected function getDayInYear($date, $pattern = 'D') |
|
544 | + protected function getDayInYear($date, $pattern='D') |
|
545 | 545 | { |
546 | - if($pattern != 'D') |
|
546 | + if($pattern!='D') |
|
547 | 547 | throw new Exception('The pattern for day in year is "D".'); |
548 | 548 | |
549 | 549 | return $date->format('z'); |
@@ -555,9 +555,9 @@ discard block |
||
555 | 555 | * @param string a pattern. |
556 | 556 | * @return int day in month |
557 | 557 | */ |
558 | - protected function getDayInMonth($date, $pattern = 'FF') |
|
558 | + protected function getDayInMonth($date, $pattern='FF') |
|
559 | 559 | { |
560 | - switch ($pattern) { |
|
560 | + switch($pattern) { |
|
561 | 561 | case 'F': |
562 | 562 | return $date->format('j'); |
563 | 563 | case 'FF': |
@@ -573,9 +573,9 @@ discard block |
||
573 | 573 | * @param string a pattern. |
574 | 574 | * @return int week in year |
575 | 575 | */ |
576 | - protected function getWeekInYear($date, $pattern = 'w') |
|
576 | + protected function getWeekInYear($date, $pattern='w') |
|
577 | 577 | { |
578 | - if($pattern != 'w') |
|
578 | + if($pattern!='w') |
|
579 | 579 | throw new Exception('The pattern for week in year is "w".'); |
580 | 580 | |
581 | 581 | return $date->format('W'); |
@@ -586,12 +586,12 @@ discard block |
||
586 | 586 | * @param array getdate format. |
587 | 587 | * @return int week in month |
588 | 588 | */ |
589 | - protected function getWeekInMonth($date, $pattern = 'W') |
|
589 | + protected function getWeekInMonth($date, $pattern='W') |
|
590 | 590 | { |
591 | - if($pattern != 'W') |
|
591 | + if($pattern!='W') |
|
592 | 592 | throw new Exception('The pattern for week in month is "W".'); |
593 | 593 | |
594 | - $firstInMonth = clone($date); |
|
594 | + $firstInMonth=clone($date); |
|
595 | 595 | $firstInMonth->setDate($firstInMonth->format('Y'), $firstInMonth->format('m'), 1); |
596 | 596 | return $date->format('W') - $firstInMonth->format('W'); |
597 | 597 | } |
@@ -602,9 +602,9 @@ discard block |
||
602 | 602 | * @param string a pattern. |
603 | 603 | * @return int hours [1-24] |
604 | 604 | */ |
605 | - protected function getHourInDay($date, $pattern = 'k') |
|
605 | + protected function getHourInDay($date, $pattern='k') |
|
606 | 606 | { |
607 | - if($pattern != 'k') |
|
607 | + if($pattern!='k') |
|
608 | 608 | throw new Exception('The pattern for hour in day is "k".'); |
609 | 609 | |
610 | 610 | return $date->format('G') + 1; |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @param string a pattern. |
617 | 617 | * @return int hours in AM/PM format. |
618 | 618 | */ |
619 | - protected function getHourInAMPM($date, $pattern = 'K') |
|
619 | + protected function getHourInAMPM($date, $pattern='K') |
|
620 | 620 | { |
621 | - if($pattern != 'K') |
|
621 | + if($pattern!='K') |
|
622 | 622 | throw new Exception('The pattern for hour in AM/PM is "K".'); |
623 | 623 | |
624 | 624 | return $date->format('g') + 1; |
@@ -136,12 +136,10 @@ discard block |
||
136 | 136 | { |
137 | 137 | $sub = preg_replace('/(^\')|(\'$)/', '', $pattern); |
138 | 138 | $tokens[$i] = str_replace('``````', '\'', $sub); |
139 | - } |
|
140 | - elseif($pattern == '``````') |
|
139 | + } elseif($pattern == '``````') |
|
141 | 140 | { |
142 | 141 | $tokens[$i] = '\''; |
143 | - } |
|
144 | - else |
|
142 | + } else |
|
145 | 143 | { |
146 | 144 | $function = $this->getFunctionName($pattern); |
147 | 145 | if($function != null) |
@@ -151,8 +149,7 @@ discard block |
||
151 | 149 | { |
152 | 150 | $rs = $this->$fName($date, $pattern); |
153 | 151 | $tokens[$i] = $rs; |
154 | - } |
|
155 | - else |
|
152 | + } else |
|
156 | 153 | throw new |
157 | 154 | Exception('function ' . $function . ' not found.'); |
158 | 155 | } |
@@ -287,8 +284,7 @@ discard block |
||
287 | 284 | if($char == null || $pattern{$i} == $char || $text) |
288 | 285 | { |
289 | 286 | $token .= $pattern{$i}; |
290 | - } |
|
291 | - else |
|
287 | + } else |
|
292 | 288 | { |
293 | 289 | $tokens[] = str_replace("", "'", $token); |
294 | 290 | $token = $pattern{$i}; |
@@ -103,9 +103,7 @@ |
||
103 | 103 | * Get the data from the cache. |
104 | 104 | * @param string $catalogue The translation section. |
105 | 105 | * @param string $culture The translation locale, e.g. "en_AU". |
106 | - * @param string $filename If the source is a file, this file's modified |
|
107 | - * time is newer than the cache's modified time, no cache hit. |
|
108 | - * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
|
106 | + * @return false|string Boolean FALSE if no cache hit. Otherwise, translation |
|
109 | 107 | * table data for the specified section and locale. |
110 | 108 | */ |
111 | 109 | public function get($catalogue, $culture, $lastmodified = 0) |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | use Exception; |
14 | 14 | |
15 | -require_once(dirname(__FILE__) . '/TCache_Lite.php'); |
|
15 | +require_once(dirname(__FILE__).'/TCache_Lite.php'); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Cache the translation table into the file system. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Caceh life time, default is 1 year. |
34 | 34 | */ |
35 | - protected $lifetime = 3153600; |
|
35 | + protected $lifetime=3153600; |
|
36 | 36 | |
37 | 37 | |
38 | 38 | /** |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function __construct($cacheDir) |
43 | 43 | { |
44 | - $cacheDir = $cacheDir . '/'; |
|
44 | + $cacheDir=$cacheDir.'/'; |
|
45 | 45 | |
46 | 46 | if(!is_dir($cacheDir)) |
47 | 47 | throw new Exception( |
48 | - 'The cache directory ' . $cacheDir . ' does not exists.' . |
|
48 | + 'The cache directory '.$cacheDir.' does not exists.'. |
|
49 | 49 | 'The cache directory must be writable by the server.'); |
50 | 50 | if(!is_writable($cacheDir)) |
51 | 51 | throw new Exception( |
52 | - 'The cache directory ' . $cacheDir . ' must be writable ' . |
|
52 | + 'The cache directory '.$cacheDir.' must be writable '. |
|
53 | 53 | 'by the server.'); |
54 | 54 | |
55 | - $options = [ |
|
55 | + $options=[ |
|
56 | 56 | 'cacheDir' => $cacheDir, |
57 | 57 | 'lifeTime' => $this->getLifeTime(), |
58 | 58 | 'automaticSerialization' => true |
59 | 59 | ]; |
60 | 60 | |
61 | - $this->cache = new TCache_Lite($options); |
|
61 | + $this->cache=new TCache_Lite($options); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function setLifeTime($time) |
78 | 78 | { |
79 | - $this->lifetime = (int)$time; |
|
79 | + $this->lifetime=(int) $time; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | protected function getID($catalogue, $culture) |
88 | 88 | { |
89 | - return $catalogue . ':' . $culture; |
|
89 | + return $catalogue.':'.$culture; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | protected function getGroup($catalogue, $culture) |
98 | 98 | { |
99 | - return $catalogue . ':' . get_class($this); |
|
99 | + return $catalogue.':'.get_class($this); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -108,20 +108,20 @@ discard block |
||
108 | 108 | * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
109 | 109 | * table data for the specified section and locale. |
110 | 110 | */ |
111 | - public function get($catalogue, $culture, $lastmodified = 0) |
|
111 | + public function get($catalogue, $culture, $lastmodified=0) |
|
112 | 112 | { |
113 | - $ID = $this->getID($catalogue, $culture); |
|
114 | - $group = $this->getGroup($catalogue, $culture); |
|
113 | + $ID=$this->getID($catalogue, $culture); |
|
114 | + $group=$this->getGroup($catalogue, $culture); |
|
115 | 115 | |
116 | 116 | $this->cache->_setFileName($ID, $group); |
117 | 117 | |
118 | - $cache = $this->cache->getCacheFile(); |
|
118 | + $cache=$this->cache->getCacheFile(); |
|
119 | 119 | |
120 | - if(is_file($cache) == false) |
|
120 | + if(is_file($cache)==false) |
|
121 | 121 | return false; |
122 | 122 | |
123 | 123 | |
124 | - $lastmodified = (int)$lastmodified; |
|
124 | + $lastmodified=(int) $lastmodified; |
|
125 | 125 | |
126 | 126 | if($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
127 | 127 | return false; |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function save($data, $catalogue, $culture) |
142 | 142 | { |
143 | - $ID = $this->getID($catalogue, $culture); |
|
144 | - $group = $this->getGroup($catalogue, $culture); |
|
143 | + $ID=$this->getID($catalogue, $culture); |
|
144 | + $group=$this->getGroup($catalogue, $culture); |
|
145 | 145 | |
146 | 146 | //echo '## Cache save: "'.$ID.'" : "'.$group.'"'; |
147 | 147 | //echo "<br>\n"; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function clean($catalogue, $culture) |
158 | 158 | { |
159 | - $group = $this->getGroup($catalogue, $culture); |
|
159 | + $group=$this->getGroup($catalogue, $culture); |
|
160 | 160 | $this->cache->clean($group); |
161 | 161 | } |
162 | 162 |
@@ -199,6 +199,9 @@ discard block |
||
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | |
202 | + /** |
|
203 | + * @param string $MOFile |
|
204 | + */ |
|
202 | 205 | private function getPOFile($MOFile) |
203 | 206 | { |
204 | 207 | $filebase = substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt)); |
@@ -421,6 +424,9 @@ discard block |
||
421 | 424 | return $catalogue; |
422 | 425 | } |
423 | 426 | |
427 | + /** |
|
428 | + * @param string $catalogue |
|
429 | + */ |
|
424 | 430 | protected function createMessageTemplate($catalogue) |
425 | 431 | { |
426 | 432 | if($catalogue === null) { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * Get the Gettext class. |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__) . '/Gettext/TGettext.php'); |
|
28 | +require_once(dirname(__FILE__).'/Gettext/TGettext.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * MessageSource_gettext class. |
@@ -44,23 +44,23 @@ discard block |
||
44 | 44 | * Message data filename extension. |
45 | 45 | * @var string |
46 | 46 | */ |
47 | - protected $dataExt = '.mo'; |
|
47 | + protected $dataExt='.mo'; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * PO data filename extension |
51 | 51 | * @var string |
52 | 52 | */ |
53 | - protected $poExt = '.po'; |
|
53 | + protected $poExt='.po'; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Separator between culture name and source. |
57 | 57 | * @var string |
58 | 58 | */ |
59 | - protected $dataSeparator = '.'; |
|
59 | + protected $dataSeparator='.'; |
|
60 | 60 | |
61 | 61 | public function __construct($source) |
62 | 62 | { |
63 | - $this->source = (string)$source; |
|
63 | + $this->source=(string) $source; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | */ |
72 | 72 | protected function &loadData($filename) |
73 | 73 | { |
74 | - $mo = TGettext::factory('MO', $filename); |
|
74 | + $mo=TGettext::factory('MO', $filename); |
|
75 | 75 | $mo->load(); |
76 | - $result = $mo->toArray(); |
|
76 | + $result=$mo->toArray(); |
|
77 | 77 | |
78 | - $results = []; |
|
79 | - $count = 0; |
|
78 | + $results=[]; |
|
79 | + $count=0; |
|
80 | 80 | foreach($result['strings'] as $source => $target) |
81 | 81 | { |
82 | - $results[$source][] = $target; //target |
|
83 | - $results[$source][] = $count++; //id |
|
84 | - $results[$source][] = ''; //comments |
|
82 | + $results[$source][]=$target; //target |
|
83 | + $results[$source][]=$count++; //id |
|
84 | + $results[$source][]=''; //comments |
|
85 | 85 | } |
86 | 86 | return $results; |
87 | 87 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function getSource($variant) |
106 | 106 | { |
107 | - return $this->source . '/' . $variant; |
|
107 | + return $this->source.'/'.$variant; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -128,24 +128,24 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function getCatalogueList($catalogue) |
130 | 130 | { |
131 | - $variants = explode('_', $this->culture); |
|
132 | - $source = $catalogue . $this->dataExt; |
|
131 | + $variants=explode('_', $this->culture); |
|
132 | + $source=$catalogue.$this->dataExt; |
|
133 | 133 | |
134 | - $catalogues = [$source]; |
|
134 | + $catalogues=[$source]; |
|
135 | 135 | |
136 | - $variant = null; |
|
136 | + $variant=null; |
|
137 | 137 | |
138 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
138 | + for($i=0, $k=count($variants); $i < $k; ++$i) |
|
139 | 139 | { |
140 | 140 | if(isset($variants[$i]{0})) |
141 | 141 | { |
142 | - $variant .= ($variant)?'_' . $variants[$i]:$variants[$i]; |
|
143 | - $catalogues[] = $catalogue . $this->dataSeparator . |
|
144 | - $variant . $this->dataExt; |
|
142 | + $variant.=($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
143 | + $catalogues[]=$catalogue.$this->dataSeparator. |
|
144 | + $variant.$this->dataExt; |
|
145 | 145 | } |
146 | 146 | } |
147 | - $byDir = $this->getCatalogueByDir($catalogue); |
|
148 | - $catalogues = array_merge($byDir, array_reverse($catalogues)); |
|
147 | + $byDir=$this->getCatalogueByDir($catalogue); |
|
148 | + $catalogues=array_merge($byDir, array_reverse($catalogues)); |
|
149 | 149 | return $catalogues; |
150 | 150 | } |
151 | 151 | |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | */ |
160 | 160 | private function getCatalogueByDir($catalogue) |
161 | 161 | { |
162 | - $variants = explode('_', $this->culture); |
|
163 | - $catalogues = []; |
|
162 | + $variants=explode('_', $this->culture); |
|
163 | + $catalogues=[]; |
|
164 | 164 | |
165 | - $variant = null; |
|
165 | + $variant=null; |
|
166 | 166 | |
167 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
167 | + for($i=0, $k=count($variants); $i < $k; ++$i) |
|
168 | 168 | { |
169 | 169 | if(isset($variants[$i]{0})) |
170 | 170 | { |
171 | - $variant .= ($variant)?'_' . $variants[$i]:$variants[$i]; |
|
172 | - $catalogues[] = $variant . '/' . $catalogue . $this->dataExt; |
|
171 | + $variant.=($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
172 | + $catalogues[]=$variant.'/'.$catalogue.$this->dataExt; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | return array_reverse($catalogues); |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | * @see update() |
184 | 184 | * @see delete() |
185 | 185 | */ |
186 | - private function getVariants($catalogue = 'messages') |
|
186 | + private function getVariants($catalogue='messages') |
|
187 | 187 | { |
188 | - if($catalogue === null) { |
|
189 | - $catalogue = 'messages'; |
|
188 | + if($catalogue===null) { |
|
189 | + $catalogue='messages'; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | foreach($this->getCatalogueList($catalogue) as $variant) |
193 | 193 | { |
194 | - $file = $this->getSource($variant); |
|
195 | - $po = $this->getPOFile($file); |
|
194 | + $file=$this->getSource($variant); |
|
195 | + $po=$this->getPOFile($file); |
|
196 | 196 | if(is_file($file) || is_file($po)) |
197 | 197 | return [$variant, $file, $po]; |
198 | 198 | } |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | |
202 | 202 | private function getPOFile($MOFile) |
203 | 203 | { |
204 | - $filebase = substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt)); |
|
205 | - return $filebase . $this->poExt; |
|
204 | + $filebase=substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt)); |
|
205 | + return $filebase.$this->poExt; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -212,48 +212,48 @@ discard block |
||
212 | 212 | * @param string the catalogue to add to |
213 | 213 | * @return boolean true if saved successfuly, false otherwise. |
214 | 214 | */ |
215 | - public function save($catalogue = 'messages') |
|
215 | + public function save($catalogue='messages') |
|
216 | 216 | { |
217 | - $messages = $this->untranslated; |
|
217 | + $messages=$this->untranslated; |
|
218 | 218 | |
219 | 219 | if(count($messages) <= 0) return false; |
220 | 220 | |
221 | - $variants = $this->getVariants($catalogue); |
|
221 | + $variants=$this->getVariants($catalogue); |
|
222 | 222 | |
223 | 223 | if($variants) |
224 | - list($variant, $MOFile, $POFile) = $variants; |
|
224 | + list($variant, $MOFile, $POFile)=$variants; |
|
225 | 225 | else |
226 | - list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
|
226 | + list($variant, $MOFile, $POFile)=$this->createMessageTemplate($catalogue); |
|
227 | 227 | |
228 | - if(is_writable($MOFile) == false) |
|
228 | + if(is_writable($MOFile)==false) |
|
229 | 229 | throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
230 | - if(is_writable($POFile) == false) |
|
230 | + if(is_writable($POFile)==false) |
|
231 | 231 | throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
232 | 232 | |
233 | 233 | //set the strings as untranslated. |
234 | - $strings = []; |
|
234 | + $strings=[]; |
|
235 | 235 | foreach($messages as $message) |
236 | - $strings[$message] = ''; |
|
236 | + $strings[$message]=''; |
|
237 | 237 | |
238 | 238 | //load the PO |
239 | - $po = TGettext::factory('PO', $POFile); |
|
239 | + $po=TGettext::factory('PO', $POFile); |
|
240 | 240 | $po->load(); |
241 | - $result = $po->toArray(); |
|
241 | + $result=$po->toArray(); |
|
242 | 242 | |
243 | - $existing = count($result['strings']); |
|
243 | + $existing=count($result['strings']); |
|
244 | 244 | |
245 | 245 | //add to strings to the existing message list |
246 | - $result['strings'] = array_merge($result['strings'], $strings); |
|
246 | + $result['strings']=array_merge($result['strings'], $strings); |
|
247 | 247 | |
248 | - $new = count($result['strings']); |
|
248 | + $new=count($result['strings']); |
|
249 | 249 | |
250 | 250 | if($new > $existing) |
251 | 251 | { |
252 | 252 | //change the date 2004-12-25 12:26 |
253 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
253 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
254 | 254 | |
255 | 255 | $po->fromArray($result); |
256 | - $mo = $po->toMO(); |
|
256 | + $mo=$po->toMO(); |
|
257 | 257 | if($po->save() && $mo->save($MOFile)) |
258 | 258 | { |
259 | 259 | if(!empty($this->cache)) |
@@ -272,32 +272,32 @@ discard block |
||
272 | 272 | * @param string the catalogue to delete from. |
273 | 273 | * @return boolean true if deleted, false otherwise. |
274 | 274 | */ |
275 | - public function delete($message, $catalogue = 'messages') |
|
275 | + public function delete($message, $catalogue='messages') |
|
276 | 276 | { |
277 | - $variants = $this->getVariants($catalogue); |
|
277 | + $variants=$this->getVariants($catalogue); |
|
278 | 278 | if($variants) |
279 | - list($variant, $MOFile, $POFile) = $variants; |
|
279 | + list($variant, $MOFile, $POFile)=$variants; |
|
280 | 280 | else |
281 | 281 | return false; |
282 | 282 | |
283 | - if(is_writable($MOFile) == false) |
|
283 | + if(is_writable($MOFile)==false) |
|
284 | 284 | throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
285 | - if(is_writable($POFile) == false) |
|
285 | + if(is_writable($POFile)==false) |
|
286 | 286 | throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
287 | 287 | |
288 | - $po = TGettext::factory('PO', $POFile); |
|
288 | + $po=TGettext::factory('PO', $POFile); |
|
289 | 289 | $po->load(); |
290 | - $result = $po->toArray(); |
|
290 | + $result=$po->toArray(); |
|
291 | 291 | |
292 | 292 | foreach($result['strings'] as $string => $value) |
293 | 293 | { |
294 | - if($string == $message) |
|
294 | + if($string==$message) |
|
295 | 295 | { |
296 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
296 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
297 | 297 | unset($result['strings'][$string]); |
298 | 298 | |
299 | 299 | $po->fromArray($result); |
300 | - $mo = $po->toMO(); |
|
300 | + $mo=$po->toMO(); |
|
301 | 301 | if($po->save() && $mo->save($MOFile)) |
302 | 302 | { |
303 | 303 | if(!empty($this->cache)) |
@@ -320,33 +320,33 @@ discard block |
||
320 | 320 | * @param string the catalogue of the translation. |
321 | 321 | * @return boolean true if translation was updated, false otherwise. |
322 | 322 | */ |
323 | - public function update($text, $target, $comments, $catalogue = 'messages') |
|
323 | + public function update($text, $target, $comments, $catalogue='messages') |
|
324 | 324 | { |
325 | - $variants = $this->getVariants($catalogue); |
|
325 | + $variants=$this->getVariants($catalogue); |
|
326 | 326 | if($variants) |
327 | - list($variant, $MOFile, $POFile) = $variants; |
|
327 | + list($variant, $MOFile, $POFile)=$variants; |
|
328 | 328 | else |
329 | 329 | return false; |
330 | 330 | |
331 | - if(is_writable($MOFile) == false) |
|
331 | + if(is_writable($MOFile)==false) |
|
332 | 332 | throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
333 | - if(is_writable($POFile) == false) |
|
333 | + if(is_writable($POFile)==false) |
|
334 | 334 | throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
335 | 335 | |
336 | 336 | |
337 | - $po = TGettext::factory('PO', $POFile); |
|
337 | + $po=TGettext::factory('PO', $POFile); |
|
338 | 338 | $po->load(); |
339 | - $result = $po->toArray(); |
|
339 | + $result=$po->toArray(); |
|
340 | 340 | |
341 | 341 | foreach($result['strings'] as $string => $value) |
342 | 342 | { |
343 | - if($string == $text) |
|
343 | + if($string==$text) |
|
344 | 344 | { |
345 | - $result['strings'][$string] = $target; |
|
346 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
345 | + $result['strings'][$string]=$target; |
|
346 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
347 | 347 | |
348 | 348 | $po->fromArray($result); |
349 | - $mo = $po->toMO(); |
|
349 | + $mo=$po->toMO(); |
|
350 | 350 | |
351 | 351 | if($po->save() && $mo->save($MOFile)) |
352 | 352 | { |
@@ -378,42 +378,42 @@ discard block |
||
378 | 378 | * E.g. array('messages','en_AU') |
379 | 379 | * @return array list of catalogues |
380 | 380 | */ |
381 | - protected function getCatalogues($dir = null, $variant = null) |
|
381 | + protected function getCatalogues($dir=null, $variant=null) |
|
382 | 382 | { |
383 | - $dir = $dir?$dir:$this->source; |
|
384 | - $files = scandir($dir); |
|
383 | + $dir=$dir ? $dir : $this->source; |
|
384 | + $files=scandir($dir); |
|
385 | 385 | |
386 | - $catalogue = []; |
|
386 | + $catalogue=[]; |
|
387 | 387 | |
388 | 388 | foreach($files as $file) |
389 | 389 | { |
390 | - if(is_dir($dir . '/' . $file) |
|
390 | + if(is_dir($dir.'/'.$file) |
|
391 | 391 | && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) |
392 | 392 | { |
393 | 393 | |
394 | - $catalogue = array_merge($catalogue, |
|
395 | - $this->getCatalogues($dir . '/' . $file, $file)); |
|
394 | + $catalogue=array_merge($catalogue, |
|
395 | + $this->getCatalogues($dir.'/'.$file, $file)); |
|
396 | 396 | } |
397 | 397 | |
398 | - $pos = strpos($file, $this->dataExt); |
|
398 | + $pos=strpos($file, $this->dataExt); |
|
399 | 399 | |
400 | 400 | if($pos > 0 |
401 | - && substr($file, -1 * strlen($this->dataExt)) == $this->dataExt) |
|
401 | + && substr($file, -1 * strlen($this->dataExt))==$this->dataExt) |
|
402 | 402 | { |
403 | - $name = substr($file, 0, $pos); |
|
404 | - $dot = strrpos($name, $this->dataSeparator); |
|
405 | - $culture = $variant; |
|
406 | - $cat = $name; |
|
403 | + $name=substr($file, 0, $pos); |
|
404 | + $dot=strrpos($name, $this->dataSeparator); |
|
405 | + $culture=$variant; |
|
406 | + $cat=$name; |
|
407 | 407 | if(is_int($dot)) |
408 | 408 | { |
409 | - $culture = substr($name, $dot + 1, strlen($name)); |
|
410 | - $cat = substr($name, 0, $dot); |
|
409 | + $culture=substr($name, $dot + 1, strlen($name)); |
|
410 | + $cat=substr($name, 0, $dot); |
|
411 | 411 | } |
412 | - $details[0] = $cat; |
|
413 | - $details[1] = $culture; |
|
412 | + $details[0]=$cat; |
|
413 | + $details[1]=$culture; |
|
414 | 414 | |
415 | 415 | |
416 | - $catalogue[] = $details; |
|
416 | + $catalogue[]=$details; |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | sort($catalogue); |
@@ -423,15 +423,15 @@ discard block |
||
423 | 423 | |
424 | 424 | protected function createMessageTemplate($catalogue) |
425 | 425 | { |
426 | - if($catalogue === null) { |
|
427 | - $catalogue = 'messages'; |
|
426 | + if($catalogue===null) { |
|
427 | + $catalogue='messages'; |
|
428 | 428 | } |
429 | - $variants = $this->getCatalogueList($catalogue); |
|
430 | - $variant = array_shift($variants); |
|
431 | - $mo_file = $this->getSource($variant); |
|
432 | - $po_file = $this->getPOFile($mo_file); |
|
429 | + $variants=$this->getCatalogueList($catalogue); |
|
430 | + $variant=array_shift($variants); |
|
431 | + $mo_file=$this->getSource($variant); |
|
432 | + $po_file=$this->getPOFile($mo_file); |
|
433 | 433 | |
434 | - $dir = dirname($mo_file); |
|
434 | + $dir=dirname($mo_file); |
|
435 | 435 | if(!is_dir($dir)) |
436 | 436 | { |
437 | 437 | @mkdir($dir); |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | if(!is_dir($dir)) |
441 | 441 | throw new TException("Unable to create directory $dir"); |
442 | 442 | |
443 | - $po = TGettext::factory('PO', $po_file); |
|
444 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
445 | - $result['strings'] = []; |
|
443 | + $po=TGettext::factory('PO', $po_file); |
|
444 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
445 | + $result['strings']=[]; |
|
446 | 446 | |
447 | 447 | $po->fromArray($result); |
448 | - $mo = $po->toMO(); |
|
448 | + $mo=$po->toMO(); |
|
449 | 449 | if($po->save() && $mo->save($mo_file)) |
450 | 450 | return [$variant, $mo_file, $po_file]; |
451 | 451 | else |
@@ -86,6 +86,7 @@ discard block |
||
86 | 86 | * a CultureInfo or NumberFormatInfo instance will instantiated a instance |
87 | 87 | * for that particular culture. |
88 | 88 | * @param mixed either null, a CultureInfo, a NumberFormatInfo, or string |
89 | + * @param string $formatInfo |
|
89 | 90 | * @return NumberFormat |
90 | 91 | */ |
91 | 92 | public function __construct($formatInfo = null) |
@@ -111,6 +112,7 @@ discard block |
||
111 | 112 | * 3 decimal places. |
112 | 113 | * @param string 3-letter ISO 4217 code. For example, the code |
113 | 114 | * "USD" represents the US Dollar and "EUR" represents the Euro currency. |
115 | + * @param string $number |
|
114 | 116 | * @return string formatted number string |
115 | 117 | */ |
116 | 118 | public function format($number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8') |
@@ -232,7 +234,7 @@ discard block |
||
232 | 234 | |
233 | 235 | /** |
234 | 236 | * Format the decimal places. |
235 | - * @param string the decimal number in string form. |
|
237 | + * @param string string decimal number in string form. |
|
236 | 238 | * @return string formatted decimal places. |
237 | 239 | */ |
238 | 240 | protected function formatDecimal($string) |
@@ -280,6 +282,7 @@ discard block |
||
280 | 282 | * Set the pattern to format against. The default patterns |
281 | 283 | * are retrieved from the NumberFormatInfo instance. |
282 | 284 | * @param string the requested patterns. |
285 | + * @param string $pattern |
|
283 | 286 | * @return string a number format pattern. |
284 | 287 | */ |
285 | 288 | protected function setPattern($pattern) |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Get the NumberFormatInfo class file. |
23 | 23 | */ |
24 | -require_once(dirname(__FILE__) . '/NumberFormatInfo.php'); |
|
24 | +require_once(dirname(__FILE__).'/NumberFormatInfo.php'); |
|
25 | 25 | |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Get the encoding utilities |
29 | 29 | */ |
30 | -require_once(dirname(__FILE__) . '/util.php'); |
|
30 | +require_once(dirname(__FILE__).'/util.php'); |
|
31 | 31 | |
32 | 32 | |
33 | 33 | /** |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | * @param mixed either null, a CultureInfo, a NumberFormatInfo, or string |
89 | 89 | * @return NumberFormat |
90 | 90 | */ |
91 | - public function __construct($formatInfo = null) |
|
91 | + public function __construct($formatInfo=null) |
|
92 | 92 | { |
93 | - if($formatInfo === null) |
|
94 | - $this->formatInfo = NumberFormatInfo::getInvariantInfo(); |
|
93 | + if($formatInfo===null) |
|
94 | + $this->formatInfo=NumberFormatInfo::getInvariantInfo(); |
|
95 | 95 | elseif($formatInfo instanceof CultureInfo) |
96 | - $this->formatInfo = $formatInfo->NumberFormat; |
|
96 | + $this->formatInfo=$formatInfo->NumberFormat; |
|
97 | 97 | elseif($formatInfo instanceof NumberFormatInfo) |
98 | - $this->formatInfo = $formatInfo; |
|
98 | + $this->formatInfo=$formatInfo; |
|
99 | 99 | else |
100 | - $this->formatInfo = |
|
100 | + $this->formatInfo= |
|
101 | 101 | NumberFormatInfo::getInstance($formatInfo); |
102 | 102 | } |
103 | 103 | |
@@ -113,44 +113,44 @@ discard block |
||
113 | 113 | * "USD" represents the US Dollar and "EUR" represents the Euro currency. |
114 | 114 | * @return string formatted number string |
115 | 115 | */ |
116 | - public function format($number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8') |
|
116 | + public function format($number, $pattern='d', $currency='USD', $charset='UTF-8') |
|
117 | 117 | { |
118 | - $oldLocale = setLocale(LC_NUMERIC, '0'); |
|
118 | + $oldLocale=setLocale(LC_NUMERIC, '0'); |
|
119 | 119 | setlocale(LC_NUMERIC, 'C'); |
120 | 120 | |
121 | 121 | $this->setPattern($pattern); |
122 | 122 | |
123 | - if(strtolower($pattern) == 'p') |
|
124 | - $number = $number * 100; |
|
123 | + if(strtolower($pattern)=='p') |
|
124 | + $number=$number * 100; |
|
125 | 125 | |
126 | - $string = (string)$number; |
|
126 | + $string=(string) $number; |
|
127 | 127 | |
128 | - $decimal = $this->formatDecimal($string); |
|
129 | - $integer = $this->formatInteger(abs($number)); |
|
128 | + $decimal=$this->formatDecimal($string); |
|
129 | + $integer=$this->formatInteger(abs($number)); |
|
130 | 130 | |
131 | 131 | if(strlen($decimal) > 0) |
132 | - $result = $integer . $decimal; |
|
132 | + $result=$integer.$decimal; |
|
133 | 133 | else |
134 | - $result = $integer; |
|
134 | + $result=$integer; |
|
135 | 135 | |
136 | 136 | //get the suffix |
137 | 137 | if($number >= 0) |
138 | - $suffix = $this->formatInfo->PositivePattern; |
|
138 | + $suffix=$this->formatInfo->PositivePattern; |
|
139 | 139 | elseif($number < 0) |
140 | - $suffix = $this->formatInfo->NegativePattern; |
|
140 | + $suffix=$this->formatInfo->NegativePattern; |
|
141 | 141 | else |
142 | - $suffix = ["",""]; |
|
142 | + $suffix=["", ""]; |
|
143 | 143 | |
144 | 144 | //append and prepend suffix |
145 | - $result = $suffix[0] . $result . $suffix[1]; |
|
145 | + $result=$suffix[0].$result.$suffix[1]; |
|
146 | 146 | |
147 | 147 | //replace currency sign |
148 | - $symbol = @$this->formatInfo->getCurrencySymbol($currency); |
|
149 | - if($symbol === null) { |
|
150 | - $symbol = $currency; |
|
148 | + $symbol=@$this->formatInfo->getCurrencySymbol($currency); |
|
149 | + if($symbol===null) { |
|
150 | + $symbol=$currency; |
|
151 | 151 | } |
152 | 152 | |
153 | - $result = str_replace('¤', $symbol, $result); |
|
153 | + $result=str_replace('¤', $symbol, $result); |
|
154 | 154 | |
155 | 155 | setlocale(LC_NUMERIC, $oldLocale); |
156 | 156 | |
@@ -164,68 +164,68 @@ discard block |
||
164 | 164 | */ |
165 | 165 | protected function formatInteger($string) |
166 | 166 | { |
167 | - $string = (string)$string; |
|
167 | + $string=(string) $string; |
|
168 | 168 | |
169 | - $decimalDigits = $this->formatInfo->DecimalDigits; |
|
169 | + $decimalDigits=$this->formatInfo->DecimalDigits; |
|
170 | 170 | //if not decimal digits, assume 0 decimal points. |
171 | 171 | if(is_int($decimalDigits) && $decimalDigits > 0) |
172 | - $string = (string)round(floatval($string), $decimalDigits); |
|
173 | - $dp = strpos($string, '.'); |
|
172 | + $string=(string) round(floatval($string), $decimalDigits); |
|
173 | + $dp=strpos($string, '.'); |
|
174 | 174 | if(is_int($dp)) |
175 | - $string = substr($string, 0, $dp); |
|
176 | - $integer = ''; |
|
175 | + $string=substr($string, 0, $dp); |
|
176 | + $integer=''; |
|
177 | 177 | |
178 | - $digitSize = $this->formatInfo->getDigitSize(); |
|
178 | + $digitSize=$this->formatInfo->getDigitSize(); |
|
179 | 179 | |
180 | - $string = str_pad($string, $digitSize, '0', STR_PAD_LEFT); |
|
180 | + $string=str_pad($string, $digitSize, '0', STR_PAD_LEFT); |
|
181 | 181 | |
182 | - $len = strlen($string); |
|
182 | + $len=strlen($string); |
|
183 | 183 | |
184 | - $groupSeparator = $this->formatInfo->GroupSeparator; |
|
185 | - $groupSize = $this->formatInfo->GroupSizes; |
|
184 | + $groupSeparator=$this->formatInfo->GroupSeparator; |
|
185 | + $groupSize=$this->formatInfo->GroupSizes; |
|
186 | 186 | |
187 | 187 | |
188 | - $firstGroup = true; |
|
189 | - $multiGroup = is_int($groupSize[1]); |
|
190 | - $count = 0; |
|
188 | + $firstGroup=true; |
|
189 | + $multiGroup=is_int($groupSize[1]); |
|
190 | + $count=0; |
|
191 | 191 | |
192 | 192 | if(is_int($groupSize[0])) |
193 | 193 | { |
194 | 194 | //now for the integer groupings |
195 | - for($i = 0; $i < $len; $i++) |
|
195 | + for($i=0; $i < $len; $i++) |
|
196 | 196 | { |
197 | - $char = $string{$len - $i - 1}; |
|
197 | + $char=$string{$len - $i - 1}; |
|
198 | 198 | |
199 | - if($multiGroup && $count == 0) |
|
199 | + if($multiGroup && $count==0) |
|
200 | 200 | { |
201 | - if($i != 0 && $i % $groupSize[0] == 0) |
|
201 | + if($i!=0 && $i % $groupSize[0]==0) |
|
202 | 202 | { |
203 | - $integer = $groupSeparator . $integer; |
|
203 | + $integer=$groupSeparator.$integer; |
|
204 | 204 | $count++; |
205 | 205 | } |
206 | 206 | } |
207 | 207 | elseif($multiGroup && $count >= 1) |
208 | 208 | { |
209 | - if($i != 0 && ($i - $groupSize[0]) % $groupSize[1] == 0) |
|
209 | + if($i!=0 && ($i - $groupSize[0]) % $groupSize[1]==0) |
|
210 | 210 | { |
211 | - $integer = $groupSeparator . $integer; |
|
211 | + $integer=$groupSeparator.$integer; |
|
212 | 212 | $count++; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | else |
216 | 216 | { |
217 | - if($i != 0 && $i % $groupSize[0] == 0) |
|
217 | + if($i!=0 && $i % $groupSize[0]==0) |
|
218 | 218 | { |
219 | - $integer = $groupSeparator . $integer; |
|
219 | + $integer=$groupSeparator.$integer; |
|
220 | 220 | $count++; |
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - $integer = $char . $integer; |
|
224 | + $integer=$char.$integer; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | else |
228 | - $integer = $string; |
|
228 | + $integer=$string; |
|
229 | 229 | |
230 | 230 | return $integer; |
231 | 231 | } |
@@ -237,41 +237,41 @@ discard block |
||
237 | 237 | */ |
238 | 238 | protected function formatDecimal($string) |
239 | 239 | { |
240 | - $dp = strpos($string, '.'); |
|
241 | - $decimal = ''; |
|
240 | + $dp=strpos($string, '.'); |
|
241 | + $decimal=''; |
|
242 | 242 | |
243 | - $decimalDigits = $this->formatInfo->DecimalDigits; |
|
244 | - $decimalSeparator = $this->formatInfo->DecimalSeparator; |
|
243 | + $decimalDigits=$this->formatInfo->DecimalDigits; |
|
244 | + $decimalSeparator=$this->formatInfo->DecimalSeparator; |
|
245 | 245 | |
246 | 246 | //do the correct rounding here |
247 | 247 | //$string = round(floatval($string), $decimalDigits); |
248 | 248 | if(is_int($dp)) |
249 | 249 | { |
250 | - if($decimalDigits == -1) |
|
250 | + if($decimalDigits==-1) |
|
251 | 251 | { |
252 | - $decimal = substr($string, $dp + 1); |
|
252 | + $decimal=substr($string, $dp + 1); |
|
253 | 253 | } |
254 | 254 | elseif(is_int($decimalDigits)) |
255 | 255 | { |
256 | - $float = round((float)$string, $decimalDigits); |
|
257 | - if(strpos((string)$float, '.') === false) |
|
256 | + $float=round((float) $string, $decimalDigits); |
|
257 | + if(strpos((string) $float, '.')===false) |
|
258 | 258 | { |
259 | - $decimal = str_pad($decimal, $decimalDigits, '0'); |
|
259 | + $decimal=str_pad($decimal, $decimalDigits, '0'); |
|
260 | 260 | } |
261 | 261 | else |
262 | 262 | { |
263 | - $decimal = substr($float, strpos($float, '.') + 1); |
|
263 | + $decimal=substr($float, strpos($float, '.') + 1); |
|
264 | 264 | if(strlen($decimal) < $decimalDigits) |
265 | - $decimal = str_pad($decimal, $decimalDigits, '0'); |
|
265 | + $decimal=str_pad($decimal, $decimalDigits, '0'); |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | else |
269 | 269 | return $decimal; |
270 | 270 | |
271 | - return $decimalSeparator . $decimal; |
|
271 | + return $decimalSeparator.$decimal; |
|
272 | 272 | } |
273 | - elseif ($decimalDigits > 0) |
|
274 | - return $decimalSeparator . str_pad($decimal, $decimalDigits, '0'); |
|
273 | + elseif($decimalDigits > 0) |
|
274 | + return $decimalSeparator.str_pad($decimal, $decimalDigits, '0'); |
|
275 | 275 | |
276 | 276 | return $decimal; |
277 | 277 | } |
@@ -203,16 +203,14 @@ discard block |
||
203 | 203 | $integer = $groupSeparator . $integer; |
204 | 204 | $count++; |
205 | 205 | } |
206 | - } |
|
207 | - elseif($multiGroup && $count >= 1) |
|
206 | + } elseif($multiGroup && $count >= 1) |
|
208 | 207 | { |
209 | 208 | if($i != 0 && ($i - $groupSize[0]) % $groupSize[1] == 0) |
210 | 209 | { |
211 | 210 | $integer = $groupSeparator . $integer; |
212 | 211 | $count++; |
213 | 212 | } |
214 | - } |
|
215 | - else |
|
213 | + } else |
|
216 | 214 | { |
217 | 215 | if($i != 0 && $i % $groupSize[0] == 0) |
218 | 216 | { |
@@ -223,8 +221,7 @@ discard block |
||
223 | 221 | |
224 | 222 | $integer = $char . $integer; |
225 | 223 | } |
226 | - } |
|
227 | - else |
|
224 | + } else |
|
228 | 225 | $integer = $string; |
229 | 226 | |
230 | 227 | return $integer; |
@@ -250,27 +247,23 @@ discard block |
||
250 | 247 | if($decimalDigits == -1) |
251 | 248 | { |
252 | 249 | $decimal = substr($string, $dp + 1); |
253 | - } |
|
254 | - elseif(is_int($decimalDigits)) |
|
250 | + } elseif(is_int($decimalDigits)) |
|
255 | 251 | { |
256 | 252 | $float = round((float)$string, $decimalDigits); |
257 | 253 | if(strpos((string)$float, '.') === false) |
258 | 254 | { |
259 | 255 | $decimal = str_pad($decimal, $decimalDigits, '0'); |
260 | - } |
|
261 | - else |
|
256 | + } else |
|
262 | 257 | { |
263 | 258 | $decimal = substr($float, strpos($float, '.') + 1); |
264 | 259 | if(strlen($decimal) < $decimalDigits) |
265 | 260 | $decimal = str_pad($decimal, $decimalDigits, '0'); |
266 | 261 | } |
267 | - } |
|
268 | - else |
|
262 | + } else |
|
269 | 263 | return $decimal; |
270 | 264 | |
271 | 265 | return $decimalSeparator . $decimal; |
272 | - } |
|
273 | - elseif ($decimalDigits > 0) |
|
266 | + } elseif ($decimalDigits > 0) |
|
274 | 267 | return $decimalSeparator . str_pad($decimal, $decimalDigits, '0'); |
275 | 268 | |
276 | 269 | return $decimal; |