|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
use POData\Configuration\EntitySetRights; |
|
4
|
|
|
require_once 'POData\IBaseService.php'; |
|
5
|
|
|
require_once 'POData\IRequestHandler.php'; |
|
6
|
|
|
require_once 'POData\DataService.php'; |
|
7
|
|
|
require_once 'POData\IServiceProvider.php'; |
|
8
|
|
|
use POData\Configuration\ProtocolVersion; |
|
9
|
|
|
use POData\Configuration\ServiceConfiguration; |
|
10
|
|
|
use POData\BaseService; |
|
11
|
|
|
use POData\OperationContext\ServiceHost; |
|
12
|
|
|
use POData\Common\ODataException; |
|
13
|
|
|
use POData\Common\ODataConstants; |
|
14
|
|
|
use POData\Common\Messages; |
|
15
|
|
|
use POData\UriProcessor\UriProcessor; |
|
16
|
|
|
require_once 'WordPressMetadata.php'; |
|
17
|
|
|
require_once 'WordPressQueryProvider.php'; |
|
18
|
|
|
require_once 'WordPressDSExpressionProvider.php'; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
class WordPressDataService extends BaseService |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
private $_wordPressMetadata = null; |
|
24
|
|
|
private $_wordPressQueryProvider = null; |
|
25
|
|
|
private $_wordPressExpressionProvider = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* This method is called only once to initialize service-wide policies |
|
29
|
|
|
* |
|
30
|
|
|
* @param ServiceConfiguration $config Data service configuration object |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
View Code Duplication |
public function initialize(ServiceConfiguration $config) |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$config->setEntitySetPageSize('*', 5); |
|
37
|
|
|
$config->setEntitySetAccessRule('*', EntitySetRights::ALL); |
|
38
|
|
|
$config->setAcceptCountRequests(true); |
|
39
|
|
|
$config->setAcceptProjectionRequests(true); |
|
40
|
|
|
$config->setMaxDataServiceVersion(ProtocolVersion::V3()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get the service like IMetadataProvider, IDataServiceQueryProvider, |
|
45
|
|
|
* IStreamProvider |
|
46
|
|
|
* |
|
47
|
|
|
* @param String $serviceType Type of service IMetadataProvider, |
|
48
|
|
|
* IDataServiceQueryProvider, |
|
49
|
|
|
* IStreamProvider |
|
50
|
|
|
* |
|
51
|
|
|
* @see library/POData.IServiceProvider::getService() |
|
52
|
|
|
* @return object |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getService($serviceType) |
|
55
|
|
|
{ |
|
56
|
|
|
if(($serviceType === 'IMetadataProvider') || |
|
57
|
|
|
($serviceType === 'IQueryProvider') || |
|
58
|
|
|
($serviceType === 'IStreamProvider')) { |
|
59
|
|
|
if (is_null($this->_wordPressExpressionProvider)) { |
|
60
|
|
|
$this->_wordPressExpressionProvider = new WordPressDSExpressionProvider(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
if ($serviceType === 'IMetadataProvider') { |
|
64
|
|
|
if (is_null($this->_wordPressMetadata)) { |
|
65
|
|
|
$this->_wordPressMetadata = CreateWordPressMetadata::create(); |
|
66
|
|
|
// $this->_wordPressMetadata->mappedDetails = CreateWordPressMetadata::mappingInitialize(); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
return $this->_wordPressMetadata; |
|
69
|
|
|
} else if ($serviceType === 'IQueryProvider') { |
|
70
|
|
|
if (is_null($this->_wordPressQueryProvider)) { |
|
71
|
|
|
$this->_wordPressQueryProvider = new WordPressQueryProvider(); |
|
72
|
|
|
} |
|
73
|
|
|
return $this->_wordPressQueryProvider; |
|
74
|
|
|
} else if ($serviceType === 'IStreamProvider') { |
|
75
|
|
|
return new WordPressStreamProvider(); |
|
76
|
|
|
} |
|
77
|
|
|
return null; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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.