1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
4
|
|
|
* |
5
|
|
|
* Licensed under The MIT License |
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CakeDC\Api\Service\Action; |
13
|
|
|
|
14
|
|
|
use CakeDC\Api\Exception\ValidationException; |
15
|
|
|
use CakeDC\Api\Service\CrudService; |
16
|
|
|
use CakeDC\Api\Service\ServiceRegistry; |
17
|
|
|
use Cake\Validation\Validator; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class DescribeAction |
21
|
|
|
* |
22
|
|
|
* @package CakeDC\Api\Service\Action |
23
|
|
|
*/ |
24
|
|
|
class DescribeAction extends Action |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Apply validation process. |
29
|
|
|
* |
30
|
|
|
* @return bool|array |
31
|
|
|
*/ |
32
|
|
|
public function validates() |
33
|
|
|
{ |
34
|
|
|
$validator = new Validator(); |
35
|
|
|
$validator |
36
|
|
|
->requirePresence('service', 'create') |
37
|
|
|
->notBlank('service'); |
38
|
|
|
$errors = $validator->errors($this->getData()); |
|
|
|
|
39
|
|
|
if (!empty($errors)) { |
40
|
|
|
throw new ValidationException(__('Validation failed'), 0, null, $errors); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return true; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Describe service. |
48
|
|
|
* For services that inherited from CrudService it provides action description using CrudDescribeAction. |
49
|
|
|
* |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
1 |
|
public function execute() |
53
|
|
|
{ |
54
|
1 |
|
$serviceName = $this->getData()['service']; |
55
|
1 |
|
$service = ServiceRegistry::getServiceLocator()->get($serviceName); |
56
|
1 |
|
if ($service instanceof CrudService) { |
57
|
|
|
$route = [ |
58
|
1 |
|
'plugin' => null, |
59
|
1 |
|
'controller' => $serviceName, |
60
|
1 |
|
'action' => 'describe', |
61
|
1 |
|
'_method' => 'OPTIONS', |
62
|
1 |
|
'pass' => [], |
63
|
1 |
|
'map' => [], |
64
|
1 |
|
'_matchedRoute' => '/' . $serviceName, |
65
|
1 |
|
]; |
66
|
1 |
|
$action = $service->buildActionClass('\CakeDC\Api\Service\Action\CrudDescribeAction', $route); |
67
|
1 |
|
$service->setRequest($this->getService()->getRequest()); |
68
|
1 |
|
$service->setResponse($this->getService()->getResponse()); |
69
|
|
|
|
70
|
1 |
|
return $action->execute(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return []; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.