Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| HomeUrl | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| create | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
| sanitizeUrl | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * @package Zmsticketprinter |
| 6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | namespace BO\Zmsticketprinter\Helper; |
| 11 | |
| 12 | use BO\Mellon\Validator; |
| 13 | |
| 14 | class HomeUrl |
| 15 | { |
| 16 | /** |
| 17 | * check if new home url is requested, if not check if url exists in cookie, |
| 18 | * otherwise set current uri from request as new home url |
| 19 | * |
| 20 | **/ |
| 21 | |
| 22 | public static function create($request) |
| 23 | { |
| 24 | $homeUrl = null; |
| 25 | $validator = $request->getAttribute('validator'); |
| 26 | $ticketprinter = $validator->getParameter('ticketprinter')->isArray()->getValue(); |
| 27 | if ($ticketprinter && array_key_exists('home', $ticketprinter)) { |
| 28 | $homeUrl = Validator::value($ticketprinter['home'])->isUrl()->getValue(); |
| 29 | } elseif (!$homeUrl) { |
| 30 | $homeUrl = $request->getRequestTarget(); |
| 31 | } |
| 32 | // Clean up accumulated /& patterns from URL (bug in redirect chain) |
| 33 | $homeUrl = static::sanitizeUrl($homeUrl); |
| 34 | //\App::$log->debug("HOMEURL", [$homeUrl, $request->getRequestTarget()]); |
| 35 | \BO\Zmsclient\Ticketprinter::setHomeUrl($homeUrl, $request); |
| 36 | return $homeUrl; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Remove accumulated /& patterns from URL that occur due to redirect chain issues |
| 41 | */ |
| 42 | public static function sanitizeUrl($url) |
| 43 | { |
| 44 | // Remove repeated /& patterns (e.g., ?/&/&/& becomes ?) |
| 45 | $url = preg_replace('#\?(/&)+#', '?', $url); |
| 46 | // Remove any remaining leading /& after ? |
| 47 | $url = preg_replace('#\?/&#', '?', $url); |
| 48 | // Clean up empty query string marker |
| 49 | $url = preg_replace('#\?$#', '', $url); |
| 50 | return $url; |
| 51 | } |
| 52 | } |