RequestHandlerFactory.php
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace ACP\Editing;
use AC\ListScreenRepository\Storage;
use AC\Request;
use ACP\Editing\RequestHandler\BulkSave;
use ACP\Editing\RequestHandler\EditState;
use ACP\Editing\RequestHandler\InlineSave;
use ACP\Editing\RequestHandler\InlineValues;
use ACP\Editing\RequestHandler\SelectValues;
use LogicException;
class RequestHandlerFactory {
const METHOD_BULK_SAVE = 'bulk-save';
const METHOD_INLINE_SAVE = 'inline-save';
const METHOD_INLINE_VALUES = 'inline-values';
const METHOD_EDIT_STATE = 'edit-state';
const METHOD_INLINE_SELECT_VALUES = 'inline-select-values';
const METHOD_BULK_SELECT_VALUES = 'bulk-select-values';
/**
* @var Storage
*/
private $storage;
public function __construct( Storage $storage ) {
$this->storage = $storage;
}
/**
* @param Request $request
*
* @return RequestHandler
*/
public function create( Request $request ) {
switch ( $request->get( 'method' ) ) {
case self::METHOD_BULK_SAVE :
return new BulkSave( $this->storage );
case self::METHOD_INLINE_SAVE :
return new InlineSave( $this->storage );
case self::METHOD_INLINE_VALUES :
return new InlineValues( $this->storage );
case self::METHOD_EDIT_STATE :
return new EditState( new Preference\EditState() );
case self::METHOD_INLINE_SELECT_VALUES :
case self::METHOD_BULK_SELECT_VALUES :
return new SelectValues( $this->storage );
}
throw new LogicException( 'Invalid request.' );
}
}