Completed
Push — master ( 32af77...22792e )
by Nazar
04:43
created

Route::process_route()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
/**
3
 * @package   CleverStyle CMS
4
 * @author    Nazar Mokrynskyi <[email protected]>
5
 * @copyright Copyright (c) 2015-2016, Nazar Mokrynskyi
6
 * @license   MIT License, see license.txt
7
 */
8
namespace cs;
9
/**
10
 * @deprecated Use `cs\Request` instead
11
 * @todo       Remove in 4.x
12
 */
13
class Route {
14
	use
15
		Singleton;
16
	/**
17
	 * Current mirror according to configuration
18
	 *
19
	 * @deprecated Use `cs\Request::$mirror_index` instead
20
	 *
21
	 * @var int
22
	 */
23
	public $mirror_index = -1;
24
	/**
25
	 * Relative address as it came from URL
26
	 *
27
	 * @deprecated Use `cs\Request::$uri` instead
28
	 *
29
	 * @var string
30
	 */
31
	public $raw_relative_address = '';
32
	/**
33
	 * Normalized processed representation of relative address, may differ from raw, should be used in most cases
34
	 *
35
	 * @deprecated Use `cs\Request::$path_normalized` instead
36
	 *
37
	 * @var string
38
	 */
39
	public $relative_address = '';
40
	/**
41
	 * Contains parsed route of current page url in form of array without module name and prefixes <i>admin</i>/<i>api</i>
42
	 *
43
	 * @deprecated Use `cs\Request::$route` instead
44
	 *
45
	 * @var array
46
	 */
47
	public $route = [];
48
	/**
49
	 * Like $route property, but excludes numerical items
50
	 *
51
	 * @deprecated Use `cs\Request::$route_path` instead
52
	 *
53
	 * @var string[]
54
	 */
55
	public $path = [];
56
	/**
57
	 * Like $route property, but only includes numerical items (opposite to route_path property)
58
	 *
59
	 * @deprecated Use `cs\Request::$route_ids` instead
60
	 *
61
	 * @var int[]
62
	 */
63
	public $ids = [];
64
	/**
65
	 * Loading of configuration, initialization of $Config, $Cache, $L and Page objects, Routing processing
66
	 *
67
	 * @throws ExitException
68
	 */
69
	protected function construct () {
70
		$Request                    = Request::instance();
71
		$this->mirror_index         = &$Request->mirror_index;
0 ignored issues
show
Deprecated Code introduced by
The property cs\Route::$mirror_index has been deprecated with message: Use `cs\Request::$mirror_index` instead

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
72
		$this->raw_relative_address = &$Request->uri;
0 ignored issues
show
Deprecated Code introduced by
The property cs\Route::$raw_relative_address has been deprecated with message: Use `cs\Request::$uri` instead

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
73
		$this->relative_address     = &$Request->path_normalized;
0 ignored issues
show
Deprecated Code introduced by
The property cs\Route::$relative_address has been deprecated with message: Use `cs\Request::$path_normalized` instead

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
74
		$this->route                = &$Request->route;
0 ignored issues
show
Deprecated Code introduced by
The property cs\Route::$route has been deprecated with message: Use `cs\Request::$route` instead

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
75
		$this->path                 = &$Request->route_path;
0 ignored issues
show
Deprecated Code introduced by
The property cs\Route::$path has been deprecated with message: Use `cs\Request::$route_path` instead

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
76
		$this->ids                  = &$Request->route_ids;
0 ignored issues
show
Deprecated Code introduced by
The property cs\Route::$ids has been deprecated with message: Use `cs\Request::$route_ids` instead

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
77
	}
78
	/**
79
	 * Process raw relative route.
80
	 *
81
	 * @deprecated Use `cs\Request::analyze_route_path()` instead
82
	 *
83
	 * As result returns current route in system in form of array, corrected page address, detects MODULE, that responsible for processing this url,
84
	 * whether this is API call, ADMIN page, or HOME page
85
	 *
86
	 * @param string $raw_relative_address
87
	 *
88
	 * @return false|string[] Relative address or <i>false</i> if access denied (occurs when admin access is limited by IP). Array contains next elements:
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
89
	 *                        route, relative_address, ADMIN, API, MODULE, HOME
90
	 */
91
	function process_route ($raw_relative_address) {
92
		$path   = explode('?', $raw_relative_address, 2)[0];
93
		$result = Request::instance()->analyze_route_path($path);
94
		return [
95
			'route'            => $result['route'],
96
			'relative_address' => $result['path_normalized'],
97
			'ADMIN'            => $result['admin_path'],
98
			'API'              => $result['api_path'],
99
			'MODULE'           => $result['current_module'],
100
			'HOME'             => $result['home_page']
101
		];
102
	}
103
}
104