1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||||
5 | * @copyright Aimeos (aimeos.org), 2015-2016 |
||||
6 | * @package laravel |
||||
7 | * @subpackage Controller |
||||
8 | */ |
||||
9 | |||||
10 | |||||
11 | namespace Aimeos\Shop\Controller; |
||||
12 | |||||
13 | use Illuminate\Http\Request; |
||||
14 | use Illuminate\Routing\Controller; |
||||
15 | use Illuminate\Support\Facades\Input; |
||||
16 | use Illuminate\Support\Facades\Route; |
||||
17 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||||
18 | use Psr\Http\Message\ServerRequestInterface; |
||||
19 | use Zend\Diactoros\Response; |
||||
20 | |||||
21 | |||||
22 | /** |
||||
23 | * Aimeos controller for the JSON REST API |
||||
24 | * |
||||
25 | * @package laravel |
||||
26 | * @subpackage Controller |
||||
27 | */ |
||||
28 | class JsonadmController extends Controller |
||||
29 | { |
||||
30 | use AuthorizesRequests; |
||||
31 | |||||
32 | |||||
33 | /** |
||||
34 | * Deletes the resource object or a list of resource objects |
||||
35 | * |
||||
36 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
37 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
38 | */ |
||||
39 | public function deleteAction( ServerRequestInterface $request ) |
||||
40 | { |
||||
41 | if( config( 'shop.authorize', true ) ) { |
||||
42 | $this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] ); |
||||
43 | } |
||||
44 | |||||
45 | return $this->createAdmin()->delete( $request, new Response() ); |
||||
46 | } |
||||
47 | |||||
48 | |||||
49 | /** |
||||
50 | * Returns the requested resource object or list of resource objects |
||||
51 | * |
||||
52 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
53 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
54 | */ |
||||
55 | public function getAction( ServerRequestInterface $request ) |
||||
56 | { |
||||
57 | if( config( 'shop.authorize', true ) ) { |
||||
58 | $this->authorize( 'admin', [JsonadmController::class, ['admin', 'api', 'editor']] ); |
||||
59 | } |
||||
60 | |||||
61 | return $this->createAdmin()->get( $request, new Response() ); |
||||
62 | } |
||||
63 | |||||
64 | |||||
65 | /** |
||||
66 | * Updates a resource object or a list of resource objects |
||||
67 | * |
||||
68 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
69 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
70 | */ |
||||
71 | public function patchAction( ServerRequestInterface $request ) |
||||
72 | { |
||||
73 | if( config( 'shop.authorize', true ) ) { |
||||
74 | $this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] ); |
||||
75 | } |
||||
76 | |||||
77 | return $this->createAdmin()->patch( $request, new Response() ); |
||||
78 | } |
||||
79 | |||||
80 | |||||
81 | /** |
||||
82 | * Creates a new resource object or a list of resource objects |
||||
83 | * |
||||
84 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
85 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
86 | */ |
||||
87 | public function postAction( ServerRequestInterface $request ) |
||||
88 | { |
||||
89 | if( config( 'shop.authorize', true ) ) { |
||||
90 | $this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] ); |
||||
91 | } |
||||
92 | |||||
93 | return $this->createAdmin()->post( $request, new Response() ); |
||||
94 | } |
||||
95 | |||||
96 | |||||
97 | /** |
||||
98 | * Creates or updates a single resource object |
||||
99 | * |
||||
100 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
101 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
102 | */ |
||||
103 | public function putAction( ServerRequestInterface $request ) |
||||
104 | { |
||||
105 | if( config( 'shop.authorize', true ) ) { |
||||
106 | $this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] ); |
||||
107 | } |
||||
108 | |||||
109 | return $this->createAdmin()->put( $request, new Response() ); |
||||
110 | } |
||||
111 | |||||
112 | |||||
113 | /** |
||||
114 | * Returns the available HTTP verbs and the resource URLs |
||||
115 | * |
||||
116 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
117 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
118 | */ |
||||
119 | public function optionsAction( ServerRequestInterface $request ) |
||||
120 | { |
||||
121 | if( config( 'shop.authorize', true ) ) { |
||||
122 | $this->authorize( 'admin', [JsonadmController::class, ['admin', 'api', 'editor']] ); |
||||
123 | } |
||||
124 | |||||
125 | return $this->createAdmin()->options( $request, new Response() ); |
||||
126 | } |
||||
127 | |||||
128 | |||||
129 | /** |
||||
130 | * Returns the JsonAdm client |
||||
131 | * |
||||
132 | * @return \Aimeos\Admin\JsonAdm\Iface JsonAdm client |
||||
133 | */ |
||||
134 | protected function createAdmin() |
||||
135 | { |
||||
136 | $site = Route::input( 'site', Input::get( 'site', 'default' ) ); |
||||
137 | $lang = Input::get( 'locale', config( 'app.locale', 'en' ) ); |
||||
138 | $resource = Route::input( 'resource' ); |
||||
139 | |||||
140 | $aimeos = app( 'aimeos' )->get(); |
||||
141 | $templatePaths = $aimeos->getCustomPaths( 'admin/jsonadm/templates' ); |
||||
142 | |||||
143 | $context = app( 'aimeos.context' )->get( false, 'backend' ); |
||||
144 | $context->setI18n( app('aimeos.i18n')->get( array( $lang, 'en' ) ) ); |
||||
145 | $context->setLocale( app('aimeos.locale')->getBackend( $context, $site ) ); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
146 | $context->setView( app( 'aimeos.view' )->create( $context, $templatePaths, $lang ) ); |
||||
147 | |||||
148 | return \Aimeos\Admin\JsonAdm::create( $context, $aimeos, $resource ); |
||||
0 ignored issues
–
show
It seems like
$resource can also be of type object ; however, parameter $path of Aimeos\Admin\JsonAdm::create() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
149 | } |
||||
150 | } |
||||
151 |