[ 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) 2016 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\Component\Router\Rules; 11 12 use Joomla\CMS\Component\Router\RouterView; 13 14 // phpcs:disable PSR1.Files.SideEffects 15 \defined('JPATH_PLATFORM') or die; 16 // phpcs:enable PSR1.Files.SideEffects 17 18 /** 19 * Rule to process URLs without a menu item 20 * 21 * @since 3.4 22 */ 23 class NomenuRules implements RulesInterface 24 { 25 /** 26 * Router this rule belongs to 27 * 28 * @var RouterView 29 * @since 3.4 30 */ 31 protected $router; 32 33 /** 34 * Class constructor. 35 * 36 * @param RouterView $router Router this rule belongs to 37 * 38 * @since 3.4 39 */ 40 public function __construct(RouterView $router) 41 { 42 $this->router = $router; 43 } 44 45 /** 46 * Dummy method to fulfil the interface requirements 47 * 48 * @param array &$query The query array to process 49 * 50 * @return void 51 * 52 * @since 3.4 53 * @codeCoverageIgnore 54 */ 55 public function preprocess(&$query) 56 { 57 } 58 59 /** 60 * Parse a menu-less URL 61 * 62 * @param array &$segments The URL segments to parse 63 * @param array &$vars The vars that result from the segments 64 * 65 * @return void 66 * 67 * @since 3.4 68 */ 69 public function parse(&$segments, &$vars) 70 { 71 $active = $this->router->menu->getActive(); 72 73 if (!\is_object($active)) { 74 $views = $this->router->getViews(); 75 76 if (isset($views[$segments[0]])) { 77 $vars['view'] = array_shift($segments); 78 $view = $views[$vars['view']]; 79 80 if (isset($view->key) && isset($segments[0])) { 81 if (\is_callable(array($this->router, 'get' . ucfirst($view->name) . 'Id'))) { 82 if ($view->parent_key && $this->router->app->input->get($view->parent_key)) { 83 $vars[$view->parent->key] = $this->router->app->input->get($view->parent_key); 84 $vars[$view->parent_key] = $this->router->app->input->get($view->parent_key); 85 } 86 87 if ($view->nestable) { 88 $vars[$view->key] = 0; 89 90 while (count($segments)) { 91 $segment = array_shift($segments); 92 $result = \call_user_func_array(array($this->router, 'get' . ucfirst($view->name) . 'Id'), array($segment, $vars)); 93 94 if (!$result) { 95 array_unshift($segments, $segment); 96 break; 97 } 98 99 $vars[$view->key] = preg_replace('/-/', ':', $result, 1); 100 } 101 } else { 102 $segment = array_shift($segments); 103 $result = \call_user_func_array(array($this->router, 'get' . ucfirst($view->name) . 'Id'), array($segment, $vars)); 104 105 $vars[$view->key] = preg_replace('/-/', ':', $result, 1); 106 } 107 } else { 108 $vars[$view->key] = preg_replace('/-/', ':', array_shift($segments), 1); 109 } 110 } 111 } 112 } 113 } 114 115 /** 116 * Build a menu-less URL 117 * 118 * @param array &$query The vars that should be converted 119 * @param array &$segments The URL segments to create 120 * 121 * @return void 122 * 123 * @since 3.4 124 */ 125 public function build(&$query, &$segments) 126 { 127 $menu_found = false; 128 129 if (isset($query['Itemid'])) { 130 $item = $this->router->menu->getItem($query['Itemid']); 131 132 if ( 133 !isset($query['option']) 134 || ($item && isset($item->query['option']) && $item->query['option'] === $query['option']) 135 ) { 136 $menu_found = true; 137 } 138 } 139 140 if (!$menu_found && isset($query['view'])) { 141 $views = $this->router->getViews(); 142 143 if (isset($views[$query['view']])) { 144 $view = $views[$query['view']]; 145 $segments[] = $query['view']; 146 147 if ($view->key && isset($query[$view->key])) { 148 if (\is_callable(array($this->router, 'get' . ucfirst($view->name) . 'Segment'))) { 149 $result = \call_user_func_array(array($this->router, 'get' . ucfirst($view->name) . 'Segment'), array($query[$view->key], $query)); 150 151 if ($view->nestable) { 152 array_pop($result); 153 154 while (count($result)) { 155 $segments[] = str_replace(':', '-', array_pop($result)); 156 } 157 } else { 158 $segments[] = str_replace(':', '-', array_pop($result)); 159 } 160 } else { 161 $segments[] = str_replace(':', '-', $query[$view->key]); 162 } 163 164 unset($query[$views[$query['view']]->key]); 165 } 166 167 unset($query['view']); 168 } 169 } 170 } 171 }
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 |