This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
RestfulApiPlugin.php
104 lines (89 loc) · 2.23 KB
/
RestfulApiPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Craft;
use RestfulApi\Exceptions\RestfulApiException;
class RestfulApiPlugin extends BasePlugin
{
/**
* Get Name
*
* @return string Name
*/
public function getName()
{
return Craft::t('Restful Api');
}
/**
* Get Version
*
* @return string Version
*/
public function getVersion()
{
return '0.0.0';
}
/**
* Get Developer
*
* @return string Developer
*/
public function getDeveloper()
{
return 'Airtype';
}
/**
* Get Developer Url
*
* @return string Developer Url
*/
public function getDeveloperUrl()
{
return 'http://airtype.com';
}
/**
* Register Site Routes
*
* @return array Site Routes
*/
public function registerSiteRoutes()
{
$route_prefix = craft()->config->get('apiRoutePrefix', 'restfulApi');
return [
$route_prefix => ['action' => 'restfulApi/resourceRouter'],
sprintf('%s/(?P<elementType>\w+)(/(?P<elementId>[\w\-\d]+)(/(?P<action>\w+))?)?', $route_prefix) => ['action' => 'restfulApi/resourceRouter'],
];
}
/**
* Init
*
* @return void
*/
public function init()
{
$this->autoload_files();
if (craft()->config->get('paginationParameter', 'restfulApi') === craft()->config->get('pageTrigger')) {
$exception = new RestfulApiException;
$exception->setMessage('The `paginationParameter` cannot be the same as `pageTrigger`.');
throw $exception;
}
}
/**
* Autoload Files
*
* @return void
*/
public function autoload_files()
{
$autoload = craft()->config->get('autoload', 'restfulApi');
if ($autoload['transformers']) {
Craft::import('plugins.*.transformers.*', true);
} else {
Craft::import('plugins.restfulapi.transformers.*', true);
}
if ($autoload['validators']) {
Craft::import('plugins.*.validators.*', true);
} else {
Craft::import('plugins.restfulapi.validators.*', true);
}
Craft::import('plugins.restfulapi.vendor.autoload', true);
}
}