1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||||
5 | * @copyright Aimeos (aimeos.org), 2017 |
||||
6 | * @package laravel |
||||
7 | * @subpackage Controller |
||||
8 | */ |
||||
9 | |||||
10 | |||||
11 | namespace Aimeos\Shop\Controller; |
||||
12 | |||||
13 | use Illuminate\Routing\Controller; |
||||
14 | use Illuminate\Support\Facades\Input; |
||||
15 | use Illuminate\Support\Facades\Route; |
||||
16 | use Psr\Http\Message\ServerRequestInterface; |
||||
17 | use Zend\Diactoros\Response; |
||||
18 | |||||
19 | |||||
20 | /** |
||||
21 | * Aimeos controller for the JSON REST API |
||||
22 | * |
||||
23 | * @package laravel |
||||
24 | * @subpackage Controller |
||||
25 | */ |
||||
26 | class JsonapiController extends Controller |
||||
27 | { |
||||
28 | /** |
||||
29 | * Deletes the resource object or a list of resource objects |
||||
30 | * |
||||
31 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
32 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
33 | */ |
||||
34 | public function deleteAction( ServerRequestInterface $request ) |
||||
35 | { |
||||
36 | return $this->createClient()->delete( $request, new Response() ); |
||||
37 | } |
||||
38 | |||||
39 | |||||
40 | /** |
||||
41 | * Returns the requested resource object or list of resource objects |
||||
42 | * |
||||
43 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
44 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
45 | */ |
||||
46 | public function getAction( ServerRequestInterface $request ) |
||||
47 | { |
||||
48 | return $this->createClient()->get( $request, new Response() ); |
||||
49 | } |
||||
50 | |||||
51 | |||||
52 | /** |
||||
53 | * Updates a resource object or a list of resource objects |
||||
54 | * |
||||
55 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
56 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
57 | */ |
||||
58 | public function patchAction( ServerRequestInterface $request ) |
||||
59 | { |
||||
60 | return $this->createClient()->patch( $request, new Response() ); |
||||
61 | } |
||||
62 | |||||
63 | |||||
64 | /** |
||||
65 | * Creates a new resource object or a list of resource objects |
||||
66 | * |
||||
67 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
68 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
69 | */ |
||||
70 | public function postAction( ServerRequestInterface $request ) |
||||
71 | { |
||||
72 | return $this->createClient()->post( $request, new Response() ); |
||||
73 | } |
||||
74 | |||||
75 | |||||
76 | /** |
||||
77 | * Creates or updates a single resource object |
||||
78 | * |
||||
79 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
80 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
81 | */ |
||||
82 | public function putAction( ServerRequestInterface $request ) |
||||
83 | { |
||||
84 | return $this->createClient()->put( $request, new Response() ); |
||||
85 | } |
||||
86 | |||||
87 | |||||
88 | /** |
||||
89 | * Returns the available HTTP verbs and the resource URLs |
||||
90 | * |
||||
91 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
||||
92 | * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
||||
93 | */ |
||||
94 | public function optionsAction( ServerRequestInterface $request ) |
||||
95 | { |
||||
96 | return $this->createClient()->options( $request, new Response() ); |
||||
97 | } |
||||
98 | |||||
99 | |||||
100 | /** |
||||
101 | * Returns the JsonAdm client |
||||
102 | * |
||||
103 | * @return \Aimeos\Client\JsonApi\Iface JsonApi client |
||||
104 | */ |
||||
105 | protected function createClient() |
||||
106 | { |
||||
107 | $resource = Route::input( 'resource' ); |
||||
108 | $related = Route::input( 'related', Input::get( 'related' ) ); |
||||
109 | |||||
110 | $aimeos = app( 'aimeos' )->get(); |
||||
111 | $tmplPaths = $aimeos->getCustomPaths( 'client/jsonapi/templates' ); |
||||
112 | |||||
113 | $context = app( 'aimeos.context' )->get(); |
||||
114 | $langid = $context->getLocale()->getLanguageId(); |
||||
115 | |||||
116 | $context->setView( app( 'aimeos.view' )->create( $context, $tmplPaths, $langid ) ); |
||||
117 | |||||
118 | return \Aimeos\Client\JsonApi::create( $context, $resource . '/' . $related ); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
Are you sure
$related of type object|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
119 | } |
||||
120 | } |
||||
121 |