1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2023 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Shop\Controller; |
10
|
|
|
|
11
|
|
|
use Illuminate\Routing\Controller; |
12
|
|
|
use Illuminate\Support\Facades\Route; |
13
|
|
|
use Illuminate\Support\Facades\Request; |
14
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
15
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
16
|
|
|
use Nyholm\Psr7\Factory\Psr17Factory; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Aimeos controller for the JSON REST API |
21
|
|
|
*/ |
22
|
|
|
class JsonadmController extends Controller |
23
|
|
|
{ |
24
|
|
|
use AuthorizesRequests; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Deletes the resource object or a list of resource objects |
29
|
|
|
* |
30
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
31
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
32
|
|
|
*/ |
33
|
|
|
public function deleteAction( ServerRequestInterface $request ) |
34
|
|
|
{ |
35
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
36
|
|
|
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $this->createAdmin()->delete( $request, ( new Psr17Factory )->createResponse() ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the requested resource object or list of resource objects |
45
|
|
|
* |
46
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
47
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
48
|
|
|
*/ |
49
|
|
|
public function getAction( ServerRequestInterface $request ) |
50
|
|
|
{ |
51
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
52
|
|
|
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $this->createAdmin()->get( $request, ( new Psr17Factory )->createResponse() ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Updates a resource object or a list of resource objects |
61
|
|
|
* |
62
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
63
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
64
|
|
|
*/ |
65
|
|
|
public function patchAction( ServerRequestInterface $request ) |
66
|
|
|
{ |
67
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
68
|
|
|
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->createAdmin()->patch( $request, ( new Psr17Factory )->createResponse() ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Creates a new resource object or a list of resource objects |
77
|
|
|
* |
78
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
79
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
80
|
|
|
*/ |
81
|
|
|
public function postAction( ServerRequestInterface $request ) |
82
|
|
|
{ |
83
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
84
|
|
|
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->createAdmin()->post( $request, ( new Psr17Factory )->createResponse() ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Creates or updates a single resource object |
93
|
|
|
* |
94
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
95
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
96
|
|
|
*/ |
97
|
|
|
public function putAction( ServerRequestInterface $request ) |
98
|
|
|
{ |
99
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
100
|
|
|
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->createAdmin()->put( $request, ( new Psr17Factory )->createResponse() ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns the available HTTP verbs and the resource URLs |
109
|
|
|
* |
110
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
111
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
112
|
|
|
*/ |
113
|
|
|
public function optionsAction( ServerRequestInterface $request ) |
114
|
|
|
{ |
115
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
116
|
|
|
$this->authorize( 'admin', [JsonadmController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $this->createAdmin()->options( $request, ( new Psr17Factory )->createResponse() ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Returns the JsonAdm client |
125
|
|
|
* |
126
|
|
|
* @return \Aimeos\Admin\JsonAdm\Iface JsonAdm client |
127
|
|
|
*/ |
128
|
|
|
protected function createAdmin() : \Aimeos\Admin\JsonAdm\Iface |
129
|
|
|
{ |
130
|
|
|
$site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) ); |
|
|
|
|
131
|
|
|
$lang = Request::get( 'locale', config( 'app.locale', 'en' ) ); |
132
|
|
|
$resource = Route::input( 'resource', '' ); |
133
|
|
|
|
134
|
|
|
$aimeos = app( 'aimeos' )->get(); |
135
|
|
|
$templatePaths = $aimeos->getTemplatePaths( 'admin/jsonadm/templates' ); |
136
|
|
|
|
137
|
|
|
$context = app( 'aimeos.context' )->get( false, 'backend' ); |
138
|
|
|
$context->setI18n( app( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) ); |
139
|
|
|
$context->setLocale( app( 'aimeos.locale' )->getBackend( $context, $site ) ); |
140
|
|
|
$context->setView( app( 'aimeos.view' )->create( $context, $templatePaths, $lang ) ); |
141
|
|
|
|
142
|
|
|
return \Aimeos\Admin\JsonAdm::create( $context, $aimeos, $resource ); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.