|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Cortex Foundation Module. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Cortex Foundation Module |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
declare(strict_types=1); |
|
17
|
|
|
|
|
18
|
|
|
namespace Cortex\Foundation\Overrides\Illuminate\Routing; |
|
19
|
|
|
|
|
20
|
|
|
use Illuminate\Routing\UrlGenerator as BaseUrlGenerator; |
|
21
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
|
22
|
|
|
|
|
23
|
|
|
class UrlGenerator extends BaseUrlGenerator |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* The backend URI. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $backendUri = 'backend'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Set the backend URI. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $backendUri |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
public function setBackendUri($backendUri) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->backendUri = $backendUri; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Generate an absolute URL to the given admin path. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $path |
|
48
|
|
|
* @param array $parameters |
|
49
|
|
|
* @param bool $secure |
|
|
|
|
|
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function toBackend($path, array $parameters = [], $secure = null) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->to("{$this->backendUri}/{$path}", $parameters, $secure); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Generate a absolute URL to the given path. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $path |
|
62
|
|
|
* @param mixed $extra |
|
63
|
|
|
* @param bool|null $secure |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function to($path, $extra = [], $secure = null) |
|
68
|
|
|
{ |
|
69
|
|
|
return config('rinvex.cortex.route.locale_prefix') |
|
70
|
|
|
? LaravelLocalization::localizeURL(parent::to($path, $extra, $secure)) |
|
71
|
|
|
: parent::to($path, $extra, $secure); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function routeUrl() |
|
78
|
|
|
{ |
|
79
|
|
|
if (! $this->routeGenerator) { |
|
80
|
|
|
$this->routeGenerator = new RouteUrlGenerator($this, $this->request); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $this->routeGenerator; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
|
|
public function previous($fallback = false) |
|
90
|
|
|
{ |
|
91
|
|
|
return ($previousUrl = $this->request->input('previous_url')) ? $this->to($previousUrl) : parent::previous($fallback); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* {@inheritdoc} |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function toRoute($route, $parameters, $absolute) |
|
98
|
|
|
{ |
|
99
|
|
|
// Bind {locale} route parameter |
|
100
|
|
|
if (config('rinvex.cortex.route.locale_prefix') && ! isset($parameters['locale'])) { |
|
101
|
|
|
$parameters['locale'] = LaravelLocalization::getCurrentLocale(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->routeUrl()->to( |
|
105
|
|
|
$route, $this->formatParameters($parameters), $absolute |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.