Skip to content

Commit 79531db

Browse files
committed
Extension for collection actions autoload.
1 parent 934985e commit 79531db

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
}

0 commit comments

Comments
 (0)