-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1876 from tomudding/fix/index-php-in-url-assembly
fix: index.php being interpreted as valid base path when assembling URLs
- Loading branch information
Showing
9 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\View\Helper; | ||
|
||
use Application\Model\Enums\Languages; | ||
use Laminas\View\Helper\AbstractHelper; | ||
use Laminas\View\Helper\ServerUrl; | ||
|
||
use function implode; | ||
use function preg_replace; | ||
|
||
/** | ||
* View helper to generate URLs of the current page with a hash `#`. | ||
*/ | ||
class HashUrl extends AbstractHelper | ||
{ | ||
public function __construct(private readonly ServerUrl $serverUrlHelper) | ||
{ | ||
} | ||
|
||
public function __invoke(): string | ||
{ | ||
$path = null; | ||
if (isset($_SERVER['REQUEST_URI'])) { | ||
// Drop `/index.php` if it exists. | ||
$path = preg_replace( | ||
'/^((\/' . implode('|', Languages::stringValues()) . ')?\/index\.php)/', | ||
'', | ||
$_SERVER['REQUEST_URI'], | ||
); | ||
} | ||
|
||
return $this->serverUrlHelper->__invoke($path) . '#'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters