1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use POData\UriProcessor\ResourcePathProcessor\SegmentParser\KeyDescriptor; |
4
|
|
|
use POData\Providers\Metadata\ResourceSet; |
5
|
|
|
use POData\Providers\Metadata\ResourceProperty; |
6
|
|
|
use POData\Providers\Query\IQueryProvider; |
7
|
|
|
require_once "WordPressMetadata.php"; |
8
|
|
|
require_once "POData\Providers\Query\IDataServiceQueryProvider2.php"; |
9
|
|
|
|
10
|
|
|
/** The name of the database for WordPress */ |
11
|
|
|
define('DB_NAME', 'wordpress'); |
12
|
|
|
|
13
|
|
|
/** MySQL database username */ |
14
|
|
|
define('DB_USER', 'root'); |
15
|
|
|
|
16
|
|
|
/** MySQL database password */ |
17
|
|
|
define('DB_PASSWORD', 'root'); |
18
|
|
|
|
19
|
|
|
/** MySQL hostname */ |
20
|
|
|
define('DB_HOST', 'localhost'); |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class WordPressQueryProvider implements IQueryProvider |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Handle to connection to Database |
27
|
|
|
*/ |
28
|
|
|
private $_connectionHandle = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Reference to the custom expression provider |
32
|
|
|
* |
33
|
|
|
* @var NorthWindDSExpressionProvider |
34
|
|
|
*/ |
35
|
|
|
private $_wordPressMySQLExpressionProvider; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Constructs a new instance of WordPressQueryProvider |
39
|
|
|
* |
40
|
|
|
*/ |
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
$this->_connectionHandle = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true); |
44
|
|
|
if ( $this->_connectionHandle ) { |
|
|
|
|
45
|
|
|
} else { |
46
|
|
|
die(print_r(mysql_error(), true)); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
mysql_select_db(DB_NAME, $this->_connectionHandle); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* (non-PHPdoc) |
54
|
|
|
* @see POData\Providers\Query.IQueryProvider::canApplyQueryOptions() |
55
|
|
|
*/ |
56
|
|
|
public function handlesOrderedPaging() |
57
|
|
|
{ |
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* (non-PHPdoc) |
63
|
|
|
* @see POData\Providers\Query.IQueryProvider::getExpressionProvider() |
64
|
|
|
*/ |
65
|
|
|
public function getExpressionProvider() |
66
|
|
|
{ |
67
|
|
|
if (is_null($this->_wordPressMySQLExpressionProvider)) { |
68
|
|
|
$this->_wordPressMySQLExpressionProvider = new WordPressDSExpressionProvider(); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->_wordPressMySQLExpressionProvider; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Gets collection of entities belongs to an entity set |
76
|
|
|
* |
77
|
|
|
* @param ResourceSet $resourceSet The entity set whose |
78
|
|
|
* entities needs to be fetched |
79
|
|
|
* @param string $filterOption Contains the filter condition |
|
|
|
|
80
|
|
|
* @param string $select For future purpose,no need to pass it |
81
|
|
|
* @param string $orderby For future purpose,no need to pass it |
82
|
|
|
* @param string $top For future purpose,no need to pass it |
83
|
|
|
* @param string $skip For future purpose,no need to pass it |
84
|
|
|
* |
85
|
|
|
* @return array(Object) |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
public function getResourceSet(ResourceSet $resourceSet,$filter=null,$select=null,$orderby=null,$top=null,$skip=null) |
88
|
|
|
{ |
89
|
|
|
$resourceSetName = $resourceSet->getName(); |
90
|
|
View Code Duplication |
if ($resourceSetName !== 'Posts' |
|
|
|
|
91
|
|
|
&& $resourceSetName !== 'Tags' |
92
|
|
|
&& $resourceSetName !== 'Categories' |
93
|
|
|
&& $resourceSetName !== 'Comments' |
94
|
|
|
&& $resourceSetName !== 'Users' |
95
|
|
|
) { |
96
|
|
|
die('(WordPressQueryProvider) Unknown resource set ' . $resourceSetName); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
$returnResult = array(); |
101
|
|
|
switch ($resourceSetName) { |
102
|
|
|
case 'Posts': |
103
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
104
|
|
|
." wp_posts.post_type = 'post'" |
105
|
|
|
." AND wp_posts.post_status = 'publish'"; |
106
|
|
|
if ($filter !== null) { |
107
|
|
|
$query .= " AND $filter"; |
108
|
|
|
} |
109
|
|
|
$stmt = mysql_query($query); |
110
|
|
|
$returnResult = $this->_serializePosts($stmt); |
111
|
|
|
break; |
112
|
|
View Code Duplication |
case 'Tags': |
|
|
|
|
113
|
|
|
$query = "SELECT t.*, tt.description" |
114
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
115
|
|
|
." ON tt.term_id = t.term_id" |
116
|
|
|
." WHERE tt.taxonomy = 'post_tag'"; |
117
|
|
|
if ($filter !== null) { |
118
|
|
|
$query .= " AND $filter"; |
119
|
|
|
} |
120
|
|
|
$stmt = mysql_query($query); |
121
|
|
|
$returnResult = $this->_serializeTags($stmt); |
122
|
|
|
break; |
123
|
|
View Code Duplication |
case 'Categories': |
|
|
|
|
124
|
|
|
$query = "SELECT t.*, tt.description" |
125
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
126
|
|
|
." ON tt.term_id = t.term_id" |
127
|
|
|
." WHERE tt.taxonomy = 'category'"; |
128
|
|
|
if ($filter !== null) { |
129
|
|
|
$query .= " AND $filter"; |
130
|
|
|
} |
131
|
|
|
$stmt = mysql_query($query); |
132
|
|
|
$returnResult = $this->_serializeCategories($stmt); |
133
|
|
|
break; |
134
|
|
|
case 'Comments': |
135
|
|
|
$query = "SELECT * FROM `wp_comments` WHERE" |
136
|
|
|
." wp_comments.comment_approved = 1"; |
137
|
|
|
if ($filter !== null) { |
138
|
|
|
$query .= " AND $filter"; |
139
|
|
|
} |
140
|
|
|
$stmt = mysql_query($query); |
141
|
|
|
$returnResult = $this->_serializeComments($stmt); |
142
|
|
|
break; |
143
|
|
|
case 'Users': |
144
|
|
|
$query = "SELECT * FROM `wp_users`"; |
145
|
|
|
//print "<br>Filter:".$filter; |
|
|
|
|
146
|
|
|
if ($filter !== null) { |
147
|
|
|
$query .= " AND $filter"; |
148
|
|
|
} |
149
|
|
|
$stmt = mysql_query($query); |
150
|
|
|
//$data = mysql_fetch_assoc($stmt); |
|
|
|
|
151
|
|
|
$returnResult = $this->_serializeUsers($stmt); |
152
|
|
|
break; |
153
|
|
|
} |
154
|
|
|
mysql_free_result($stmt); |
|
|
|
|
155
|
|
|
return $returnResult; |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Gets an entity instance from an entity set identifed by a key |
160
|
|
|
* |
161
|
|
|
* @param ResourceSet $resourceSet The entity set from which an entity |
162
|
|
|
* needs to be fetched |
163
|
|
|
* @param KeyDescriptor $keyDescriptor The key to identify the entity |
164
|
|
|
* to be fetched |
165
|
|
|
* |
166
|
|
|
* @return object|null Returns entity instance if found else null |
167
|
|
|
*/ |
168
|
|
|
public function getResourceFromResourceSet(ResourceSet $resourceSet, KeyDescriptor $keyDescriptor) |
169
|
|
|
{ |
170
|
|
|
$resourceSetName = $resourceSet->getName(); |
171
|
|
View Code Duplication |
if ($resourceSetName !== 'Posts' |
|
|
|
|
172
|
|
|
&& $resourceSetName !== 'Tags' |
173
|
|
|
&& $resourceSetName !== 'Categories' |
174
|
|
|
&& $resourceSetName !== 'Comments' |
175
|
|
|
&& $resourceSetName !== 'Users' |
176
|
|
|
) { |
177
|
|
|
die('(WordPressQueryProvider) Unknown resource set ' . $resourceSetName); |
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$namedKeyValues = $keyDescriptor->getValidatedNamedValues(); |
181
|
|
|
$keys = array(); |
182
|
|
|
foreach ($namedKeyValues as $key => $value) { |
183
|
|
|
$keys[] = "$key = '$value[0]' "; |
184
|
|
|
} |
185
|
|
|
$conditionStr = implode(' AND ', $keys); |
|
|
|
|
186
|
|
|
|
187
|
|
|
switch ($resourceSetName) { |
188
|
|
|
case 'Posts': |
189
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
190
|
|
|
." wp_posts.post_type = 'post'" |
191
|
|
|
." AND wp_posts.post_status = 'publish'" |
192
|
|
|
." AND wp_posts.ID = ".$namedKeyValues['PostID'][0]; |
193
|
|
|
$stmt = mysql_query($query); |
194
|
|
|
|
195
|
|
|
//If resource not found return null to the library |
196
|
|
|
if (!mysql_num_rows($stmt)) { |
197
|
|
|
return null; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$data = mysql_fetch_assoc($stmt); |
201
|
|
|
$result = $this->_serializePost($data); |
202
|
|
|
break; |
203
|
|
|
case 'Tags': |
204
|
|
|
$query = "SELECT t.*, tt.description" |
205
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
206
|
|
|
." ON tt.term_id = t.term_id" |
207
|
|
|
." WHERE tt.taxonomy = 'post_tag'" |
208
|
|
|
." AND t.term_id = ".$namedKeyValues['TagID'][0]; |
209
|
|
|
$stmt = mysql_query($query); |
210
|
|
|
|
211
|
|
|
//If resource not found return null to the library |
212
|
|
|
if (!mysql_num_rows($stmt)) { |
213
|
|
|
return null; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
$data = mysql_fetch_assoc($stmt); |
217
|
|
|
$result = $this->_serializeTag($data); |
218
|
|
|
break; |
219
|
|
|
case 'Categories': |
220
|
|
|
$query = "SELECT t.*, tt.description" |
221
|
|
|
." FROM `wp_terms` AS t INNER JOIN `wp_term_taxonomy` as tt" |
222
|
|
|
." ON tt.term_id = t.term_id" |
223
|
|
|
." WHERE tt.taxonomy = 'category'" |
224
|
|
|
." AND t.term_id = ".$namedKeyValues['CategoryID'][0]; |
225
|
|
|
$stmt = mysql_query($query); |
226
|
|
|
|
227
|
|
|
//If resource not found return null to the library |
228
|
|
|
if (!mysql_num_rows($stmt)) { |
229
|
|
|
return null; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
$data = mysql_fetch_assoc($stmt); |
233
|
|
|
$result = $this->_serializeCategory($data); |
234
|
|
|
break; |
235
|
|
View Code Duplication |
case 'Comments': |
|
|
|
|
236
|
|
|
$query = "SELECT * FROM `wp_comments`" |
237
|
|
|
." WHERE comment_approved = 1" |
238
|
|
|
." AND comment_ID = ".$namedKeyValues['CommentID'][0]; |
239
|
|
|
$stmt = mysql_query($query); |
240
|
|
|
|
241
|
|
|
//If resource not found return null to the library |
242
|
|
|
if (!mysql_num_rows($stmt)) { |
243
|
|
|
return null; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
$data = mysql_fetch_assoc($stmt); |
247
|
|
|
$result = $this->_serializeComment($data); |
248
|
|
|
break; |
249
|
|
View Code Duplication |
case 'Users': |
|
|
|
|
250
|
|
|
$query = "SELECT * FROM `wp_users` WHERE ID = ".$namedKeyValues['UserID'][0]; |
251
|
|
|
$stmt = mysql_query($query); |
252
|
|
|
|
253
|
|
|
//If resource not found return null to the library |
254
|
|
|
if (!mysql_num_rows($stmt)) { |
255
|
|
|
return null; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
$data = mysql_fetch_assoc($stmt); |
259
|
|
|
$result = $this->_serializeUser($data); |
260
|
|
|
break; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
mysql_free_result($stmt); |
|
|
|
|
264
|
|
|
return $result; |
|
|
|
|
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Get related resource set for a resource |
269
|
|
|
* |
270
|
|
|
* @param ResourceSet $sourceResourceSet The source resource set |
271
|
|
|
* @param mixed $sourceEntityInstance The resource |
272
|
|
|
* @param ResourceSet $targetResourceSet The resource set of |
273
|
|
|
* the navigation property |
274
|
|
|
* @param ResourceProperty $targetProperty The navigation property to be |
275
|
|
|
* retrieved |
276
|
|
|
* @param string $filterOption Contains the filter condition |
|
|
|
|
277
|
|
|
* @param string $select For future purpose,no need to pass it |
278
|
|
|
* @param string $orderby For future purpose,no need to pass it |
279
|
|
|
* @param string $top For future purpose,no need to pass it |
280
|
|
|
* @param string $skip For future purpose,no need to pass it |
281
|
|
|
* |
282
|
|
|
* @return object[] Array of related resource if exists, if no |
283
|
|
|
* related resources found returns empty array |
284
|
|
|
*/ |
285
|
|
|
public function getRelatedResourceSet(ResourceSet $sourceResourceSet, |
286
|
|
|
$sourceEntityInstance, |
287
|
|
|
ResourceSet $targetResourceSet, |
288
|
|
|
ResourceProperty $targetProperty, |
289
|
|
|
$filter=null ,$select=null, $orderby=null, $top=null, $skip=null |
290
|
|
|
) { |
291
|
|
|
$result = array(); |
292
|
|
|
$srcClass = get_class($sourceEntityInstance); |
293
|
|
|
$navigationPropName = $targetProperty->getName(); |
294
|
|
|
|
295
|
|
|
switch (true) { |
296
|
|
|
case ($srcClass == 'Post'): |
297
|
|
|
if ($navigationPropName == 'Tags') { |
298
|
|
|
$query = "SELECT t.*, tt.description" |
299
|
|
|
." FROM wp_terms AS t" |
300
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
301
|
|
|
." ON tt.term_id = t.term_id" |
302
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
303
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
304
|
|
|
." WHERE tt.taxonomy IN ('post_tag')" |
305
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)"; |
306
|
|
|
if ($filter !== null) { |
307
|
|
|
$query .= " AND $filter"; |
308
|
|
|
} |
309
|
|
|
$stmt = mysql_query($query); |
310
|
|
|
if ( $stmt === false) { |
311
|
|
|
die(mysql_error()); |
|
|
|
|
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
$result = $this->_serializeTags($stmt); |
315
|
|
|
} elseif ($navigationPropName == 'Categories') { |
316
|
|
|
$query = "SELECT t.*, tt.description" |
317
|
|
|
." FROM wp_terms AS t" |
318
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
319
|
|
|
." ON tt.term_id = t.term_id" |
320
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
321
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
322
|
|
|
." WHERE tt.taxonomy IN ('category')" |
323
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)"; |
324
|
|
|
if ($filter !== null) { |
325
|
|
|
$query .= " AND $filter"; |
326
|
|
|
} |
327
|
|
|
$stmt = mysql_query($query); |
328
|
|
|
if ( $stmt === false) { |
329
|
|
|
die(mysql_error()); |
|
|
|
|
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
$result = $this->_serializeCategories($stmt); |
333
|
|
View Code Duplication |
} else if ($navigationPropName == 'Comments') { |
|
|
|
|
334
|
|
|
$query = "SELECT * FROM `wp_comments`" |
335
|
|
|
." WHERE comment_approved = 1" |
336
|
|
|
." AND comment_post_ID = $sourceEntityInstance->PostID"; |
337
|
|
|
if ($filter !== null) { |
338
|
|
|
$query .= " AND $filter"; |
339
|
|
|
} |
340
|
|
|
$stmt = mysql_query($query); |
341
|
|
|
if ( $stmt === false) { |
342
|
|
|
die(mysql_error()); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
$result = $this->_serializeComments($stmt); |
346
|
|
|
} else { |
347
|
|
|
die('Post does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
348
|
|
|
} |
349
|
|
|
break; |
350
|
|
|
|
351
|
|
View Code Duplication |
case ($srcClass == 'Tag'): |
|
|
|
|
352
|
|
|
if ($navigationPropName == 'Posts') { |
353
|
|
|
$query = "SELECT p . *" |
354
|
|
|
." FROM wp_posts AS p" |
355
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
356
|
|
|
." ON p.ID = tr.object_id" |
357
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
358
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
359
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->TagID" |
360
|
|
|
." AND p.post_type = 'post'" |
361
|
|
|
." AND p.post_status = 'publish'"; |
362
|
|
|
if ($filter !== null) { |
363
|
|
|
$query .= " AND $filter"; |
364
|
|
|
} |
365
|
|
|
$stmt = mysql_query($query); |
366
|
|
|
if ( $stmt === false) { |
367
|
|
|
die(mysql_error()); |
|
|
|
|
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
$result = $this->_serializePosts($stmt); |
371
|
|
|
} else { |
372
|
|
|
die('Tag does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
373
|
|
|
} |
374
|
|
|
break; |
375
|
|
|
|
376
|
|
View Code Duplication |
case ($srcClass == 'Category'): |
|
|
|
|
377
|
|
|
if ($navigationPropName == 'Posts') { |
378
|
|
|
$query = "SELECT p . *" |
379
|
|
|
." FROM wp_posts AS p" |
380
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
381
|
|
|
." ON p.ID = tr.object_id" |
382
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
383
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
384
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->CategoryID" |
385
|
|
|
." AND p.post_type = 'post'" |
386
|
|
|
." AND p.post_status = 'publish'"; |
387
|
|
|
if ($filter !== null) { |
388
|
|
|
$query .= " AND $filter"; |
389
|
|
|
} |
390
|
|
|
$stmt = mysql_query($query); |
391
|
|
|
if ( $stmt === false) { |
392
|
|
|
die(mysql_error()); |
|
|
|
|
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
$result = $this->_serializePosts($stmt); |
396
|
|
|
} else { |
397
|
|
|
die('Category does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
398
|
|
|
} |
399
|
|
|
break; |
400
|
|
|
|
401
|
|
|
case ($srcClass == 'Comment'): |
402
|
|
|
die('Comment does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
403
|
|
|
break; |
|
|
|
|
404
|
|
|
|
405
|
|
|
case ($srcClass == 'User'): |
406
|
|
|
if ($navigationPropName == 'Posts') { |
407
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
408
|
|
|
." wp_posts.post_type = 'post'" |
409
|
|
|
." AND wp_posts.post_status = 'publish'" |
410
|
|
|
." AND wp_posts.post_author = $sourceEntityInstance->UserID"; |
411
|
|
|
if ($filter !== null) { |
412
|
|
|
$query .= " AND $filter"; |
413
|
|
|
} |
414
|
|
|
$stmt = mysql_query($query); |
415
|
|
|
if ( $stmt === false) { |
416
|
|
|
die(mysql_error()); |
|
|
|
|
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
$result = $this->_serializePosts($stmt); |
420
|
|
View Code Duplication |
} elseif ($navigationPropName == 'Comments') { |
|
|
|
|
421
|
|
|
$query = "SELECT * FROM `wp_comments`" |
422
|
|
|
." WHERE comment_approved = 1" |
423
|
|
|
." AND wp_comments.user_id = $sourceEntityInstance->UserID"; |
424
|
|
|
if ($filter !== null) { |
425
|
|
|
$query .= " AND $filter"; |
426
|
|
|
} |
427
|
|
|
$stmt = mysql_query($query); |
428
|
|
|
if ( $stmt === false) { |
429
|
|
|
die(mysql_error()); |
|
|
|
|
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
$result = $this->_serializeComments($stmt); |
433
|
|
|
} else { |
434
|
|
|
die('User does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
435
|
|
|
} |
436
|
|
|
break; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
mysql_free_result($stmt); |
|
|
|
|
440
|
|
|
return $result; |
|
|
|
|
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Gets a related entity instance from an entity set identifed by a key |
445
|
|
|
* |
446
|
|
|
* @param ResourceSet $sourceResourceSet The entity set related to |
447
|
|
|
* the entity to be fetched. |
448
|
|
|
* @param object $sourceEntityInstance The related entity instance. |
449
|
|
|
* @param ResourceSet $targetResourceSet The entity set from which |
450
|
|
|
* entity needs to be fetched. |
451
|
|
|
* @param ResourceProperty $targetProperty The metadata of the target |
452
|
|
|
* property. |
453
|
|
|
* @param KeyDescriptor $keyDescriptor The key to identify the entity |
454
|
|
|
* to be fetched. |
455
|
|
|
* |
456
|
|
|
* @return object|null Returns entity instance if found else null |
457
|
|
|
*/ |
458
|
|
|
public function getResourceFromRelatedResourceSet(ResourceSet $sourceResourceSet, |
459
|
|
|
$sourceEntityInstance, |
460
|
|
|
ResourceSet $targetResourceSet, |
461
|
|
|
ResourceProperty $targetProperty, |
462
|
|
|
KeyDescriptor $keyDescriptor |
463
|
|
|
) { |
464
|
|
|
$result = array(); |
465
|
|
|
$srcClass = get_class($sourceEntityInstance); |
466
|
|
|
$navigationPropName = $targetProperty->getName(); |
467
|
|
|
|
468
|
|
|
$keys = array(); |
469
|
|
|
$namedKeyValues = $keyDescriptor->getValidatedNamedValues(); |
470
|
|
|
foreach ($namedKeyValues as $key => $value) { |
471
|
|
|
$keys[] = "$key = '$value[0]' "; |
472
|
|
|
} |
473
|
|
|
$conditionStr = implode(' AND ', $keys); |
|
|
|
|
474
|
|
|
|
475
|
|
|
switch (true) { |
476
|
|
|
case ($srcClass == 'Post'): |
477
|
|
|
if ($navigationPropName == 'Tags') { |
478
|
|
|
$query = "SELECT t.*, tt.description" |
479
|
|
|
." FROM wp_terms AS t" |
480
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
481
|
|
|
." ON tt.term_id = t.term_id" |
482
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
483
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
484
|
|
|
." WHERE tt.taxonomy IN ('post_tag')" |
485
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)" |
486
|
|
|
." AND tt.term_id = ".$namedKeyValues['TagID'][0]; |
487
|
|
|
$stmt = mysql_query($query); |
488
|
|
|
$result = $this->_serializeTags($stmt); |
489
|
|
|
} elseif ($navigationPropName == 'Categories') { |
490
|
|
|
$query = "SELECT t.*, tt.description" |
491
|
|
|
." FROM wp_terms AS t" |
492
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
493
|
|
|
." ON tt.term_id = t.term_id" |
494
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
495
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
496
|
|
|
." WHERE tt.taxonomy IN ('category')" |
497
|
|
|
." AND tr.object_id IN ($sourceEntityInstance->PostID)" |
498
|
|
|
." AND tt.term_id = ".$namedKeyValues['CategoryID'][0]; |
499
|
|
|
$stmt = mysql_query($query); |
500
|
|
|
$result = $this->_serializeCategories($stmt); |
501
|
|
View Code Duplication |
} else if ($navigationPropName == 'Comments') { |
|
|
|
|
502
|
|
|
$query = "SELECT * FROM `wp_comments`" |
503
|
|
|
." WHERE comment_approved = 1" |
504
|
|
|
." AND comment_post_ID = $sourceEntityInstance->PostID" |
505
|
|
|
." AND comment_ID = ".$namedKeyValues['CommentID'][0]; |
506
|
|
|
$stmt = mysql_query($query); |
507
|
|
|
$result = $this->_serializeComments($stmt); |
508
|
|
|
} else { |
509
|
|
|
die('Post does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
510
|
|
|
} |
511
|
|
|
break; |
512
|
|
|
|
513
|
|
View Code Duplication |
case ($srcClass == 'Tag'): |
|
|
|
|
514
|
|
|
if ($navigationPropName == 'Posts') { |
515
|
|
|
$query = "SELECT p . *" |
516
|
|
|
." FROM wp_posts AS p" |
517
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
518
|
|
|
." ON p.ID = tr.object_id" |
519
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
520
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
521
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->TagID" |
522
|
|
|
." AND p.post_type = 'post'" |
523
|
|
|
." AND p.post_status = 'publish'" |
524
|
|
|
." AND p.ID = ".$namedKeyValues['PostID'][0]; |
525
|
|
|
$stmt = mysql_query($query); |
526
|
|
|
$result = $this->_serializePosts($stmt); |
527
|
|
|
} else { |
528
|
|
|
die('Tag does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
529
|
|
|
} |
530
|
|
|
break; |
531
|
|
|
|
532
|
|
View Code Duplication |
case ($srcClass == 'Category'): |
|
|
|
|
533
|
|
|
if ($navigationPropName == 'Posts') { |
534
|
|
|
$query = "SELECT p . *" |
535
|
|
|
." FROM wp_posts AS p" |
536
|
|
|
." INNER JOIN wp_term_relationships AS tr" |
537
|
|
|
." ON p.ID = tr.object_id" |
538
|
|
|
." INNER JOIN wp_term_taxonomy AS tt" |
539
|
|
|
." ON tr.term_taxonomy_id = tt.term_taxonomy_id" |
540
|
|
|
." WHERE tt.term_id = $sourceEntityInstance->CategoryID" |
541
|
|
|
." AND p.post_type = 'post'" |
542
|
|
|
." AND p.post_status = 'publish'" |
543
|
|
|
." AND p.ID = ".$namedKeyValues['PostID'][0]; |
544
|
|
|
$stmt = mysql_query($query); |
545
|
|
|
$result = $this->_serializePosts($stmt); |
546
|
|
|
} else { |
547
|
|
|
die('Category does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
548
|
|
|
} |
549
|
|
|
break; |
550
|
|
|
|
551
|
|
|
case ($srcClass == 'Comment'): |
552
|
|
|
die('Comment does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
553
|
|
|
break; |
|
|
|
|
554
|
|
|
|
555
|
|
|
case ($srcClass == 'User'): |
556
|
|
|
if ($navigationPropName == 'Posts') { |
557
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
558
|
|
|
." wp_posts.post_type = 'post'" |
559
|
|
|
." AND wp_posts.post_status = 'publish'" |
560
|
|
|
." AND wp_posts.post_author = $sourceEntityInstance->UserID" |
561
|
|
|
." AND wp_posts.ID = ".$namedKeyValues['PostID'][0]; |
562
|
|
|
$stmt = mysql_query($query); |
563
|
|
|
$result = $this->_serializePosts($stmt); |
564
|
|
View Code Duplication |
} elseif ($navigationPropName == 'Comments') { |
|
|
|
|
565
|
|
|
$query = "SELECT * FROM `wp_comments`" |
566
|
|
|
." WHERE comment_approved = 1" |
567
|
|
|
." AND wp_comments.user_id = $sourceEntityInstance->UserID" |
568
|
|
|
." AND wp_comments.comment_ID = ".$namedKeyValues['CommentID'][0]; |
569
|
|
|
$stmt = mysql_query($query); |
570
|
|
|
$result = $this->_serializeComments($stmt); |
571
|
|
|
} else { |
572
|
|
|
die('User does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
573
|
|
|
} |
574
|
|
|
break; |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
mysql_free_result($stmt); |
|
|
|
|
578
|
|
|
return empty($result) ? null : $result[0]; |
579
|
|
|
} |
580
|
|
|
/** |
581
|
|
|
* Get related resource for a resource |
582
|
|
|
* |
583
|
|
|
* @param ResourceSet $sourceResourceSet The source resource set |
584
|
|
|
* @param mixed $sourceEntityInstance The source resource |
585
|
|
|
* @param ResourceSet $targetResourceSet The resource set of |
586
|
|
|
* the navigation property |
587
|
|
|
* @param ResourceProperty $targetProperty The navigation property to be |
588
|
|
|
* retrieved |
589
|
|
|
* |
590
|
|
|
* @return object|null The related resource if exists else null |
591
|
|
|
*/ |
592
|
|
|
public function getRelatedResourceReference(ResourceSet $sourceResourceSet, |
593
|
|
|
$sourceEntityInstance, |
594
|
|
|
ResourceSet $targetResourceSet, |
595
|
|
|
ResourceProperty $targetProperty |
596
|
|
|
) { |
597
|
|
|
$result = null; |
598
|
|
|
$srcClass = get_class($sourceEntityInstance); |
599
|
|
|
$navigationPropName = $targetProperty->getName(); |
600
|
|
|
|
601
|
|
|
switch (true) { |
602
|
|
|
case ($srcClass == 'Post'): |
603
|
|
|
if ($navigationPropName == 'User') { |
604
|
|
|
$query = "SELECT * FROM `wp_users` WHERE ID = $sourceEntityInstance->Author"; |
605
|
|
|
$stmt = mysql_query($query); |
|
|
|
|
606
|
|
|
$stmt = mysql_query($query); |
607
|
|
|
$data = mysql_fetch_assoc($stmt); |
608
|
|
|
$result = $this->_serializeUser($data); |
609
|
|
|
if ( $stmt === false) { |
610
|
|
|
die(mysql_error()); |
|
|
|
|
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
if (!mysql_num_rows($stmt)) { |
614
|
|
|
$result = null; |
615
|
|
|
} |
616
|
|
|
} else { |
617
|
|
|
die('Post does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
618
|
|
|
} |
619
|
|
|
break; |
620
|
|
|
|
621
|
|
|
case ($srcClass == 'Comment'): |
622
|
|
|
if ($navigationPropName == 'User') { |
623
|
|
|
$query = "SELECT * FROM `wp_users` WHERE ID = $sourceEntityInstance->UserID"; |
624
|
|
|
$stmt = mysql_query($query); |
625
|
|
|
if ( $stmt === false) { |
626
|
|
|
die(mysql_error()); |
|
|
|
|
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
if (!mysql_num_rows($stmt)) { |
630
|
|
|
$result = null; |
|
|
|
|
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
$data = mysql_fetch_assoc($stmt); |
634
|
|
|
$result = $this->_serializeUser($data); |
635
|
|
|
|
636
|
|
|
} elseif ($navigationPropName == 'Post') { |
637
|
|
|
$query = "SELECT * FROM `wp_posts` WHERE" |
638
|
|
|
." wp_posts.post_type = 'post'" |
639
|
|
|
." AND wp_posts.post_status = 'publish'" |
640
|
|
|
." AND wp_posts.ID = $sourceEntityInstance->PostID"; |
641
|
|
|
$stmt = mysql_query($query); |
642
|
|
|
if ( $stmt === false) { |
643
|
|
|
die(mysql_error()); |
|
|
|
|
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
if (!mysql_num_rows($stmt)) { |
647
|
|
|
$result = null; |
|
|
|
|
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
$data = mysql_fetch_assoc($stmt); |
651
|
|
|
$result = $this->_serializePost($data); |
652
|
|
|
} else { |
653
|
|
|
die('Comment does not have navigation porperty with name: ' . $navigationPropName); |
|
|
|
|
654
|
|
|
} |
655
|
|
|
break; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
mysql_free_result($stmt); |
|
|
|
|
659
|
|
|
return $result; |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
/** |
663
|
|
|
* Serialize the mysql result array into Post objects |
664
|
|
|
* |
665
|
|
|
* @param array(array) $result result of the mysql query |
|
|
|
|
666
|
|
|
* |
667
|
|
|
* @return array(Object) |
|
|
|
|
668
|
|
|
*/ |
669
|
|
|
private function _serializePosts($result) |
670
|
|
|
{ |
671
|
|
|
$posts = array(); |
672
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
673
|
|
|
$posts[] = $this->_serializePost($record); |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
return $posts; |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* Serialize the mysql row into Post object |
681
|
|
|
* |
682
|
|
|
* @param array $record each post row |
683
|
|
|
* |
684
|
|
|
* @return object |
685
|
|
|
*/ |
686
|
|
|
private function _serializePost($record) |
687
|
|
|
{ |
688
|
|
|
$post = new Post(); |
689
|
|
|
$post->PostID = $record['ID']; |
690
|
|
|
$post->Author = $record['post_author']; |
691
|
|
|
|
692
|
|
View Code Duplication |
if (!is_null($record['post_date'])) { |
|
|
|
|
693
|
|
|
$dateTime = new DateTime($record['post_date']); |
694
|
|
|
$post->Date = $dateTime->format('Y-m-d\TH:i:s'); |
695
|
|
|
} else { |
696
|
|
|
$post->Date = null; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
View Code Duplication |
if (!is_null($record['post_date_gmt'])) { |
|
|
|
|
700
|
|
|
$dateTime = new DateTime($record['post_date_gmt']); |
701
|
|
|
$post->DateGmt = $dateTime->format('Y-m-d\TH:i:s'); |
702
|
|
|
} else { |
703
|
|
|
$post->DateGmt = null; |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
$post->Content = $record['post_content']; |
707
|
|
|
$post->Title = $record['post_title']; |
708
|
|
|
$post->Excerpt = $record['post_excerpt']; |
709
|
|
|
$post->Status = $record['post_status']; |
710
|
|
|
$post->CommentStatus = $record['comment_status']; |
711
|
|
|
$post->PingStatus = $record['ping_status']; |
712
|
|
|
$post->Password = $record['post_password']; |
713
|
|
|
$post->Name = $record['post_name']; |
714
|
|
|
$post->ToPing = $record['to_ping']; |
715
|
|
|
$post->Pinged = $record['pinged']; |
716
|
|
|
|
717
|
|
View Code Duplication |
if (!is_null($record['post_modified'])) { |
|
|
|
|
718
|
|
|
$dateTime = new DateTime($record['post_modified']); |
719
|
|
|
$post->Modified = $dateTime->format('Y-m-d\TH:i:s'); |
720
|
|
|
} else { |
721
|
|
|
$post->Modified = null; |
722
|
|
|
} |
723
|
|
|
|
724
|
|
View Code Duplication |
if (!is_null($record['post_modified_gmt'])) { |
|
|
|
|
725
|
|
|
$dateTime = new DateTime($record['post_modified_gmt']); |
726
|
|
|
$post->ModifiedGmt = $dateTime->format('Y-m-d\TH:i:s'); |
727
|
|
|
} else { |
728
|
|
|
$post->ModifiedGmt = null; |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
$post->ContentFiltered = $record['post_content_filtered']; |
732
|
|
|
$post->ParentID = $record['post_parent']; |
733
|
|
|
$post->Guid = $record['guid']; |
734
|
|
|
$post->MenuOrder = $record['menu_order']; |
735
|
|
|
$post->Type = $record['post_type']; |
736
|
|
|
$post->MimeType = $record['post_mime_type']; |
737
|
|
|
$post->CommentCount = $record['comment_count']; |
738
|
|
|
return $post; |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
/** |
742
|
|
|
* Serialize the mysql result array into Tag objects |
743
|
|
|
* |
744
|
|
|
* @param array(array) $result result of the mysql query |
|
|
|
|
745
|
|
|
* |
746
|
|
|
* @return array(Object) |
|
|
|
|
747
|
|
|
*/ |
748
|
|
View Code Duplication |
private function _serializeTags($result) |
|
|
|
|
749
|
|
|
{ |
750
|
|
|
$tags = array(); |
751
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
752
|
|
|
$tags[] = $this->_serializeTag($record); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
return $tags; |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
/** |
759
|
|
|
* Serialize the mysql row into Tag object |
760
|
|
|
* |
761
|
|
|
* @param array $record each tag row |
762
|
|
|
* |
763
|
|
|
* @return object |
764
|
|
|
*/ |
765
|
|
|
private function _serializeTag($record) |
766
|
|
|
{ |
767
|
|
|
$tag = new Tag(); |
768
|
|
|
$tag->TagID = $record['term_id']; |
769
|
|
|
$tag->Name = $record['name']; |
770
|
|
|
$tag->Slug = $record['slug']; |
771
|
|
|
$tag->Description = $record['description']; |
772
|
|
|
return $tag; |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* Serialize the mysql result array into Category objects |
777
|
|
|
* |
778
|
|
|
* @param array(array) $result result of the mysql query |
|
|
|
|
779
|
|
|
* |
780
|
|
|
* @return array(Object) |
|
|
|
|
781
|
|
|
*/ |
782
|
|
View Code Duplication |
private function _serializeCategories($result) |
|
|
|
|
783
|
|
|
{ |
784
|
|
|
$cats = array(); |
785
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
786
|
|
|
$cats[] = $this->_serializeCategory($record); |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
return $cats; |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
/** |
793
|
|
|
* Serialize the mysql row into Category object |
794
|
|
|
* |
795
|
|
|
* @param array $record each category row |
796
|
|
|
* |
797
|
|
|
* @return object |
798
|
|
|
*/ |
799
|
|
|
private function _serializeCategory($record) |
800
|
|
|
{ |
801
|
|
|
$cat = new Category(); |
802
|
|
|
$cat->CategoryID = $record['term_id']; |
803
|
|
|
$cat->Name = $record['name']; |
804
|
|
|
$cat->Slug = $record['slug']; |
805
|
|
|
$cat->Description = $record['description']; |
806
|
|
|
return $cat; |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* Serialize the mysql result array into Comment objects |
811
|
|
|
* |
812
|
|
|
* @param array(array) $result mysql query result |
|
|
|
|
813
|
|
|
* |
814
|
|
|
* @return array(Object) |
|
|
|
|
815
|
|
|
*/ |
816
|
|
|
private function _serializeComments($result) |
817
|
|
|
{ |
818
|
|
|
$comments = array(); |
819
|
|
|
while ( $record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
820
|
|
|
$comments[] = $this->_serializeComment($record); |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
return $comments; |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* Serialize the mysql row into Comment object |
828
|
|
|
* |
829
|
|
|
* @param array $record each comment row |
830
|
|
|
* |
831
|
|
|
* @return object |
832
|
|
|
*/ |
833
|
|
|
private function _serializeComment($record) |
834
|
|
|
{ |
835
|
|
|
$comment = new Comment(); |
836
|
|
|
$comment->CommentID = $record['comment_ID']; |
837
|
|
|
$comment->PostID = $record['comment_post_ID']; |
838
|
|
|
$comment->Author = $record['comment_author']; |
839
|
|
|
$comment->AuthorEmail = $record['comment_author_email']; |
840
|
|
|
$comment->AuthorUrl = $record['comment_author_url']; |
841
|
|
|
$comment->AuthorIp = $record['comment_author_IP']; |
842
|
|
|
|
843
|
|
View Code Duplication |
if (!is_null($record['comment_date'])) { |
|
|
|
|
844
|
|
|
$dateTime = new DateTime($record['comment_date']); |
845
|
|
|
$comment->Date = $dateTime->format('Y-m-d\TH:i:s'); |
846
|
|
|
} else { |
847
|
|
|
$comment->Date = null; |
848
|
|
|
} |
849
|
|
|
|
850
|
|
View Code Duplication |
if (!is_null($record['comment_date_gmt'])) { |
|
|
|
|
851
|
|
|
$dateTime = new DateTime($record['comment_date_gmt']); |
852
|
|
|
$comment->DateGmt = $dateTime->format('Y-m-d\TH:i:s'); |
853
|
|
|
} else { |
854
|
|
|
$comment->DateGmt = null; |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
$comment->Content = $record['comment_content']; |
858
|
|
|
$comment->Karma = $record['comment_karma']; |
859
|
|
|
$comment->Approved = $record['comment_approved']; |
860
|
|
|
$comment->Agent = $record['comment_agent']; |
861
|
|
|
$comment->Type = $record['comment_type']; |
862
|
|
|
$comment->ParentID = $record['comment_parent']; |
863
|
|
|
$comment->UserID = $record['user_id']; |
864
|
|
|
return $comment; |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
/** |
868
|
|
|
* Serialize the mysql result array into User objects |
869
|
|
|
* |
870
|
|
|
* @param array(array) $result result of the mysql query |
|
|
|
|
871
|
|
|
* |
872
|
|
|
* @return array(Object) |
|
|
|
|
873
|
|
|
*/ |
874
|
|
|
private function _serializeUsers($result) |
875
|
|
|
{ |
876
|
|
|
$users = array(); |
877
|
|
|
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)) { |
878
|
|
|
$users[] = $this->_serializeUser($record); |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
return $users; |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
/** |
885
|
|
|
* Serialize the mysql row into User object |
886
|
|
|
* |
887
|
|
|
* @param array $record each user row |
888
|
|
|
* |
889
|
|
|
* @return object |
890
|
|
|
*/ |
891
|
|
|
private function _serializeUser($record) |
892
|
|
|
{ |
893
|
|
|
$user = new User(); |
894
|
|
|
$user->UserID = $record['ID']; |
895
|
|
|
$user->Login = $record['user_login']; |
896
|
|
|
$user->Nicename = $record['user_nicename']; |
897
|
|
|
$user->Email = $record['user_email']; |
898
|
|
|
$user->Url = $record['user_url']; |
899
|
|
|
|
900
|
|
View Code Duplication |
if (!is_null($record['user_registered'])) { |
|
|
|
|
901
|
|
|
$dateTime = new DateTime($record['user_registered']); |
902
|
|
|
$user->Registered = $dateTime->format('Y-m-d\TH:i:s'); |
903
|
|
|
} else { |
904
|
|
|
$user->Registered = null; |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
$user->Status = $record['user_status']; |
908
|
|
|
$user->DisplayName = $record['display_name']; |
909
|
|
|
return $user; |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
|
913
|
|
|
} |
914
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.