Jsonadm::putAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 4
rs 10
c 2
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Slim
7
 * @subpackage Controller
8
 */
9
10
11
namespace Aimeos\Slim\Controller;
12
13
use Psr\Container\ContainerInterface;
14
use Psr\Http\Message\ServerRequestInterface;
15
use Psr\Http\Message\ResponseInterface;
16
17
18
/**
19
 * Aimeos controller for the JSON REST API
20
 *
21
 * @package Slim
22
 * @subpackage Controller
23
 */
24
class Jsonadm
25
{
26
	/**
27
	 * Deletes the resource object or a list of resource objects
28
	 *
29
	 * @param ContainerInterface $container Dependency injection container
30
	 * @param ServerRequestInterface $request Request object
31
	 * @param ResponseInterface $response Response object
32
	 * @param array $args Associative list of route parameters
33
	 * @return ResponseInterface $response Modified response object with generated output
34
	 */
35
	public static function deleteAction( ContainerInterface $container, ServerRequestInterface $request,
36
		ResponseInterface $response, array $args ) : ResponseInterface
37
	{
38
		return self::createAdmin( $container, $request, $response, $args )->delete( $request, $response );
39
	}
40
41
42
	/**
43
	 * Returns the requested resource object or list of resource objects
44
	 *
45
	 * @param ContainerInterface $container Dependency injection container
46
	 * @param ServerRequestInterface $request Request object
47
	 * @param ResponseInterface $response Response object
48
	 * @param array $args Associative list of route parameters
49
	 * @return ResponseInterface $response Modified response object with generated output
50
	 */
51
	public static function getAction( ContainerInterface $container, ServerRequestInterface $request,
52
		ResponseInterface $response, array $args ) : ResponseInterface
53
	{
54
		return self::createAdmin( $container, $request, $response, $args )->get( $request, $response );
55
	}
56
57
58
	/**
59
	 * Updates a resource object or a list of resource objects
60
	 *
61
	 * @param ContainerInterface $container Dependency injection container
62
	 * @param ServerRequestInterface $request Request object
63
	 * @param ResponseInterface $response Response object
64
	 * @param array $args Associative list of route parameters
65
	 * @return ResponseInterface $response Modified response object with generated output
66
	 */
67
	public static function patchAction( ContainerInterface $container, ServerRequestInterface $request,
68
		ResponseInterface $response, array $args ) : ResponseInterface
69
	{
70
		return self::createAdmin( $container, $request, $response, $args )->patch( $request, $response );
71
	}
72
73
74
	/**
75
	 * Creates a new resource object or a list of resource objects
76
	 *
77
	 * @param ContainerInterface $container Dependency injection container
78
	 * @param ServerRequestInterface $request Request object
79
	 * @param ResponseInterface $response Response object
80
	 * @param array $args Associative list of route parameters
81
	 * @return ResponseInterface $response Modified response object with generated output
82
	 */
83
	public static function postAction( ContainerInterface $container, ServerRequestInterface $request,
84
		ResponseInterface $response, array $args ) : ResponseInterface
85
	{
86
		return self::createAdmin( $container, $request, $response, $args )->post( $request, $response );
87
	}
88
89
90
	/**
91
	 * Creates or updates a single resource object
92
	 *
93
	 * @param ContainerInterface $container Dependency injection container
94
	 * @param ServerRequestInterface $request Request object
95
	 * @param ResponseInterface $response Response object
96
	 * @param array $args Associative list of route parameters
97
	 * @return ResponseInterface $response Modified response object with generated output
98
	 */
99
	public static function putAction( ContainerInterface $container, ServerRequestInterface $request,
100
		ResponseInterface $response, array $args ) : ResponseInterface
101
	{
102
		return self::createAdmin( $container, $request, $response, $args )->put( $request, $response );
103
	}
104
105
106
	/**
107
	 * Returns the available HTTP verbs and the resource URLs
108
	 *
109
	 * @param ContainerInterface $container Dependency injection container
110
	 * @param ServerRequestInterface $request Request object
111
	 * @param ResponseInterface $response Response object
112
	 * @param array $args Associative list of route parameters
113
	 * @return ResponseInterface $response Modified response object with generated output
114
	 */
115
	public static function optionsAction( ContainerInterface $container, ServerRequestInterface $request,
116
		ResponseInterface $response, array $args ) : ResponseInterface
117
	{
118
		return self::createAdmin( $container, $request, $response, $args )->options( $request, $response );
119
	}
120
121
122
	/**
123
	 * Returns the resource controller
124
	 *
125
	 * @param ContainerInterface $container Dependency injection container
126
	 * @param ServerRequestInterface $request Request object
127
	 * @param ResponseInterface $response Response object
128
	 * @param array $args Associative list of route parameters
129
	 * @return \Aimeos\Admin\JsonAdm\Iface JSON admin client
130
	 */
131
	protected static function createAdmin( ContainerInterface $container, ServerRequestInterface $request,
132
		ResponseInterface $response, array $args ) : \Aimeos\Admin\JsonAdm\Iface
133
	{
134
		$resource = ( isset( $args['resource'] ) ? $args['resource'] : '' );
135
		$site = ( isset( $args['site'] ) ? $args['site'] : 'default' );
136
		$lang = ( isset( $args['lang'] ) ? $args['lang'] : 'en' );
137
138
		$aimeos = $container->get( 'aimeos' );
139
		$templatePaths = $aimeos->getCustomPaths( 'admin/jsonadm/templates' );
140
141
		$context = $container->get( 'aimeos.context' )->get( false, $args, 'backend' );
142
		$context->setI18n( $container->get( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) );
143
		$context->setLocale( $container->get( 'aimeos.locale' )->getBackend( $context, $site ) );
144
145
		$view = $container->get( 'aimeos.view' )->create( $context, $request, $response, $args, $templatePaths, $lang );
146
		$context->setView( $view );
147
148
		return \Aimeos\Admin\JsonAdm::create( $context, $aimeos, $resource );
149
	}
150
}
151