1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Drest package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Lee Davis |
9
|
|
|
* @copyright Copyright (c) Lee Davis <@leedavis81> |
10
|
|
|
* @link https://github.com/leedavis81/drest/blob/master/LICENSE |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT X License (MIT) |
12
|
|
|
*/ |
13
|
|
|
namespace Drest; |
14
|
|
|
|
15
|
|
|
use Exception; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Base exception class for all Drest exceptions. |
19
|
|
|
*/ |
20
|
|
|
class DrestException extends Exception |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
// Set up and configuration |
24
|
1 |
|
public static function metadataCacheNotConfigured() |
25
|
|
|
{ |
26
|
1 |
|
return new self( |
27
|
|
|
'Class Metadata Cache is not configured, ensure an instance of Doctrine\Common\Cache\Cache' . |
28
|
1 |
|
'is passed to the Drest\Configuration::setMetadataCacheImpl()'); |
29
|
|
|
} |
30
|
|
|
|
31
|
1 |
|
public static function currentlyRunningDebugMode() |
32
|
|
|
{ |
33
|
1 |
|
return new self( |
34
|
|
|
'Debug mode is set to on. This will cause configuration exceptions to be' . |
35
|
1 |
|
' displayed and should be switched off in production'); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
public static function annotatedResourceRequiresAtLeastOneServiceDefinition($className) |
39
|
|
|
{ |
40
|
1 |
|
return new self( |
41
|
1 |
|
'The annotated resource on class ' . $className . ' doesn\'t have any service definitions.' . |
42
|
1 |
|
' Ensure you have "services={@Drest\Service(..)} set'); |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
public static function routeAlreadyDefinedWithName($class, $name) |
46
|
|
|
{ |
47
|
2 |
|
return new self( |
48
|
2 |
|
'Route on class ' . $class . ' already exists with the name ' . $name . '. These must be unique'); |
49
|
|
|
} |
50
|
|
|
|
51
|
2 |
|
public static function routeNameIsEmpty() |
52
|
|
|
{ |
53
|
2 |
|
return new self( |
54
|
2 |
|
'Route name used cannot be blank, and must only contain alphanumerics or underscore'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $verb |
59
|
|
|
* @return DrestException |
60
|
|
|
*/ |
61
|
2 |
|
public static function invalidHttpVerbUsed($verb) |
62
|
|
|
{ |
63
|
2 |
|
return new self( |
64
|
2 |
|
'Used an unknown HTTP verb of "' . $verb . '"'); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
public static function unknownDetectContentOption() |
68
|
|
|
{ |
69
|
1 |
|
return new self( |
70
|
1 |
|
'Content option used is invalid. Please see DETECT_CONTENT_* options in Drest\Configuration'); |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
public static function pathToConfigFilesRequired() |
74
|
|
|
{ |
75
|
1 |
|
return new self( |
76
|
1 |
|
'Path to your configuration files are required for the driver to retrieve all class names'); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
public static function unableToLoadMetaDataFromDriver() |
80
|
|
|
{ |
81
|
2 |
|
return new self( |
82
|
2 |
|
'Unable to load metadata using supplied driver'); |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
public static function invalidExposeRelationFetchType() |
86
|
|
|
{ |
87
|
1 |
|
return new self( |
88
|
|
|
'Invalid relation fetch type used. ' . |
89
|
1 |
|
'Please see Doctrine\ORM\Mapping\ClassMetadataInfo::FETCH_* for available options'); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public static function unknownExposeRequestOption() |
93
|
|
|
{ |
94
|
1 |
|
return new self( |
95
|
|
|
'Unknown expose request option used. ' . |
96
|
1 |
|
'Please see EXPOSE_REQUEST_* options in Drest\Configuration'); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
public static function basePathMustBeAString() |
100
|
|
|
{ |
101
|
1 |
|
return new self('Base path used is invalid. Must be a string'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public static function handleAlreadyDefinedForRoute(Mapping\RouteMetaData $route) |
105
|
|
|
{ |
106
|
|
|
return new self( |
107
|
|
|
'There is a handle already defined for the route ' |
108
|
|
|
. $route->getName() . ' on class ' . $route->getClassMetaData()->getClassName()); |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
public static function handleForGetRouteMustBeStatic() |
112
|
|
|
{ |
113
|
1 |
|
return new self('Any handle used for a get call must be defined as static'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string $name |
118
|
|
|
* @return DrestException |
119
|
|
|
*/ |
120
|
1 |
|
public static function handleAnnotationDoesntMatchRouteName($name) |
121
|
|
|
{ |
122
|
1 |
|
return new self( |
123
|
1 |
|
'The configured handle "' . $name . '" doesn\'t match any route of that name. ' . |
124
|
1 |
|
'Ensure @Drest\Handle(for="my_route") matches @Drest\Route(name="my_route")'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string $name |
129
|
|
|
* @return DrestException |
130
|
|
|
*/ |
131
|
|
|
public static function routeRequiresHandle($name) |
132
|
|
|
{ |
133
|
|
|
return new self( |
134
|
|
|
'Route requires a handle. Ensure a @Drest\Handle(for="' . $name . '") function is set.' . |
135
|
|
|
' These are required for all push type routes (POST/PUT/PATCH)'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public static function handleForCannotBeEmpty() |
139
|
|
|
{ |
140
|
|
|
return new self('The @Drest\Handle configuration MUST contain a valid / matching "for" value'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public static function invalidNamedRouteSyntax() |
144
|
|
|
{ |
145
|
|
|
return new self( |
146
|
|
|
'Invalid named route syntax. ' . |
147
|
|
|
'Must use a formatted string of: {EntityClassName}::{RouteName}. Eg "Entities\\User::get_users"'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $routeName |
153
|
|
|
* @param string $className |
154
|
|
|
* @return DrestException |
155
|
|
|
*/ |
156
|
1 |
|
public static function unableToFindRouteByName($routeName, $className) |
157
|
|
|
{ |
158
|
1 |
|
return new self( |
159
|
1 |
|
'Unable to find the named route "' . $routeName . '" on class ' . $className); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public static function resourceCanOnlyHaveOneRouteSetAsOrigin() |
163
|
|
|
{ |
164
|
|
|
return new self('A resource can only have one route set as "origin"'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public static function unableToHandleACollectionPush() |
168
|
|
|
{ |
169
|
|
|
return new self( |
170
|
|
|
'Requests to push data (PUT/POST/PATCH) can only be used on individual elements.' . |
171
|
|
|
' Data collections cannot be pushed'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Service Exceptions |
176
|
|
|
* @param string $class |
177
|
|
|
* @return DrestException |
178
|
|
|
*/ |
179
|
|
|
public static function actionClassNotAnInstanceOfActionAbstract($class) |
180
|
|
|
{ |
181
|
|
|
return new self( |
182
|
|
|
'Action class "' . $class . '" is not an instance of Drest\Service\Action\ActionAbstract.'); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param string $class |
187
|
|
|
* @return DrestException |
188
|
|
|
*/ |
189
|
|
|
public static function unknownActionClass($class) |
190
|
|
|
{ |
191
|
|
|
return new self('Unknown action class "' . $class . '"'); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public static function noMatchedRouteSet() |
195
|
|
|
{ |
196
|
|
|
return new self( |
197
|
|
|
'No matched route has been set on this service class.' . |
198
|
|
|
' The content type is needed for a default service method call'); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|