|
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\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 JsonapiController extends Controller |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Deletes the resource object or a list of resource objects |
|
32
|
|
|
* |
|
33
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
|
34
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
|
35
|
|
|
*/ |
|
36
|
|
|
public function deleteAction( ServerRequestInterface $request ) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->createClient()->delete( $request, new Response() ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the requested resource object or list of resource objects |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
|
46
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getAction( ServerRequestInterface $request ) |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->createClient()->get( $request, new Response() ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Updates a resource object or a list of resource objects |
|
56
|
|
|
* |
|
57
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
|
58
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
|
59
|
|
|
*/ |
|
60
|
|
|
public function patchAction( ServerRequestInterface $request ) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->createClient()->patch( $request, new Response() ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Creates a new resource object or a list of resource objects |
|
68
|
|
|
* |
|
69
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
|
70
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
|
71
|
|
|
*/ |
|
72
|
|
|
public function postAction( ServerRequestInterface $request ) |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->createClient()->post( $request, new Response() ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Creates or updates a single resource object |
|
80
|
|
|
* |
|
81
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
|
82
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
|
83
|
|
|
*/ |
|
84
|
|
|
public function putAction( ServerRequestInterface $request ) |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->createClient()->put( $request, new Response() ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the available HTTP verbs and the resource URLs |
|
92
|
|
|
* |
|
93
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
|
94
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
|
95
|
|
|
*/ |
|
96
|
|
|
public function optionsAction( ServerRequestInterface $request ) |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->createClient()->options( $request, new Response() ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns the JsonAdm client |
|
104
|
|
|
* |
|
105
|
|
|
* @return \Aimeos\Client\JsonApi\Iface JsonApi client |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function createClient() |
|
108
|
|
|
{ |
|
109
|
|
|
$site = Route::input( 'site', Input::get( 'site', 'default' ) ); |
|
|
|
|
|
|
110
|
|
|
$lang = Input::get( 'lang', config( 'app.locale', 'en' ) ); |
|
111
|
|
|
$resource = Route::input( 'resource' ); |
|
112
|
|
|
|
|
113
|
|
|
$tmplPaths = app( '\Aimeos\Shop\Base\Aimeos' )->get()->getCustomPaths( 'client/jsonapi/templates' ); |
|
114
|
|
|
|
|
115
|
|
|
$context = app( '\Aimeos\Shop\Base\Context' )->get(); |
|
116
|
|
|
$context->setView( app( '\Aimeos\Shop\Base\View' )->create( $context, $tmplPaths, $lang ) ); |
|
117
|
|
|
|
|
118
|
|
|
return \Aimeos\Client\JsonApi\Factory::createClient( $context, $tmplPaths, $resource ); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.