Completed
Pull Request — master (#40)
by
unknown
10:59
created

CollectionExtension::beforeProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 1
dl 0
loc 19
ccs 0
cts 15
cp 0
crap 2
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2017, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Service\Extension;
13
14
use CakeDC\Api\Service\Action\Action;
15
use CakeDC\Api\Service\Action\Collection\AddEditAction;
16
use CakeDC\Api\Service\Action\Collection\DeleteAction;
17
use CakeDC\Api\Service\Service;
18
use Cake\Event\Event;
19
use Cake\Event\EventListenerInterface;
20
21
class CollectionExtension extends Extension implements EventListenerInterface
22
{
23
    /**
24
     * @var Service
25
     */
26
    protected $_service;
27
28
    /**
29
     * Returns a list of events this object is implementing. When the class is registered
30
     * in an event manager, each individual method will be associated with the respective event.
31
     *
32
     * @return array
33
     */
34
    public function implementedEvents()
35
    {
36
        return [
37
            'Service.beforeDispatch' => 'beforeProcess',
38
        ];
39
    }
40
41
    /**
42
     * before process
43
     *
44
     * @param Event $event An Event instance.
45
     * @return void
46
     */
47
    public function beforeProcess(Event $event)
48
    {
49
        $this->_service = $event->getData('service');
50
        $this->_service->mapAction('bulkAdd', AddEditAction::class, [
51
            'method' => ['POST'],
52
            'mapCors' => true,
53
            'path' => 'bulk'
54
        ]);
55
        $this->_service->mapAction('bulkEdit', AddEditAction::class, [
56
            'method' => ['PUT'],
57
            'mapCors' => true,
58
            'path' => 'bulk'
59
        ]);
60
        $this->_service->mapAction('bulkDelete', DeleteAction::class, [
61
            'method' => ['DELETE'],
62
            'mapCors' => true,
63
            'path' => 'bulk'
64
        ]);
65
    }
66
}
67