[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Extension; 11 12 use Joomla\CMS\Application\CMSApplicationInterface; 13 use Joomla\CMS\Categories\CategoryInterface; 14 use Joomla\CMS\Categories\CategoryServiceInterface; 15 use Joomla\CMS\Categories\CategoryServiceTrait; 16 use Joomla\CMS\Categories\SectionNotFoundException; 17 use Joomla\CMS\Component\Router\RouterInterface; 18 use Joomla\CMS\Component\Router\RouterLegacy; 19 use Joomla\CMS\Component\Router\RouterServiceInterface; 20 use Joomla\CMS\Dispatcher\DispatcherInterface; 21 use Joomla\CMS\Dispatcher\LegacyComponentDispatcher; 22 use Joomla\CMS\Fields\FieldsServiceInterface; 23 use Joomla\CMS\Filesystem\Path; 24 use Joomla\CMS\Menu\AbstractMenu; 25 use Joomla\CMS\MVC\Factory\LegacyFactory; 26 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 27 use Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface; 28 use Joomla\CMS\Tag\TagServiceInterface; 29 use Joomla\CMS\Tag\TagServiceTrait; 30 31 // phpcs:disable PSR1.Files.SideEffects 32 \defined('JPATH_PLATFORM') or die; 33 // phpcs:enable PSR1.Files.SideEffects 34 35 /** 36 * Access to component specific services. 37 * 38 * @since 4.0.0 39 */ 40 class LegacyComponent implements 41 ComponentInterface, 42 MVCFactoryServiceInterface, 43 CategoryServiceInterface, 44 FieldsServiceInterface, 45 RouterServiceInterface, 46 TagServiceInterface 47 { 48 use CategoryServiceTrait, TagServiceTrait { 49 CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait; 50 CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait; 51 } 52 53 /** 54 * @var string 55 * 56 * @since 4.0.0 57 */ 58 private $component; 59 60 /** 61 * LegacyComponentContainer constructor. 62 * 63 * @param string $component The component 64 * 65 * @since 4.0.0 66 */ 67 public function __construct(string $component) 68 { 69 $this->component = str_replace('com_', '', $component); 70 } 71 72 /** 73 * Returns the dispatcher for the given application. 74 * 75 * @param CMSApplicationInterface $application The application 76 * 77 * @return DispatcherInterface 78 * 79 * @since 4.0.0 80 */ 81 public function getDispatcher(CMSApplicationInterface $application): DispatcherInterface 82 { 83 return new LegacyComponentDispatcher($application); 84 } 85 86 /** 87 * Get the factory. 88 * 89 * @return MVCFactoryInterface 90 * 91 * @since 4.0.0 92 * @throws \UnexpectedValueException May be thrown if the factory has not been set. 93 */ 94 public function getMVCFactory(): MVCFactoryInterface 95 { 96 return new LegacyFactory(); 97 } 98 99 /** 100 * Returns the category service. 101 * 102 * @param array $options The options 103 * @param string $section The section 104 * 105 * @return CategoryInterface 106 * 107 * @since 4.0.0 108 * @throws SectionNotFoundException 109 */ 110 public function getCategory(array $options = [], $section = ''): CategoryInterface 111 { 112 $classname = ucfirst($this->component) . ucfirst($section) . 'Categories'; 113 114 if (!class_exists($classname)) { 115 $path = JPATH_SITE . '/components/com_' . $this->component . '/helpers/category.php'; 116 117 if (!is_file($path)) { 118 throw new SectionNotFoundException(); 119 } 120 121 include_once $path; 122 } 123 124 if (!class_exists($classname)) { 125 throw new SectionNotFoundException(); 126 } 127 128 return new $classname($options); 129 } 130 131 /** 132 * Adds Count Items for Category Manager. 133 * 134 * @param \stdClass[] $items The category objects 135 * @param string $section The section 136 * 137 * @return void 138 * 139 * @since 4.0.0 140 * @throws \Exception 141 */ 142 public function countItems(array $items, string $section) 143 { 144 $helper = $this->loadHelper(); 145 146 if (!$helper || !\is_callable(array($helper, 'countItems'))) { 147 return; 148 } 149 150 $helper::countItems($items, $section); 151 } 152 153 /** 154 * Adds Count Items for Tag Manager. 155 * 156 * @param \stdClass[] $items The content objects 157 * @param string $extension The name of the active view. 158 * 159 * @return void 160 * 161 * @since 4.0.0 162 * @throws \Exception 163 */ 164 public function countTagItems(array $items, string $extension) 165 { 166 $helper = $this->loadHelper(); 167 168 if (!$helper || !\is_callable(array($helper, 'countTagItems'))) { 169 return; 170 } 171 172 $helper::countTagItems($items, $extension); 173 } 174 175 /** 176 * Returns a valid section for articles. If it is not valid then null 177 * is returned. 178 * 179 * @param string $section The section to get the mapping for 180 * @param object $item The item 181 * 182 * @return string|null The new section 183 * 184 * @since 4.0.0 185 */ 186 public function validateSection($section, $item = null) 187 { 188 $helper = $this->loadHelper(); 189 190 if (!$helper || !\is_callable(array($helper, 'validateSection'))) { 191 return $section; 192 } 193 194 return $helper::validateSection($section, $item); 195 } 196 197 /** 198 * Returns valid contexts. 199 * 200 * @return array 201 * 202 * @since 4.0.0 203 */ 204 public function getContexts(): array 205 { 206 $helper = $this->loadHelper(); 207 208 if (!$helper || !\is_callable(array($helper, 'getContexts'))) { 209 return []; 210 } 211 212 return $helper::getContexts(); 213 } 214 215 /** 216 * Returns the router. 217 * 218 * @param CMSApplicationInterface $application The application object 219 * @param AbstractMenu $menu The menu object to work with 220 * 221 * @return RouterInterface 222 * 223 * @since 4.0.0 224 */ 225 public function createRouter(CMSApplicationInterface $application, AbstractMenu $menu): RouterInterface 226 { 227 $compname = ucfirst($this->component); 228 $class = $compname . 'Router'; 229 230 if (!class_exists($class)) { 231 // Use the component routing handler if it exists 232 $path = JPATH_SITE . '/components/com_' . $this->component . '/router.php'; 233 234 // Use the custom routing handler if it exists 235 if (is_file($path)) { 236 require_once $path; 237 } 238 } 239 240 if (class_exists($class)) { 241 $reflection = new \ReflectionClass($class); 242 243 if (\in_array('Joomla\\CMS\\Component\\Router\\RouterInterface', $reflection->getInterfaceNames())) { 244 return new $class($application, $menu); 245 } 246 } 247 248 return new RouterLegacy($compname); 249 } 250 251 /** 252 * Returns the classname of the legacy helper class. If none is found it returns false. 253 * 254 * @return boolean|string 255 * 256 * @since 4.0.0 257 */ 258 private function loadHelper() 259 { 260 $className = ucfirst($this->component) . 'Helper'; 261 262 if (class_exists($className)) { 263 return $className; 264 } 265 266 $file = Path::clean(JPATH_ADMINISTRATOR . '/components/com_' . $this->component . '/helpers/' . $this->component . '.php'); 267 268 if (!is_file($file)) { 269 return false; 270 } 271 272 \JLoader::register($className, $file); 273 274 if (!class_exists($className)) { 275 return false; 276 } 277 278 return $className; 279 } 280 }
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 |