forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Banners.php
104 lines (91 loc) · 2.73 KB
/
Banners.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* @package Joomla.Plugin
* @subpackage Webservices.banners
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\WebServices\Banners\Extension;
use Joomla\CMS\Event\Application\BeforeApiRouteEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\ApiRouter;
use Joomla\Event\SubscriberInterface;
use Joomla\Router\Route;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Web Services adapter for com_banners.
*
* @since 4.0.0
*/
final class Banners extends CMSPlugin implements SubscriberInterface
{
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onBeforeApiRoute' => 'onBeforeApiRoute',
];
}
/**
* Registers com_banners's API's routes in the application
*
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();
$router->createCRUDRoutes(
'v1/banners',
'banners',
['component' => 'com_banners']
);
$router->createCRUDRoutes(
'v1/banners/clients',
'clients',
['component' => 'com_banners']
);
$router->createCRUDRoutes(
'v1/banners/categories',
'categories',
['component' => 'com_categories', 'extension' => 'com_banners']
);
$this->createContentHistoryRoutes($router);
}
/**
* Create contenthistory routes
*
* @param ApiRouter &$router The API Routing object
*
* @return void
*
* @since 4.0.0
*/
private function createContentHistoryRoutes(&$router): void
{
$defaults = [
'component' => 'com_contenthistory',
'type_alias' => 'com_banners.banner',
'type_id' => 9,
];
$getDefaults = array_merge(['public' => false], $defaults);
$routes = [
new Route(['GET'], 'v1/banners/:id/contenthistory', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
new Route(['PATCH'], 'v1/banners/:id/contenthistory/keep', 'history.keep', ['id' => '(\d+)'], $defaults),
new Route(['DELETE'], 'v1/banners/:id/contenthistory', 'history.delete', ['id' => '(\d+)'], $defaults),
];
$router->addRoutes($routes);
}
}