1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2022-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
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Aimeos controller for the GraphQL Admin API |
20
|
|
|
*/ |
21
|
|
|
class GraphqlController extends Controller |
22
|
|
|
{ |
23
|
|
|
use AuthorizesRequests; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Creates a new resource object or a list of resource objects |
28
|
|
|
* |
29
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object |
30
|
|
|
* @return \Psr\Http\Message\ResponseInterface Response object containing the generated output |
31
|
|
|
*/ |
32
|
|
|
public function indexAction( ServerRequestInterface $request ) |
33
|
|
|
{ |
34
|
|
|
if( config( 'shop.authorize', true ) ) { |
|
|
|
|
35
|
|
|
$this->authorize( 'admin', [GraphqlController::class, array_merge( config( 'shop.roles', ['admin', 'editor'] ), ['api'] )] ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$site = Route::input( 'site', Request::get( 'site', config( 'shop.mshop.locale.site', 'default' ) ) ); |
39
|
|
|
$lang = Request::get( 'locale', config( 'app.locale', 'en' ) ); |
40
|
|
|
|
41
|
|
|
$context = app( 'aimeos.context' )->get( false, 'backend' ); |
|
|
|
|
42
|
|
|
$context->setI18n( app( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) ); |
|
|
|
|
43
|
|
|
$context->setLocale( app( 'aimeos.locale' )->getBackend( $context, $site ) ); |
44
|
|
|
$context->setView( app( 'aimeos.view' )->create( $context, [], $lang ) ); |
45
|
|
|
|
46
|
|
|
return \Aimeos\Admin\Graphql::execute( $context, $request ); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|