[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Plugin 4 * @subpackage Webservices.Media 5 * 6 * @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 defined('_JEXEC') or die; 11 12 use Joomla\CMS\Plugin\CMSPlugin; 13 use Joomla\CMS\Router\ApiRouter; 14 use Joomla\Router\Route; 15 16 /** 17 * Web Services adapter for com_media. 18 * 19 * @since 4.1.0 20 */ 21 class PlgWebservicesMedia extends CMSPlugin 22 { 23 /** 24 * Load the language file on instantiation. 25 * 26 * @var boolean 27 * @since 4.1.0 28 */ 29 protected $autoloadLanguage = true; 30 31 /** 32 * Registers com_media's API's routes in the application. 33 * 34 * @param ApiRouter &$router The API Routing object 35 * 36 * @return void 37 * 38 * @since 4.1.0 39 */ 40 public function onBeforeApiRoute(&$router): void 41 { 42 $this->createAdapterReadRoutes( 43 $router, 44 'v1/media/adapters', 45 'adapters', 46 ['component' => 'com_media'] 47 ); 48 $this->createMediaCRUDRoutes( 49 $router, 50 'v1/media/files', 51 'media', 52 ['component' => 'com_media'] 53 ); 54 } 55 56 /** 57 * Creates adapter read routes. 58 * 59 * @param ApiRouter &$router The API Routing object 60 * @param string $baseName The base name of the component. 61 * @param string $controller The name of the controller that contains CRUD functions. 62 * @param array $defaults An array of default values that are used when the URL is matched. 63 * @param bool $publicGets Allow the public to make GET requests. 64 * 65 * @return void 66 * 67 * @since 4.1.0 68 */ 69 private function createAdapterReadRoutes(&$router, $baseName, $controller, $defaults = [], $publicGets = false): void 70 { 71 $getDefaults = array_merge(['public' => $publicGets], $defaults); 72 73 $routes = [ 74 new Route(['GET'], $baseName, $controller . '.displayList', [], $getDefaults), 75 new Route(['GET'], $baseName . '/:id', $controller . '.displayItem', [], $getDefaults), 76 ]; 77 78 $router->addRoutes($routes); 79 } 80 81 /** 82 * Creates media CRUD routes. 83 * 84 * @param ApiRouter &$router The API Routing object 85 * @param string $baseName The base name of the component. 86 * @param string $controller The name of the controller that contains CRUD functions. 87 * @param array $defaults An array of default values that are used when the URL is matched. 88 * @param bool $publicGets Allow the public to make GET requests. 89 * 90 * @return void 91 * 92 * @since 4.1.0 93 */ 94 private function createMediaCRUDRoutes(&$router, $baseName, $controller, $defaults = [], $publicGets = false): void 95 { 96 $getDefaults = array_merge(['public' => $publicGets], $defaults); 97 98 $routes = [ 99 new Route(['GET'], $baseName, $controller . '.displayList', [], $getDefaults), 100 // When the path ends with a backslash, then list the items 101 new Route(['GET'], $baseName . '/:path/', $controller . '.displayList', ['path' => '.*\/'], $getDefaults), 102 new Route(['GET'], $baseName . '/:path', $controller . '.displayItem', ['path' => '.*'], $getDefaults), 103 new Route(['POST'], $baseName, $controller . '.add', [], $defaults), 104 new Route(['PATCH'], $baseName . '/:path', $controller . '.edit', ['path' => '.*'], $defaults), 105 new Route(['DELETE'], $baseName . '/:path', $controller . '.delete', ['path' => '.*'], $defaults), 106 ]; 107 108 $router->addRoutes($routes); 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |