JsonadmController::patchAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
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\Routing\Controller;
14
use Illuminate\Support\Facades\Route;
15
use Illuminate\Support\Facades\Request;
16
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
17
use Psr\Http\Message\ServerRequestInterface;
18
use Zend\Diactoros\Response;
19
20
21
/**
22
 * Aimeos controller for the JSON REST API
23
 *
24
 * @package laravel
25
 * @subpackage Controller
26
 */
27
class JsonadmController extends Controller
28
{
29
	use AuthorizesRequests;
30
31
32
	/**
33
	 * Deletes the resource object or a list of resource objects
34
	 *
35
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
36
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
37
	 */
38
	public function deleteAction( ServerRequestInterface $request )
39
	{
40
		if( config( 'shop.authorize', true ) ) {
41
			$this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] );
42
		}
43
44
		return $this->createAdmin()->delete( $request, new Response() );
45
	}
46
47
48
	/**
49
	 * Returns the requested resource object or list of resource objects
50
	 *
51
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
52
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
53
	 */
54
	public function getAction( ServerRequestInterface $request )
55
	{
56
		if( config( 'shop.authorize', true ) ) {
57
			$this->authorize( 'admin', [JsonadmController::class, ['admin', 'api', 'editor']] );
58
		}
59
60
		return $this->createAdmin()->get( $request, new Response() );
61
	}
62
63
64
	/**
65
	 * Updates a 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 patchAction( ServerRequestInterface $request )
71
	{
72
		if( config( 'shop.authorize', true ) ) {
73
			$this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] );
74
		}
75
76
		return $this->createAdmin()->patch( $request, new Response() );
77
	}
78
79
80
	/**
81
	 * Creates a new resource object or a list of resource objects
82
	 *
83
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
84
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
85
	 */
86
	public function postAction( ServerRequestInterface $request )
87
	{
88
		if( config( 'shop.authorize', true ) ) {
89
			$this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] );
90
		}
91
92
		return $this->createAdmin()->post( $request, new Response() );
93
	}
94
95
96
	/**
97
	 * Creates or updates a single resource object
98
	 *
99
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
100
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
101
	 */
102
	public function putAction( ServerRequestInterface $request )
103
	{
104
		if( config( 'shop.authorize', true ) ) {
105
			$this->authorize( 'admin', [JsonadmController::class, ['admin', 'api']] );
106
		}
107
108
		return $this->createAdmin()->put( $request, new Response() );
109
	}
110
111
112
	/**
113
	 * Returns the available HTTP verbs and the resource URLs
114
	 *
115
	 * @param \Psr\Http\Message\ServerRequestInterface $request Request object
116
	 * @return \Psr\Http\Message\ResponseInterface Response object containing the generated output
117
	 */
118
	public function optionsAction( ServerRequestInterface $request )
119
	{
120
		if( config( 'shop.authorize', true ) ) {
121
			$this->authorize( 'admin', [JsonadmController::class, ['admin', 'api', 'editor']] );
122
		}
123
124
		return $this->createAdmin()->options( $request, new Response() );
125
	}
126
127
128
	/**
129
	 * Returns the JsonAdm client
130
	 *
131
	 * @return \Aimeos\Admin\JsonAdm\Iface JsonAdm client
132
	 */
133
	protected function createAdmin()
134
	{
135
		$site = Route::input( 'site', Request::get( 'site', 'default' ) );
136
		$lang = Request::get( 'locale', config( 'app.locale', 'en' ) );
137
		$resource = Route::input( 'resource' );
138
139
		$aimeos = app( 'aimeos' )->get();
140
		$templatePaths = $aimeos->getCustomPaths( 'admin/jsonadm/templates' );
141
142
		$context = app( 'aimeos.context' )->get( false, 'backend' );
143
		$context->setI18n( app('aimeos.i18n')->get( array( $lang, 'en' ) ) );
144
		$context->setLocale( app('aimeos.locale')->getBackend( $context, $site ) );
0 ignored issues
show
Bug introduced by Andreas
It seems like $site can also be of type object; however, parameter $site of Aimeos\Shop\Base\Locale::getBackend() 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 ignore-type  annotation

144
		$context->setLocale( app('aimeos.locale')->getBackend( $context, /** @scrutinizer ignore-type */ $site ) );
Loading history...
145
		$context->setView( app( 'aimeos.view' )->create( $context, $templatePaths, $lang ) );
146
147
		return \Aimeos\Admin\JsonAdm::create( $context, $aimeos, $resource );
0 ignored issues
show
Bug introduced by Andreas
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 ignore-type  annotation

147
		return \Aimeos\Admin\JsonAdm::create( $context, $aimeos, /** @scrutinizer ignore-type */ $resource );
Loading history...
148
	}
149
}
150