Skip to content

Commit

Permalink
[5.1] webservices plugins use concrete event classes
Browse files Browse the repository at this point in the history
  • Loading branch information
heelc29 committed Oct 8, 2023
1 parent bd79fd3 commit e6534ea
Show file tree
Hide file tree
Showing 17 changed files with 366 additions and 73 deletions.
26 changes: 22 additions & 4 deletions plugins/webservices/banners/src/Extension/Banners.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

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
Expand All @@ -23,19 +25,35 @@
*
* @since 4.0.0
*/
final class Banners extends CMSPlugin
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 ApiRouter &$router The API Routing object
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(&$router)
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();

$router->createCRUDRoutes(
'v1/banners',
'banners',
Expand Down Expand Up @@ -66,7 +84,7 @@ public function onBeforeApiRoute(&$router)
*
* @since 4.0.0
*/
private function createContentHistoryRoutes(&$router)
private function createContentHistoryRoutes(&$router): void
{
$defaults = [
'component' => 'com_contenthistory',
Expand Down
25 changes: 21 additions & 4 deletions plugins/webservices/config/src/Extension/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace Joomla\Plugin\WebServices\Config\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
Expand All @@ -23,19 +24,35 @@
*
* @since 4.0.0
*/
final class Config extends CMSPlugin
final class Config 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_config's API's routes in the application
*
* @param ApiRouter &$router The API Routing object
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(&$router)
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();

$defaults = ['component' => 'com_config'];
$getDefaults = array_merge(['public' => false], $defaults);

Expand Down
28 changes: 23 additions & 5 deletions plugins/webservices/contact/src/Extension/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace Joomla\Plugin\WebServices\Contact\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
Expand All @@ -23,19 +25,35 @@
*
* @since 4.0.0
*/
final class Contact extends CMSPlugin
final class Contact 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_contact's API's routes in the application
*
* @param ApiRouter &$router The API Routing object
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(&$router)
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();

$route = new Route(
['POST'],
'v1/contacts/form/:id',
Expand Down Expand Up @@ -72,7 +90,7 @@ public function onBeforeApiRoute(&$router)
*
* @since 4.0.0
*/
private function createFieldsRoutes(&$router)
private function createFieldsRoutes(&$router): void
{
$router->createCRUDRoutes(
'v1/fields/contacts/contact',
Expand Down Expand Up @@ -120,7 +138,7 @@ private function createFieldsRoutes(&$router)
*
* @since 4.0.0
*/
private function createContentHistoryRoutes(&$router)
private function createContentHistoryRoutes(&$router): void
{
$defaults = [
'component' => 'com_contenthistory',
Expand Down
28 changes: 23 additions & 5 deletions plugins/webservices/content/src/Extension/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace Joomla\Plugin\WebServices\Content\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
Expand All @@ -23,19 +25,35 @@
*
* @since 4.0.0
*/
final class Content extends CMSPlugin
final class Content 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_content's API's routes in the application
*
* @param ApiRouter &$router The API Routing object
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(&$router)
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();

$router->createCRUDRoutes(
'v1/content/articles',
'articles',
Expand All @@ -62,7 +80,7 @@ public function onBeforeApiRoute(&$router)
*
* @since 4.0.0
*/
private function createFieldsRoutes(&$router)
private function createFieldsRoutes(&$router): void
{
$router->createCRUDRoutes(
'v1/fields/content/articles',
Expand Down Expand Up @@ -98,7 +116,7 @@ private function createFieldsRoutes(&$router)
*
* @since 4.0.0
*/
private function createContentHistoryRoutes(&$router)
private function createContentHistoryRoutes(&$router): void
{
$defaults = [
'component' => 'com_contenthistory',
Expand Down
25 changes: 21 additions & 4 deletions plugins/webservices/installer/src/Extension/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

namespace Joomla\Plugin\WebServices\Installer\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
Expand All @@ -23,19 +24,35 @@
*
* @since 4.0.0
*/
final class Installer extends CMSPlugin
final class Installer 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_installer's API's routes in the application
*
* @param ApiRouter &$router The API Routing object
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(&$router)
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();

$defaults = ['component' => 'com_installer', 'public' => false];

$routes = [
Expand Down
31 changes: 24 additions & 7 deletions plugins/webservices/languages/src/Extension/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

namespace Joomla\Plugin\WebServices\Languages\Extension;

use Joomla\CMS\Factory;
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
Expand All @@ -24,19 +25,35 @@
*
* @since 4.0.0
*/
final class Languages extends CMSPlugin
final class Languages 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_languages's API's routes in the application
*
* @param ApiRouter &$router The API Routing object
* @param BeforeApiRouteEvent $event The event object
*
* @return void
*
* @since 4.0.0
*/
public function onBeforeApiRoute(&$router)
public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
{
$router = $event->getRouter();

$router->createCRUDRoutes(
'v1/languages/content',
'languages',
Expand All @@ -56,7 +73,7 @@ public function onBeforeApiRoute(&$router)
*
* @since 4.0.0
*/
private function createLanguageOverridesRoutes(&$router)
private function createLanguageOverridesRoutes(&$router): void
{
$defaults = ['component' => 'com_languages'];

Expand All @@ -68,7 +85,7 @@ private function createLanguageOverridesRoutes(&$router)
$router->addRoutes($routes);

/** @var \Joomla\Component\Languages\Administrator\Model\LanguagesModel $model */
$model = Factory::getApplication()->bootComponent('com_languages')
$model = $this->getApplication()->bootComponent('com_languages')
->getMVCFactory()->createModel('Languages', 'Administrator', ['ignore_request' => true]);

foreach ($model->getItems() as $item) {
Expand Down Expand Up @@ -112,7 +129,7 @@ private function createLanguageOverridesRoutes(&$router)
*
* @since 4.0.0
*/
private function createLanguageInstallerRoutes(&$router)
private function createLanguageInstallerRoutes(&$router): void
{
$defaults = ['component' => 'com_installer'];
$getDefaults = array_merge(['public' => false], $defaults);
Expand Down

0 comments on commit e6534ea

Please sign in to comment.