1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Component
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Default routing class for missing or legacy component routers
14 *
15 * @since 3.3
16 */
17 class JComponentRouterLegacy implements JComponentRouterInterface
18 {
19 /**
20 * Name of the component
21 *
22 * @var string
23 * @since 3.3
24 */
25 protected $component;
26
27 /**
28 * Constructor
29 *
30 * @param string $component Component name without the com_ prefix this router should react upon
31 *
32 * @since 3.3
33 */
34 public function __construct($component)
35 {
36 $this->component = $component;
37 }
38
39 /**
40 * Generic preprocess function for missing or legacy component router
41 *
42 * @param array $query An associative array of URL arguments
43 *
44 * @return array The URL arguments to use to assemble the subsequent URL.
45 *
46 * @since 3.3
47 */
48 public function preprocess($query)
49 {
50 return $query;
51 }
52
53 /**
54 * Generic build function for missing or legacy component router
55 *
56 * @param array &$query An array of URL arguments
57 *
58 * @return array The URL arguments to use to assemble the subsequent URL.
59 *
60 * @since 3.3
61 */
62 public function build(&$query)
63 {
64 $function = $this->component . 'BuildRoute';
65
66 if (function_exists($function))
67 {
68 $segments = $function($query);
69 $total = count($segments);
70
71 for ($i = 0; $i < $total; $i++)
72 {
73 $segments[$i] = str_replace(':', '-', $segments[$i]);
74 }
75
76 return $segments;
77 }
78
79 return array();
80 }
81
82 /**
83 * Generic parse function for missing or legacy component router
84 *
85 * @param array &$segments The segments of the URL to parse.
86 *
87 * @return array The URL attributes to be used by the application.
88 *
89 * @since 3.3
90 */
91 public function parse(&$segments)
92 {
93 $function = $this->component . 'ParseRoute';
94
95 if (function_exists($function))
96 {
97 $total = count($segments);
98
99 for ($i = 0; $i < $total; $i++)
100 {
101 $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1);
102 }
103
104 return $function($segments);
105 }
106
107 return array();
108 }
109 }
110