File tree Expand file tree Collapse file tree 3 files changed +4
-50
lines changed Expand file tree Collapse file tree 3 files changed +4
-50
lines changed Original file line number Diff line number Diff line change 14
14
"nette/utils" : " ^3.2" ,
15
15
"nette/application" : " ^3.1" ,
16
16
"nette/di" : " ^3.0" ,
17
- "league/commonmark" : " ^1.5"
17
+ "league/commonmark" : " ^1.5" ,
18
+ "baraja-core/url" : " ^1.0"
18
19
},
19
20
"require-dev" : {
20
21
"phpstan/phpstan" : " ^0.12.18" ,
Original file line number Diff line number Diff line change 5
5
namespace Baraja \Markdown ;
6
6
7
7
8
+ use Baraja \Url \Url ;
8
9
use Nette \Application \LinkGenerator ;
9
10
use Nette \Application \UI \InvalidLinkException ;
10
11
use Nette \Localization \Translator ;
@@ -120,18 +121,7 @@ function (array $match): string {
120
121
121
122
protected function resolveBaseUrl (): string
122
123
{
123
- if ($ this ->baseUrl === null ) {
124
- if (($ baseUrl = Helpers::getBaseUrl ()) === null ) {
125
- throw new \LogicException (
126
- 'BaseUrl can not be null. ' . "\n"
127
- . 'To solve this issue: BaseUrl is automatically detected according to the current HTTP request. '
128
- . 'In CLI mode (when there is no HTTP request), you need to manually define the BaseUrl by the setBaseUrl() method. '
129
- );
130
- }
131
- $ this ->baseUrl = $ baseUrl ;
132
- }
133
-
134
- return $ this ->baseUrl ;
124
+ return $ this ->baseUrl ?? Url::get ()->getBaseUrl ();
135
125
}
136
126
137
127
Original file line number Diff line number Diff line change @@ -15,43 +15,6 @@ public function __construct()
15
15
}
16
16
17
17
18
- /**
19
- * Return current absolute URL.
20
- * Return null, if current URL does not exist (for example in CLI mode).
21
- */
22
- public static function getCurrentUrl (): ?string
23
- {
24
- if (!isset ($ _SERVER ['REQUEST_URI ' ], $ _SERVER ['HTTP_HOST ' ])) {
25
- return null ;
26
- }
27
-
28
- return (isset ($ _SERVER ['HTTPS ' ]) && $ _SERVER ['HTTPS ' ] === 'on ' ? 'https ' : 'http ' )
29
- . ':// ' . $ _SERVER ['HTTP_HOST ' ] . $ _SERVER ['REQUEST_URI ' ];
30
- }
31
-
32
-
33
- public static function getBaseUrl (): ?string
34
- {
35
- static $ return ;
36
-
37
- if ($ return !== null ) {
38
- return $ return ;
39
- }
40
- if (($ currentUrl = self ::getCurrentUrl ()) !== null ) {
41
- if (preg_match ('/^(https?:\/\/.+)\/www\// ' , $ currentUrl , $ localUrlParser )) {
42
- $ return = $ localUrlParser [0 ];
43
- } elseif (preg_match ('/^(https?:\/\/[^\/]+)/ ' , $ currentUrl , $ publicUrlParser )) {
44
- $ return = $ publicUrlParser [1 ];
45
- }
46
- }
47
- if ($ return !== null ) {
48
- $ return = rtrim ($ return , '/ ' );
49
- }
50
-
51
- return $ return ;
52
- }
53
-
54
-
55
18
/**
56
19
* Sanitizes string for use inside href attribute.
57
20
*/
You can’t perform that action at this time.
0 commit comments