@@ -7,21 +7,21 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | interface RequestHandlerInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 10 | +/** |
|
| 11 | 11 | * Get the target function or class and method |
| 12 | 12 | * |
| 13 | 13 | * @return Target|null |
| 14 | 14 | */ |
| 15 | - public function getTarget(): ?Target; |
|
| 15 | +public function getTarget(): ?Target; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 17 | +/** |
|
| 18 | 18 | * @param ServerRequestInterface $xRequest |
| 19 | 19 | * |
| 20 | 20 | * @return Target |
| 21 | 21 | */ |
| 22 | - public function setTarget(ServerRequestInterface $xRequest): Target; |
|
| 22 | +public function setTarget(ServerRequestInterface $xRequest): Target; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * Check if this plugin can process the current request |
| 26 | 26 | * |
| 27 | 27 | * Called by the <Jaxon\Plugin\RequestManager> when a request has been received to determine |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return bool |
| 33 | 33 | */ |
| 34 | - public static function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 34 | +public static function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Process the current request |
| 38 | 38 | * |
| 39 | 39 | * Called by the <Jaxon\Plugin\RequestManager> when a request is being processed. |
@@ -42,5 +42,5 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public function processRequest(): void; |
|
| 45 | +public function processRequest(): void; |
|
| 46 | 46 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | abstract class AbstractAnnotation extends Annotation implements IAnnotationParser |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * Save the annotation value |
| 25 | 25 | * |
| 26 | 26 | * @param Metadata $xMetadata |
@@ -28,5 +28,5 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | - abstract public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void; |
|
| 31 | +abstract public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void; |
|
| 32 | 32 | } |
@@ -10,33 +10,33 @@ |
||
| 10 | 10 | |
| 11 | 11 | final class MinifierTest extends TestCase |
| 12 | 12 | { |
| 13 | - public function testFileNotFound() |
|
| 14 | - { |
|
| 15 | - $sSrcFile = __DIR__ . '/../minifier/nosrc.js'; |
|
| 16 | - $sDstMinFile = __DIR__ . '/../minifier/dst.min.js'; |
|
| 17 | - $xMinifier = new FileMinifier(); |
|
| 18 | - |
|
| 19 | - $this->assertFalse($xMinifier->minify($sSrcFile, $sDstMinFile)); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - public function testFileError() |
|
| 23 | - { |
|
| 24 | - $sSrcFile = __DIR__ . '/../minifier/error.js'; |
|
| 25 | - $sDstMinFile = __DIR__ . '/../minifier/dst.min.js'; |
|
| 26 | - $xMinifier = new FileMinifier(); |
|
| 27 | - |
|
| 28 | - $this->assertFalse($xMinifier->minify($sSrcFile, $sDstMinFile)); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function testMinifier() |
|
| 32 | - { |
|
| 33 | - $sSrcFile = __DIR__ . '/../minifier/src.js'; |
|
| 34 | - $sSrcMinFile = __DIR__ . '/../minifier/src.min.js'; |
|
| 35 | - $sDstMinFile = __DIR__ . '/../minifier/dst.min.js'; |
|
| 36 | - $xMinifier = new FileMinifier(); |
|
| 37 | - |
|
| 38 | - $this->assertTrue($xMinifier->minify($sSrcFile, $sDstMinFile)); |
|
| 39 | - $this->assertTrue(file_exists($sDstMinFile)); |
|
| 40 | - $this->assertEquals(filesize($sSrcMinFile), filesize($sDstMinFile)); |
|
| 41 | - } |
|
| 13 | +public function testFileNotFound() |
|
| 14 | +{ |
|
| 15 | +$sSrcFile = __DIR__ . '/../minifier/nosrc.js'; |
|
| 16 | +$sDstMinFile = __DIR__ . '/../minifier/dst.min.js'; |
|
| 17 | +$xMinifier = new FileMinifier(); |
|
| 18 | + |
|
| 19 | +$this->assertFalse($xMinifier->minify($sSrcFile, $sDstMinFile)); |
|
| 20 | +} |
|
| 21 | + |
|
| 22 | +public function testFileError() |
|
| 23 | +{ |
|
| 24 | +$sSrcFile = __DIR__ . '/../minifier/error.js'; |
|
| 25 | +$sDstMinFile = __DIR__ . '/../minifier/dst.min.js'; |
|
| 26 | +$xMinifier = new FileMinifier(); |
|
| 27 | + |
|
| 28 | +$this->assertFalse($xMinifier->minify($sSrcFile, $sDstMinFile)); |
|
| 29 | +} |
|
| 30 | + |
|
| 31 | +public function testMinifier() |
|
| 32 | +{ |
|
| 33 | +$sSrcFile = __DIR__ . '/../minifier/src.js'; |
|
| 34 | +$sSrcMinFile = __DIR__ . '/../minifier/src.min.js'; |
|
| 35 | +$sDstMinFile = __DIR__ . '/../minifier/dst.min.js'; |
|
| 36 | +$xMinifier = new FileMinifier(); |
|
| 37 | + |
|
| 38 | +$this->assertTrue($xMinifier->minify($sSrcFile, $sDstMinFile)); |
|
| 39 | +$this->assertTrue(file_exists($sDstMinFile)); |
|
| 40 | +$this->assertEquals(filesize($sSrcMinFile), filesize($sDstMinFile)); |
|
| 41 | +} |
|
| 42 | 42 | } |
@@ -7,51 +7,51 @@ |
||
| 7 | 7 | |
| 8 | 8 | final class TemplateTest extends TestCase |
| 9 | 9 | { |
| 10 | - /** |
|
| 10 | +/** |
|
| 11 | 11 | * @var TemplateEngine |
| 12 | 12 | */ |
| 13 | - protected $xTemplateEngine; |
|
| 14 | - |
|
| 15 | - protected function setUp(): void |
|
| 16 | - { |
|
| 17 | - $this->xTemplateEngine = new TemplateEngine(); |
|
| 18 | - $this->xTemplateEngine->addNamespace('test', __DIR__ . '/../templates', '.php'); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function testTemplate() |
|
| 22 | - { |
|
| 23 | - $this->assertEquals('Good morning Mr. Johnson', |
|
| 24 | - $this->xTemplateEngine->render('test::simple', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - public function testDefaultNamespace() |
|
| 28 | - { |
|
| 29 | - $this->xTemplateEngine->setDefaultNamespace('test'); |
|
| 30 | - $this->assertEquals('Good morning Mr. Johnson', |
|
| 31 | - $this->xTemplateEngine->render('simple', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function testRenderEmbeddedTemplate() |
|
| 35 | - { |
|
| 36 | - $this->assertEquals('Good morning Mr. Johnson.', |
|
| 37 | - $this->xTemplateEngine->render('test::embedded-content', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function testIncludeEmbeddedTemplate() |
|
| 41 | - { |
|
| 42 | - $this->assertEquals('Good morning Mr. Johnson.', |
|
| 43 | - $this->xTemplateEngine->render('test::embedded-include', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function testMissingTemplate() |
|
| 47 | - { |
|
| 48 | - $this->assertEquals('', |
|
| 49 | - $this->xTemplateEngine->render('test::missing', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function testUnknownNamespace() |
|
| 53 | - { |
|
| 54 | - $this->assertEquals('', |
|
| 55 | - $this->xTemplateEngine->render('toast::embedded-include', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 56 | - } |
|
| 13 | +protected $xTemplateEngine; |
|
| 14 | + |
|
| 15 | +protected function setUp(): void |
|
| 16 | +{ |
|
| 17 | +$this->xTemplateEngine = new TemplateEngine(); |
|
| 18 | +$this->xTemplateEngine->addNamespace('test', __DIR__ . '/../templates', '.php'); |
|
| 19 | +} |
|
| 20 | + |
|
| 21 | +public function testTemplate() |
|
| 22 | +{ |
|
| 23 | +$this->assertEquals('Good morning Mr. Johnson', |
|
| 24 | +$this->xTemplateEngine->render('test::simple', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 25 | +} |
|
| 26 | + |
|
| 27 | +public function testDefaultNamespace() |
|
| 28 | +{ |
|
| 29 | +$this->xTemplateEngine->setDefaultNamespace('test'); |
|
| 30 | +$this->assertEquals('Good morning Mr. Johnson', |
|
| 31 | +$this->xTemplateEngine->render('simple', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 32 | +} |
|
| 33 | + |
|
| 34 | +public function testRenderEmbeddedTemplate() |
|
| 35 | +{ |
|
| 36 | +$this->assertEquals('Good morning Mr. Johnson.', |
|
| 37 | +$this->xTemplateEngine->render('test::embedded-content', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 38 | +} |
|
| 39 | + |
|
| 40 | +public function testIncludeEmbeddedTemplate() |
|
| 41 | +{ |
|
| 42 | +$this->assertEquals('Good morning Mr. Johnson.', |
|
| 43 | +$this->xTemplateEngine->render('test::embedded-include', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 44 | +} |
|
| 45 | + |
|
| 46 | +public function testMissingTemplate() |
|
| 47 | +{ |
|
| 48 | +$this->assertEquals('', |
|
| 49 | +$this->xTemplateEngine->render('test::missing', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 50 | +} |
|
| 51 | + |
|
| 52 | +public function testUnknownNamespace() |
|
| 53 | +{ |
|
| 54 | +$this->assertEquals('', |
|
| 55 | +$this->xTemplateEngine->render('toast::embedded-include', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 56 | +} |
|
| 57 | 57 | } |
@@ -7,87 +7,87 @@ |
||
| 7 | 7 | |
| 8 | 8 | final class TranslatorTest extends TestCase |
| 9 | 9 | { |
| 10 | - /** |
|
| 10 | +/** |
|
| 11 | 11 | * @var Translator |
| 12 | 12 | */ |
| 13 | - protected $xTranslator; |
|
| 13 | +protected $xTranslator; |
|
| 14 | 14 | |
| 15 | - protected function setUp(): void |
|
| 16 | - { |
|
| 17 | - $this->xTranslator = new Translator(); |
|
| 18 | - $this->xTranslator->loadTranslations(__DIR__ . '/../translations/test.en.php', 'en'); |
|
| 19 | - $this->xTranslator->loadTranslations(__DIR__ . '/../translations/test.fr.php', 'fr'); |
|
| 20 | - } |
|
| 15 | +protected function setUp(): void |
|
| 16 | +{ |
|
| 17 | +$this->xTranslator = new Translator(); |
|
| 18 | +$this->xTranslator->loadTranslations(__DIR__ . '/../translations/test.en.php', 'en'); |
|
| 19 | +$this->xTranslator->loadTranslations(__DIR__ . '/../translations/test.fr.php', 'fr'); |
|
| 20 | +} |
|
| 21 | 21 | |
| 22 | - public function testFileWithBadData() |
|
| 23 | - { |
|
| 24 | - $this->assertFalse($this->xTranslator->loadTranslations(__DIR__ . '/../translations/error.php', 'en')); |
|
| 25 | - } |
|
| 22 | +public function testFileWithBadData() |
|
| 23 | +{ |
|
| 24 | +$this->assertFalse($this->xTranslator->loadTranslations(__DIR__ . '/../translations/error.php', 'en')); |
|
| 25 | +} |
|
| 26 | 26 | |
| 27 | - public function testFileNotFound() |
|
| 28 | - { |
|
| 29 | - $this->assertFalse($this->xTranslator->loadTranslations(__DIR__ . '/../translations/not-found.php', 'en')); |
|
| 30 | - } |
|
| 27 | +public function testFileNotFound() |
|
| 28 | +{ |
|
| 29 | +$this->assertFalse($this->xTranslator->loadTranslations(__DIR__ . '/../translations/not-found.php', 'en')); |
|
| 30 | +} |
|
| 31 | 31 | |
| 32 | - public function testMissingEnTranslations() |
|
| 33 | - { |
|
| 34 | - $this->xTranslator->setLocale('en'); |
|
| 35 | - $this->assertEquals('salutations.hello', $this->xTranslator->trans('salutations.hello')); |
|
| 36 | - } |
|
| 32 | +public function testMissingEnTranslations() |
|
| 33 | +{ |
|
| 34 | +$this->xTranslator->setLocale('en'); |
|
| 35 | +$this->assertEquals('salutations.hello', $this->xTranslator->trans('salutations.hello')); |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - public function testMissingFrTranslations() |
|
| 39 | - { |
|
| 40 | - $this->xTranslator->setLocale('fr'); |
|
| 41 | - $this->assertEquals('salutations.hello', $this->xTranslator->trans('salutations.hello')); |
|
| 42 | - } |
|
| 38 | +public function testMissingFrTranslations() |
|
| 39 | +{ |
|
| 40 | +$this->xTranslator->setLocale('fr'); |
|
| 41 | +$this->assertEquals('salutations.hello', $this->xTranslator->trans('salutations.hello')); |
|
| 42 | +} |
|
| 43 | 43 | |
| 44 | - public function testSimpleEnTranslations() |
|
| 45 | - { |
|
| 46 | - $this->xTranslator->setLocale('en'); |
|
| 47 | - $this->assertEquals('Good morning', $this->xTranslator->trans('salutations.morning')); |
|
| 48 | - $this->assertEquals('Good afternoon', $this->xTranslator->trans('salutations.afternoon')); |
|
| 49 | - } |
|
| 44 | +public function testSimpleEnTranslations() |
|
| 45 | +{ |
|
| 46 | +$this->xTranslator->setLocale('en'); |
|
| 47 | +$this->assertEquals('Good morning', $this->xTranslator->trans('salutations.morning')); |
|
| 48 | +$this->assertEquals('Good afternoon', $this->xTranslator->trans('salutations.afternoon')); |
|
| 49 | +} |
|
| 50 | 50 | |
| 51 | - public function testSimpleFrTranslations() |
|
| 52 | - { |
|
| 53 | - $this->xTranslator->setLocale('fr'); |
|
| 54 | - $this->assertEquals('Bonjour', $this->xTranslator->trans('salutations.morning')); |
|
| 55 | - $this->assertEquals('Bonsoir', $this->xTranslator->trans('salutations.afternoon')); |
|
| 56 | - } |
|
| 51 | +public function testSimpleFrTranslations() |
|
| 52 | +{ |
|
| 53 | +$this->xTranslator->setLocale('fr'); |
|
| 54 | +$this->assertEquals('Bonjour', $this->xTranslator->trans('salutations.morning')); |
|
| 55 | +$this->assertEquals('Bonsoir', $this->xTranslator->trans('salutations.afternoon')); |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - public function testEnTranslationsWithPlaceholders() |
|
| 59 | - { |
|
| 60 | - $this->xTranslator->setLocale('en'); |
|
| 61 | - $this->assertEquals('Good morning Mr. Johnson', |
|
| 62 | - $this->xTranslator->trans('placeholders.morning', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 63 | - $this->assertEquals('Good afternoon Mrs. Smith', |
|
| 64 | - $this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mrs.', 'name' => 'Smith'])); |
|
| 65 | - } |
|
| 58 | +public function testEnTranslationsWithPlaceholders() |
|
| 59 | +{ |
|
| 60 | +$this->xTranslator->setLocale('en'); |
|
| 61 | +$this->assertEquals('Good morning Mr. Johnson', |
|
| 62 | +$this->xTranslator->trans('placeholders.morning', ['title' => 'Mr.', 'name' => 'Johnson'])); |
|
| 63 | +$this->assertEquals('Good afternoon Mrs. Smith', |
|
| 64 | +$this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mrs.', 'name' => 'Smith'])); |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - public function testFrTranslationsWithPlaceholders() |
|
| 68 | - { |
|
| 69 | - $this->xTranslator->setLocale('fr'); |
|
| 70 | - $this->assertEquals('Bonjour M. Pierre', |
|
| 71 | - $this->xTranslator->trans('placeholders.morning', ['title' => 'M.', 'name' => 'Pierre'])); |
|
| 72 | - $this->assertEquals('Bonsoir Mme Paule', |
|
| 73 | - $this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mme', 'name' => 'Paule'])); |
|
| 74 | - } |
|
| 67 | +public function testFrTranslationsWithPlaceholders() |
|
| 68 | +{ |
|
| 69 | +$this->xTranslator->setLocale('fr'); |
|
| 70 | +$this->assertEquals('Bonjour M. Pierre', |
|
| 71 | +$this->xTranslator->trans('placeholders.morning', ['title' => 'M.', 'name' => 'Pierre'])); |
|
| 72 | +$this->assertEquals('Bonsoir Mme Paule', |
|
| 73 | +$this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mme', 'name' => 'Paule'])); |
|
| 74 | +} |
|
| 75 | 75 | |
| 76 | - public function testExplicitEnTranslations() |
|
| 77 | - { |
|
| 78 | - $this->xTranslator->setLocale('fr'); |
|
| 79 | - $this->assertEquals('Good morning Mr. Johnson', |
|
| 80 | - $this->xTranslator->trans('placeholders.morning', ['title' => 'Mr.', 'name' => 'Johnson'], 'en')); |
|
| 81 | - $this->assertEquals('Good afternoon Mrs. Smith', |
|
| 82 | - $this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mrs.', 'name' => 'Smith'], 'en')); |
|
| 83 | - } |
|
| 76 | +public function testExplicitEnTranslations() |
|
| 77 | +{ |
|
| 78 | +$this->xTranslator->setLocale('fr'); |
|
| 79 | +$this->assertEquals('Good morning Mr. Johnson', |
|
| 80 | +$this->xTranslator->trans('placeholders.morning', ['title' => 'Mr.', 'name' => 'Johnson'], 'en')); |
|
| 81 | +$this->assertEquals('Good afternoon Mrs. Smith', |
|
| 82 | +$this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mrs.', 'name' => 'Smith'], 'en')); |
|
| 83 | +} |
|
| 84 | 84 | |
| 85 | - public function testExplicitFrTranslations() |
|
| 86 | - { |
|
| 87 | - $this->xTranslator->setLocale('en'); |
|
| 88 | - $this->assertEquals('Bonjour M. Pierre', |
|
| 89 | - $this->xTranslator->trans('placeholders.morning', ['title' => 'M.', 'name' => 'Pierre'], 'fr')); |
|
| 90 | - $this->assertEquals('Bonsoir Mme Paule', |
|
| 91 | - $this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mme', 'name' => 'Paule'], 'fr')); |
|
| 92 | - } |
|
| 85 | +public function testExplicitFrTranslations() |
|
| 86 | +{ |
|
| 87 | +$this->xTranslator->setLocale('en'); |
|
| 88 | +$this->assertEquals('Bonjour M. Pierre', |
|
| 89 | +$this->xTranslator->trans('placeholders.morning', ['title' => 'M.', 'name' => 'Pierre'], 'fr')); |
|
| 90 | +$this->assertEquals('Bonsoir Mme Paule', |
|
| 91 | +$this->xTranslator->trans('placeholders.afternoon', ['title' => 'Mme', 'name' => 'Paule'], 'fr')); |
|
| 92 | +} |
|
| 93 | 93 | } |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'salutations' => [ |
|
| 5 | - 'morning' => "Good morning", |
|
| 6 | - 'afternoon' => "Good afternoon", |
|
| 7 | - ], |
|
| 8 | - 'placeholders' => [ |
|
| 9 | - 'morning' => "Good morning :title :name", |
|
| 10 | - 'afternoon' => "Good afternoon :title :name", |
|
| 11 | - ], |
|
| 4 | +'salutations' => [ |
|
| 5 | +'morning' => "Good morning", |
|
| 6 | +'afternoon' => "Good afternoon", |
|
| 7 | +], |
|
| 8 | +'placeholders' => [ |
|
| 9 | +'morning' => "Good morning :title :name", |
|
| 10 | +'afternoon' => "Good afternoon :title :name", |
|
| 11 | +], |
|
| 12 | 12 | ]; |
@@ -1,12 +1,12 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'salutations' => [ |
|
| 5 | - 'morning' => "Bonjour", |
|
| 6 | - 'afternoon' => "Bonsoir", |
|
| 7 | - ], |
|
| 8 | - 'placeholders' => [ |
|
| 9 | - 'morning' => "Bonjour :title :name", |
|
| 10 | - 'afternoon' => "Bonsoir :title :name", |
|
| 11 | - ], |
|
| 4 | +'salutations' => [ |
|
| 5 | +'morning' => "Bonjour", |
|
| 6 | +'afternoon' => "Bonsoir", |
|
| 7 | +], |
|
| 8 | +'placeholders' => [ |
|
| 9 | +'morning' => "Bonjour :title :name", |
|
| 10 | +'afternoon' => "Bonsoir :title :name", |
|
| 11 | +], |
|
| 12 | 12 | ]; |
@@ -8,202 +8,202 @@ |
||
| 8 | 8 | |
| 9 | 9 | final class UriDetectorTest extends TestCase |
| 10 | 10 | { |
| 11 | - /** |
|
| 11 | +/** |
|
| 12 | 12 | * @var UriDetector |
| 13 | 13 | */ |
| 14 | - protected $xUriDetector; |
|
| 14 | +protected $xUriDetector; |
|
| 15 | 15 | |
| 16 | - protected function setUp(): void |
|
| 17 | - { |
|
| 18 | - $this->xUriDetector = new UriDetector(); |
|
| 19 | - } |
|
| 16 | +protected function setUp(): void |
|
| 17 | +{ |
|
| 18 | +$this->xUriDetector = new UriDetector(); |
|
| 19 | +} |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * @throws UriException |
| 23 | 23 | */ |
| 24 | - public function testUri() |
|
| 25 | - { |
|
| 26 | - $this->assertEquals('http://example.test/path', $this->xUriDetector->detect([ |
|
| 27 | - 'REQUEST_URI' => 'http://example.test/path' |
|
| 28 | - ])); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 24 | +public function testUri() |
|
| 25 | +{ |
|
| 26 | +$this->assertEquals('http://example.test/path', $this->xUriDetector->detect([ |
|
| 27 | +'REQUEST_URI' => 'http://example.test/path' |
|
| 28 | +])); |
|
| 29 | +} |
|
| 30 | + |
|
| 31 | +/** |
|
| 32 | 32 | * @throws UriException |
| 33 | 33 | */ |
| 34 | - public function testUriWithParam() |
|
| 35 | - { |
|
| 36 | - $this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 37 | - $this->xUriDetector->detect([ |
|
| 38 | - 'REQUEST_URI' => 'http://example.test/path?param1=value1¶m2="value2"', |
|
| 39 | - ]) |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 34 | +public function testUriWithParam() |
|
| 35 | +{ |
|
| 36 | +$this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 37 | +$this->xUriDetector->detect([ |
|
| 38 | + 'REQUEST_URI' => 'http://example.test/path?param1=value1¶m2="value2"', |
|
| 39 | +]) |
|
| 40 | +); |
|
| 41 | +} |
|
| 42 | + |
|
| 43 | +/** |
|
| 44 | 44 | * @throws UriException |
| 45 | 45 | */ |
| 46 | - public function testUriWithUser() |
|
| 47 | - { |
|
| 48 | - $this->assertEquals('http://[email protected]/path', $this->xUriDetector->detect([ |
|
| 49 | - 'REQUEST_URI' => 'http://[email protected]/path' |
|
| 50 | - ])); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 46 | +public function testUriWithUser() |
|
| 47 | +{ |
|
| 48 | +$this->assertEquals('http://[email protected]/path', $this->xUriDetector->detect([ |
|
| 49 | +'REQUEST_URI' => 'http://[email protected]/path' |
|
| 50 | +])); |
|
| 51 | +} |
|
| 52 | + |
|
| 53 | +/** |
|
| 54 | 54 | * @throws UriException |
| 55 | 55 | */ |
| 56 | - public function testUriWithUserAndPass() |
|
| 57 | - { |
|
| 58 | - $this->assertEquals('http://user:[email protected]/path', $this->xUriDetector->detect([ |
|
| 59 | - 'REQUEST_URI' => 'http://user:[email protected]/path' |
|
| 60 | - ])); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 56 | +public function testUriWithUserAndPass() |
|
| 57 | +{ |
|
| 58 | +$this->assertEquals('http://user:[email protected]/path', $this->xUriDetector->detect([ |
|
| 59 | +'REQUEST_URI' => 'http://user:[email protected]/path' |
|
| 60 | +])); |
|
| 61 | +} |
|
| 62 | + |
|
| 63 | +/** |
|
| 64 | 64 | * @throws UriException |
| 65 | 65 | */ |
| 66 | - public function testUriWithEmptyBasename() |
|
| 67 | - { |
|
| 68 | - $this->assertEquals('http://example.test/', $this->xUriDetector->detect([ |
|
| 69 | - 'REQUEST_URI' => 'http://example.test//' |
|
| 70 | - ])); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 66 | +public function testUriWithEmptyBasename() |
|
| 67 | +{ |
|
| 68 | +$this->assertEquals('http://example.test/', $this->xUriDetector->detect([ |
|
| 69 | +'REQUEST_URI' => 'http://example.test//' |
|
| 70 | +])); |
|
| 71 | +} |
|
| 72 | + |
|
| 73 | +/** |
|
| 74 | 74 | * @throws UriException |
| 75 | 75 | */ |
| 76 | - public function testUriWithParts() |
|
| 77 | - { |
|
| 78 | - $this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 79 | - $this->xUriDetector->detect([ |
|
| 80 | - 'HTTP_SCHEME' => 'http', |
|
| 81 | - 'HTTP_HOST' => 'example.test', |
|
| 82 | - 'PATH_INFO' => '/path', |
|
| 83 | - 'QUERY_STRING' => 'param1=value1¶m2="value2"', |
|
| 84 | - ]) |
|
| 85 | - ); |
|
| 86 | - $this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 87 | - $this->xUriDetector->detect([ |
|
| 88 | - 'HTTPS' => 'off', |
|
| 89 | - 'HTTP_HOST' => 'example.test', |
|
| 90 | - 'PATH_INFO' => '/path', |
|
| 91 | - 'QUERY_STRING' => 'param1=value1¶m2="value2"', |
|
| 92 | - ]) |
|
| 93 | - ); |
|
| 94 | - $this->assertEquals('https://example.test:8080/path', |
|
| 95 | - $this->xUriDetector->detect([ |
|
| 96 | - 'HTTPS' => 'on', |
|
| 97 | - 'SERVER_NAME' => 'example.test:8080', |
|
| 98 | - 'PATH_INFO' => '/path', |
|
| 99 | - ]) |
|
| 100 | - ); |
|
| 101 | - $this->assertEquals('https://example.test:8080/path', |
|
| 102 | - $this->xUriDetector->detect([ |
|
| 103 | - 'HTTPS' => 'on', |
|
| 104 | - 'SERVER_NAME' => 'example.test', |
|
| 105 | - 'SERVER_PORT' => '8080', |
|
| 106 | - 'PATH_INFO' => '/path', |
|
| 107 | - ]) |
|
| 108 | - ); |
|
| 109 | - $this->assertEquals('https://example.test:8080/path', |
|
| 110 | - $this->xUriDetector->detect([ |
|
| 111 | - 'HTTP_X_FORWARDED_SSL' => 'on', |
|
| 112 | - 'SERVER_NAME' => 'example.test:8080', |
|
| 113 | - 'PATH_INFO' => '/path', |
|
| 114 | - ]) |
|
| 115 | - ); |
|
| 116 | - $this->assertEquals('https://example.test:8080/path', |
|
| 117 | - $this->xUriDetector->detect([ |
|
| 118 | - 'HTTP_X_FORWARDED_PROTO' => 'https', |
|
| 119 | - 'SERVER_NAME' => 'example.test:8080', |
|
| 120 | - 'PATH_INFO' => '/path', |
|
| 121 | - ]) |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 76 | +public function testUriWithParts() |
|
| 77 | +{ |
|
| 78 | +$this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 79 | +$this->xUriDetector->detect([ |
|
| 80 | + 'HTTP_SCHEME' => 'http', |
|
| 81 | + 'HTTP_HOST' => 'example.test', |
|
| 82 | + 'PATH_INFO' => '/path', |
|
| 83 | + 'QUERY_STRING' => 'param1=value1¶m2="value2"', |
|
| 84 | +]) |
|
| 85 | +); |
|
| 86 | +$this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 87 | +$this->xUriDetector->detect([ |
|
| 88 | + 'HTTPS' => 'off', |
|
| 89 | + 'HTTP_HOST' => 'example.test', |
|
| 90 | + 'PATH_INFO' => '/path', |
|
| 91 | + 'QUERY_STRING' => 'param1=value1¶m2="value2"', |
|
| 92 | +]) |
|
| 93 | +); |
|
| 94 | +$this->assertEquals('https://example.test:8080/path', |
|
| 95 | +$this->xUriDetector->detect([ |
|
| 96 | + 'HTTPS' => 'on', |
|
| 97 | + 'SERVER_NAME' => 'example.test:8080', |
|
| 98 | + 'PATH_INFO' => '/path', |
|
| 99 | +]) |
|
| 100 | +); |
|
| 101 | +$this->assertEquals('https://example.test:8080/path', |
|
| 102 | +$this->xUriDetector->detect([ |
|
| 103 | + 'HTTPS' => 'on', |
|
| 104 | + 'SERVER_NAME' => 'example.test', |
|
| 105 | + 'SERVER_PORT' => '8080', |
|
| 106 | + 'PATH_INFO' => '/path', |
|
| 107 | +]) |
|
| 108 | +); |
|
| 109 | +$this->assertEquals('https://example.test:8080/path', |
|
| 110 | +$this->xUriDetector->detect([ |
|
| 111 | + 'HTTP_X_FORWARDED_SSL' => 'on', |
|
| 112 | + 'SERVER_NAME' => 'example.test:8080', |
|
| 113 | + 'PATH_INFO' => '/path', |
|
| 114 | +]) |
|
| 115 | +); |
|
| 116 | +$this->assertEquals('https://example.test:8080/path', |
|
| 117 | +$this->xUriDetector->detect([ |
|
| 118 | + 'HTTP_X_FORWARDED_PROTO' => 'https', |
|
| 119 | + 'SERVER_NAME' => 'example.test:8080', |
|
| 120 | + 'PATH_INFO' => '/path', |
|
| 121 | +]) |
|
| 122 | +); |
|
| 123 | +} |
|
| 124 | + |
|
| 125 | +/** |
|
| 126 | 126 | * @throws UriException |
| 127 | 127 | */ |
| 128 | - public function testRemoveJaxonParam() |
|
| 129 | - { |
|
| 130 | - $this->assertEquals('http://example.test/path', $this->xUriDetector->detect([ |
|
| 131 | - 'REQUEST_URI' => 'http://example.test/path?jxnGenerate=true' |
|
| 132 | - ])); |
|
| 133 | - $this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 134 | - $this->xUriDetector->detect([ |
|
| 135 | - 'REQUEST_URI' => 'http://example.test/path?param1=value1&jxnGenerate=true¶m2="value2"', |
|
| 136 | - ]) |
|
| 137 | - ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function testErrorMissingHost() |
|
| 141 | - { |
|
| 142 | - $this->expectException(UriException::class); |
|
| 143 | - $this->xUriDetector->detect([ |
|
| 144 | - 'HTTPS' => 'on', |
|
| 145 | - 'PATH_INFO' => '/path', |
|
| 146 | - 'QUERY_STRING' => 'param1=value1¶m2="value2"', |
|
| 147 | - ]); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function testRedirectSimpleUrl() |
|
| 151 | - { |
|
| 152 | - $this->assertEquals('http://example.test/path', |
|
| 153 | - $this->xUriDetector->redirect('http://example.test/path', [])); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function testRedirectUrlWithAnchor() |
|
| 157 | - { |
|
| 158 | - $this->assertEquals('http://example.test/path?param=value#anchor', |
|
| 159 | - $this->xUriDetector->redirect('http://example.test/path?param=value#anchor', [])); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function testRedirectUrlWithParam() |
|
| 163 | - { |
|
| 164 | - $this->assertEquals('http://example.test/path?param=value', |
|
| 165 | - $this->xUriDetector->redirect('http://example.test/path?param=value', [])); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - public function testRedirectUrlWithParams() |
|
| 169 | - { |
|
| 170 | - $this->assertEquals('http://example.test/path?param1=value1¶m2=value2', |
|
| 171 | - $this->xUriDetector->redirect('http://example.test/path?param1=value1¶m2=value2', [])); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - public function testRedirectUrlWithSpecialChars() |
|
| 175 | - { |
|
| 176 | - $this->assertEquals('http://example.test/path?param1=%22value1%22¶m2=%25value2%25#anchor', |
|
| 177 | - $this->xUriDetector->redirect('http://example.test/path?param1="value1"¶m2=%value2%#anchor', [])); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - public function testRedirectSpecialUrl() |
|
| 181 | - { |
|
| 182 | - $this->assertEquals('http://example.test/?query1234', |
|
| 183 | - $this->xUriDetector->redirect('http://example.test/?query1234', [])); |
|
| 184 | - |
|
| 185 | - $this->assertEquals('http://example.test/?query1234=', |
|
| 186 | - $this->xUriDetector->redirect('http://example.test/?query1234=', [])); |
|
| 187 | - |
|
| 188 | - $this->assertEquals('http://example.test/?param=value&query1234=0', |
|
| 189 | - $this->xUriDetector->redirect('http://example.test/?param=value&query1234=0', [])); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function testRedirectEncodedUrl() |
|
| 193 | - { |
|
| 194 | - $this->assertEquals('http://example.test/path?param1=%22value1%22¶m2=%25value2%25', |
|
| 195 | - $this->xUriDetector->redirect('http://example.test/path?param1=%22value1%22¶m2=%25value2%25', [])); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - public function testRedirectUnexpectedUrl() |
|
| 199 | - { |
|
| 200 | - $this->assertEquals('http://example.test/', |
|
| 201 | - $this->xUriDetector->redirect('http://example.test/? ', [])); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - public function testRedirectQueryString() |
|
| 205 | - { |
|
| 206 | - $this->assertEquals('http://example.test/?param1=value1', |
|
| 207 | - $this->xUriDetector->redirect('http://example.test/? ', ['QUERY_STRING' => 'param1=value1'])); |
|
| 208 | - } |
|
| 128 | +public function testRemoveJaxonParam() |
|
| 129 | +{ |
|
| 130 | +$this->assertEquals('http://example.test/path', $this->xUriDetector->detect([ |
|
| 131 | +'REQUEST_URI' => 'http://example.test/path?jxnGenerate=true' |
|
| 132 | +])); |
|
| 133 | +$this->assertEquals('http://example.test/path?param1=value1¶m2=%22value2%22', |
|
| 134 | +$this->xUriDetector->detect([ |
|
| 135 | + 'REQUEST_URI' => 'http://example.test/path?param1=value1&jxnGenerate=true¶m2="value2"', |
|
| 136 | +]) |
|
| 137 | +); |
|
| 138 | +} |
|
| 139 | + |
|
| 140 | +public function testErrorMissingHost() |
|
| 141 | +{ |
|
| 142 | +$this->expectException(UriException::class); |
|
| 143 | +$this->xUriDetector->detect([ |
|
| 144 | +'HTTPS' => 'on', |
|
| 145 | +'PATH_INFO' => '/path', |
|
| 146 | +'QUERY_STRING' => 'param1=value1¶m2="value2"', |
|
| 147 | +]); |
|
| 148 | +} |
|
| 149 | + |
|
| 150 | +public function testRedirectSimpleUrl() |
|
| 151 | +{ |
|
| 152 | +$this->assertEquals('http://example.test/path', |
|
| 153 | +$this->xUriDetector->redirect('http://example.test/path', [])); |
|
| 154 | +} |
|
| 155 | + |
|
| 156 | +public function testRedirectUrlWithAnchor() |
|
| 157 | +{ |
|
| 158 | +$this->assertEquals('http://example.test/path?param=value#anchor', |
|
| 159 | +$this->xUriDetector->redirect('http://example.test/path?param=value#anchor', [])); |
|
| 160 | +} |
|
| 161 | + |
|
| 162 | +public function testRedirectUrlWithParam() |
|
| 163 | +{ |
|
| 164 | +$this->assertEquals('http://example.test/path?param=value', |
|
| 165 | +$this->xUriDetector->redirect('http://example.test/path?param=value', [])); |
|
| 166 | +} |
|
| 167 | + |
|
| 168 | +public function testRedirectUrlWithParams() |
|
| 169 | +{ |
|
| 170 | +$this->assertEquals('http://example.test/path?param1=value1¶m2=value2', |
|
| 171 | +$this->xUriDetector->redirect('http://example.test/path?param1=value1¶m2=value2', [])); |
|
| 172 | +} |
|
| 173 | + |
|
| 174 | +public function testRedirectUrlWithSpecialChars() |
|
| 175 | +{ |
|
| 176 | +$this->assertEquals('http://example.test/path?param1=%22value1%22¶m2=%25value2%25#anchor', |
|
| 177 | +$this->xUriDetector->redirect('http://example.test/path?param1="value1"¶m2=%value2%#anchor', [])); |
|
| 178 | +} |
|
| 179 | + |
|
| 180 | +public function testRedirectSpecialUrl() |
|
| 181 | +{ |
|
| 182 | +$this->assertEquals('http://example.test/?query1234', |
|
| 183 | +$this->xUriDetector->redirect('http://example.test/?query1234', [])); |
|
| 184 | + |
|
| 185 | +$this->assertEquals('http://example.test/?query1234=', |
|
| 186 | +$this->xUriDetector->redirect('http://example.test/?query1234=', [])); |
|
| 187 | + |
|
| 188 | +$this->assertEquals('http://example.test/?param=value&query1234=0', |
|
| 189 | +$this->xUriDetector->redirect('http://example.test/?param=value&query1234=0', [])); |
|
| 190 | +} |
|
| 191 | + |
|
| 192 | +public function testRedirectEncodedUrl() |
|
| 193 | +{ |
|
| 194 | +$this->assertEquals('http://example.test/path?param1=%22value1%22¶m2=%25value2%25', |
|
| 195 | +$this->xUriDetector->redirect('http://example.test/path?param1=%22value1%22¶m2=%25value2%25', [])); |
|
| 196 | +} |
|
| 197 | + |
|
| 198 | +public function testRedirectUnexpectedUrl() |
|
| 199 | +{ |
|
| 200 | +$this->assertEquals('http://example.test/', |
|
| 201 | +$this->xUriDetector->redirect('http://example.test/? ', [])); |
|
| 202 | +} |
|
| 203 | + |
|
| 204 | +public function testRedirectQueryString() |
|
| 205 | +{ |
|
| 206 | +$this->assertEquals('http://example.test/?param1=value1', |
|
| 207 | +$this->xUriDetector->redirect('http://example.test/? ', ['QUERY_STRING' => 'param1=value1'])); |
|
| 208 | +} |
|
| 209 | 209 | } |
@@ -29,40 +29,40 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | class UriDetector |
| 31 | 31 | { |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * The URL components |
| 34 | 34 | * |
| 35 | 35 | * @var array |
| 36 | 36 | */ |
| 37 | - protected $aUrl; |
|
| 37 | +protected $aUrl; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @param array $aServerParams The server environment variables |
| 41 | 41 | * |
| 42 | 42 | * @return void |
| 43 | 43 | */ |
| 44 | - private function setScheme(array $aServerParams): void |
|
| 45 | - { |
|
| 46 | - if(isset($this->aUrl['scheme'])) |
|
| 47 | - { |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - if(isset($aServerParams['HTTP_SCHEME'])) |
|
| 51 | - { |
|
| 52 | - $this->aUrl['scheme'] = $aServerParams['HTTP_SCHEME']; |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - if((isset($aServerParams['HTTPS']) && strtolower($aServerParams['HTTPS']) === 'on') || |
|
| 56 | - (isset($aServerParams['HTTP_X_FORWARDED_SSL']) && $aServerParams['HTTP_X_FORWARDED_SSL'] === 'on') || |
|
| 57 | - (isset($aServerParams['HTTP_X_FORWARDED_PROTO']) && $aServerParams['HTTP_X_FORWARDED_PROTO'] === 'https')) |
|
| 58 | - { |
|
| 59 | - $this->aUrl['scheme'] = 'https'; |
|
| 60 | - return; |
|
| 61 | - } |
|
| 62 | - $this->aUrl['scheme'] = 'http'; |
|
| 63 | - } |
|
| 44 | +private function setScheme(array $aServerParams): void |
|
| 45 | +{ |
|
| 46 | +if(isset($this->aUrl['scheme'])) |
|
| 47 | +{ |
|
| 48 | +return; |
|
| 49 | +} |
|
| 50 | +if(isset($aServerParams['HTTP_SCHEME'])) |
|
| 51 | +{ |
|
| 52 | +$this->aUrl['scheme'] = $aServerParams['HTTP_SCHEME']; |
|
| 53 | +return; |
|
| 54 | +} |
|
| 55 | +if((isset($aServerParams['HTTPS']) && strtolower($aServerParams['HTTPS']) === 'on') || |
|
| 56 | +(isset($aServerParams['HTTP_X_FORWARDED_SSL']) && $aServerParams['HTTP_X_FORWARDED_SSL'] === 'on') || |
|
| 57 | +(isset($aServerParams['HTTP_X_FORWARDED_PROTO']) && $aServerParams['HTTP_X_FORWARDED_PROTO'] === 'https')) |
|
| 58 | +{ |
|
| 59 | +$this->aUrl['scheme'] = 'https'; |
|
| 60 | +return; |
|
| 61 | +} |
|
| 62 | +$this->aUrl['scheme'] = 'http'; |
|
| 63 | +} |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * Get the URL from the $aServerParams var |
| 67 | 67 | * |
| 68 | 68 | * @param array $aServerParams The server environment variables |
@@ -70,140 +70,140 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return void |
| 72 | 72 | */ |
| 73 | - private function setHostFromServer(array $aServerParams, string $sKey): void |
|
| 74 | - { |
|
| 75 | - if(isset($this->aUrl['host']) || empty($aServerParams[$sKey])) |
|
| 76 | - { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - if(strpos($aServerParams[$sKey], ':') === false) |
|
| 80 | - { |
|
| 81 | - $this->aUrl['host'] = $aServerParams[$sKey]; |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - list($this->aUrl['host'], $this->aUrl['port']) = explode(':', $aServerParams[$sKey]); |
|
| 85 | - } |
|
| 73 | +private function setHostFromServer(array $aServerParams, string $sKey): void |
|
| 74 | +{ |
|
| 75 | +if(isset($this->aUrl['host']) || empty($aServerParams[$sKey])) |
|
| 76 | +{ |
|
| 77 | +return; |
|
| 78 | +} |
|
| 79 | +if(strpos($aServerParams[$sKey], ':') === false) |
|
| 80 | +{ |
|
| 81 | +$this->aUrl['host'] = $aServerParams[$sKey]; |
|
| 82 | +return; |
|
| 83 | +} |
|
| 84 | +list($this->aUrl['host'], $this->aUrl['port']) = explode(':', $aServerParams[$sKey]); |
|
| 85 | +} |
|
| 86 | 86 | |
| 87 | - /** |
|
| 87 | +/** |
|
| 88 | 88 | * @param array $aServerParams The server environment variables |
| 89 | 89 | * |
| 90 | 90 | * @return void |
| 91 | 91 | * @throws UriException |
| 92 | 92 | */ |
| 93 | - private function setHost(array $aServerParams): void |
|
| 94 | - { |
|
| 95 | - $this->setHostFromServer($aServerParams, 'HTTP_X_FORWARDED_HOST'); |
|
| 96 | - $this->setHostFromServer($aServerParams, 'HTTP_HOST'); |
|
| 97 | - $this->setHostFromServer($aServerParams, 'SERVER_NAME'); |
|
| 98 | - if(empty($this->aUrl['host'])) |
|
| 99 | - { |
|
| 100 | - throw new UriException(); |
|
| 101 | - } |
|
| 102 | - if(empty($this->aUrl['port']) && isset($aServerParams['SERVER_PORT'])) |
|
| 103 | - { |
|
| 104 | - $this->aUrl['port'] = $aServerParams['SERVER_PORT']; |
|
| 105 | - } |
|
| 106 | - } |
|
| 93 | +private function setHost(array $aServerParams): void |
|
| 94 | +{ |
|
| 95 | +$this->setHostFromServer($aServerParams, 'HTTP_X_FORWARDED_HOST'); |
|
| 96 | +$this->setHostFromServer($aServerParams, 'HTTP_HOST'); |
|
| 97 | +$this->setHostFromServer($aServerParams, 'SERVER_NAME'); |
|
| 98 | +if(empty($this->aUrl['host'])) |
|
| 99 | +{ |
|
| 100 | +throw new UriException(); |
|
| 101 | +} |
|
| 102 | +if(empty($this->aUrl['port']) && isset($aServerParams['SERVER_PORT'])) |
|
| 103 | +{ |
|
| 104 | +$this->aUrl['port'] = $aServerParams['SERVER_PORT']; |
|
| 105 | +} |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * @param array $aServerParams The server environment variables |
| 110 | 110 | * |
| 111 | 111 | * @return void |
| 112 | 112 | */ |
| 113 | - private function setPath(array $aServerParams): void |
|
| 114 | - { |
|
| 115 | - if(isset($this->aUrl['path']) && strlen(basename($this->aUrl['path'])) === 0) |
|
| 116 | - { |
|
| 117 | - unset($this->aUrl['path']); |
|
| 118 | - } |
|
| 119 | - if(isset($this->aUrl['path'])) |
|
| 120 | - { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - $aPath = parse_url($aServerParams['PATH_INFO'] ?? ($aServerParams['PHP_SELF'] ?? '')); |
|
| 124 | - if(isset($aPath['path'])) |
|
| 125 | - { |
|
| 126 | - $this->aUrl['path'] = $aPath['path']; |
|
| 127 | - } |
|
| 128 | - } |
|
| 113 | +private function setPath(array $aServerParams): void |
|
| 114 | +{ |
|
| 115 | +if(isset($this->aUrl['path']) && strlen(basename($this->aUrl['path'])) === 0) |
|
| 116 | +{ |
|
| 117 | +unset($this->aUrl['path']); |
|
| 118 | +} |
|
| 119 | +if(isset($this->aUrl['path'])) |
|
| 120 | +{ |
|
| 121 | +return; |
|
| 122 | +} |
|
| 123 | +$aPath = parse_url($aServerParams['PATH_INFO'] ?? ($aServerParams['PHP_SELF'] ?? '')); |
|
| 124 | +if(isset($aPath['path'])) |
|
| 125 | +{ |
|
| 126 | +$this->aUrl['path'] = $aPath['path']; |
|
| 127 | +} |
|
| 128 | +} |
|
| 129 | 129 | |
| 130 | - /** |
|
| 130 | +/** |
|
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | - private function getPath(): string |
|
| 134 | - { |
|
| 135 | - return '/' . ltrim($this->aUrl['path'], '/'); |
|
| 136 | - } |
|
| 133 | +private function getPath(): string |
|
| 134 | +{ |
|
| 135 | +return '/' . ltrim($this->aUrl['path'], '/'); |
|
| 136 | +} |
|
| 137 | 137 | |
| 138 | - /** |
|
| 138 | +/** |
|
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - private function getUser(): string |
|
| 142 | - { |
|
| 143 | - if(empty($this->aUrl['user'])) |
|
| 144 | - { |
|
| 145 | - return ''; |
|
| 146 | - } |
|
| 147 | - $sUrl = $this->aUrl['user']; |
|
| 148 | - if(isset($this->aUrl['pass'])) |
|
| 149 | - { |
|
| 150 | - $sUrl .= ':' . $this->aUrl['pass']; |
|
| 151 | - } |
|
| 152 | - return $sUrl . '@'; |
|
| 153 | - } |
|
| 141 | +private function getUser(): string |
|
| 142 | +{ |
|
| 143 | +if(empty($this->aUrl['user'])) |
|
| 144 | +{ |
|
| 145 | +return ''; |
|
| 146 | +} |
|
| 147 | +$sUrl = $this->aUrl['user']; |
|
| 148 | +if(isset($this->aUrl['pass'])) |
|
| 149 | +{ |
|
| 150 | +$sUrl .= ':' . $this->aUrl['pass']; |
|
| 151 | +} |
|
| 152 | +return $sUrl . '@'; |
|
| 153 | +} |
|
| 154 | 154 | |
| 155 | - /** |
|
| 155 | +/** |
|
| 156 | 156 | * @return string |
| 157 | 157 | */ |
| 158 | - private function getPort(): string |
|
| 159 | - { |
|
| 160 | - if(isset($this->aUrl['port']) && |
|
| 161 | - (($this->aUrl['scheme'] === 'http' && $this->aUrl['port'] != 80) || |
|
| 162 | - ($this->aUrl['scheme'] === 'https' && $this->aUrl['port'] != 443))) |
|
| 163 | - { |
|
| 164 | - return ':' . $this->aUrl['port']; |
|
| 165 | - } |
|
| 166 | - return ''; |
|
| 167 | - } |
|
| 158 | +private function getPort(): string |
|
| 159 | +{ |
|
| 160 | +if(isset($this->aUrl['port']) && |
|
| 161 | +(($this->aUrl['scheme'] === 'http' && $this->aUrl['port'] != 80) || |
|
| 162 | + ($this->aUrl['scheme'] === 'https' && $this->aUrl['port'] != 443))) |
|
| 163 | +{ |
|
| 164 | +return ':' . $this->aUrl['port']; |
|
| 165 | +} |
|
| 166 | +return ''; |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * @param array $aServerParams The server environment variables |
| 171 | 171 | * |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - private function setQuery(array $aServerParams): void |
|
| 175 | - { |
|
| 176 | - if(empty($this->aUrl['query'])) |
|
| 177 | - { |
|
| 178 | - $this->aUrl['query'] = $aServerParams['QUERY_STRING'] ?? ''; |
|
| 179 | - } |
|
| 180 | - } |
|
| 174 | +private function setQuery(array $aServerParams): void |
|
| 175 | +{ |
|
| 176 | +if(empty($this->aUrl['query'])) |
|
| 177 | +{ |
|
| 178 | +$this->aUrl['query'] = $aServerParams['QUERY_STRING'] ?? ''; |
|
| 179 | +} |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | - private function getQuery(): string |
|
| 186 | - { |
|
| 187 | - if(empty($this->aUrl['query'])) |
|
| 188 | - { |
|
| 189 | - return ''; |
|
| 190 | - } |
|
| 191 | - $aQueries = explode('&', $this->aUrl['query']); |
|
| 192 | - foreach($aQueries as $sKey => $sQuery) |
|
| 193 | - { |
|
| 194 | - if(substr($sQuery, 0, 11) === 'jxnGenerate') |
|
| 195 | - { |
|
| 196 | - unset($aQueries[$sKey]); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - if(empty($aQueries)) |
|
| 200 | - { |
|
| 201 | - return ''; |
|
| 202 | - } |
|
| 203 | - return '?' . implode("&", $aQueries); |
|
| 204 | - } |
|
| 185 | +private function getQuery(): string |
|
| 186 | +{ |
|
| 187 | +if(empty($this->aUrl['query'])) |
|
| 188 | +{ |
|
| 189 | +return ''; |
|
| 190 | +} |
|
| 191 | +$aQueries = explode('&', $this->aUrl['query']); |
|
| 192 | +foreach($aQueries as $sKey => $sQuery) |
|
| 193 | +{ |
|
| 194 | +if(substr($sQuery, 0, 11) === 'jxnGenerate') |
|
| 195 | +{ |
|
| 196 | + unset($aQueries[$sKey]); |
|
| 197 | +} |
|
| 198 | +} |
|
| 199 | +if(empty($aQueries)) |
|
| 200 | +{ |
|
| 201 | +return ''; |
|
| 202 | +} |
|
| 203 | +return '?' . implode("&", $aQueries); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Detect the URI of the current request |
| 208 | 208 | * |
| 209 | 209 | * @param array $aServerParams The server environment variables |
@@ -211,70 +211,70 @@ discard block |
||
| 211 | 211 | * @return string |
| 212 | 212 | * @throws UriException |
| 213 | 213 | */ |
| 214 | - public function detect(array $aServerParams): string |
|
| 215 | - { |
|
| 216 | - $this->aUrl = []; |
|
| 217 | - // Try to get the request URL |
|
| 218 | - if(isset($aServerParams['REQUEST_URI'])) |
|
| 219 | - { |
|
| 220 | - $this->aUrl = parse_url($aServerParams['REQUEST_URI']); |
|
| 221 | - } |
|
| 214 | +public function detect(array $aServerParams): string |
|
| 215 | +{ |
|
| 216 | +$this->aUrl = []; |
|
| 217 | +// Try to get the request URL |
|
| 218 | +if(isset($aServerParams['REQUEST_URI'])) |
|
| 219 | +{ |
|
| 220 | +$this->aUrl = parse_url($aServerParams['REQUEST_URI']); |
|
| 221 | +} |
|
| 222 | 222 | |
| 223 | - // Fill in the empty values |
|
| 224 | - $this->setScheme($aServerParams); |
|
| 225 | - $this->setHost($aServerParams); |
|
| 226 | - $this->setPath($aServerParams); |
|
| 227 | - $this->setQuery($aServerParams); |
|
| 223 | +// Fill in the empty values |
|
| 224 | +$this->setScheme($aServerParams); |
|
| 225 | +$this->setHost($aServerParams); |
|
| 226 | +$this->setPath($aServerParams); |
|
| 227 | +$this->setQuery($aServerParams); |
|
| 228 | 228 | |
| 229 | - // Build the URL: Start with scheme, user and pass |
|
| 230 | - return $this->aUrl['scheme'] . '://' . $this->getUser() . $this->aUrl['host'] . |
|
| 231 | - $this->getPort() . str_replace(['"', "'", '<', '>'], |
|
| 232 | - ['%22', '%27', '%3C', '%3E'], $this->getPath() . $this->getQuery()); |
|
| 233 | - } |
|
| 229 | +// Build the URL: Start with scheme, user and pass |
|
| 230 | +return $this->aUrl['scheme'] . '://' . $this->getUser() . $this->aUrl['host'] . |
|
| 231 | +$this->getPort() . str_replace(['"', "'", '<', '>'], |
|
| 232 | + ['%22', '%27', '%3C', '%3E'], $this->getPath() . $this->getQuery()); |
|
| 233 | +} |
|
| 234 | 234 | |
| 235 | - /** |
|
| 235 | +/** |
|
| 236 | 236 | * @param string $sQueryPart |
| 237 | 237 | * @param string $sKey |
| 238 | 238 | * @param string $sValue |
| 239 | 239 | * |
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | - private function makeQueryPart(string $sQueryPart, string $sKey, string $sValue): string |
|
| 243 | - { |
|
| 244 | - return $sValue === '' && strpos($sQueryPart, "$sKey=") === false ? |
|
| 245 | - rawurlencode($sKey) : rawurlencode($sKey) . '=' . rawurlencode($sValue); |
|
| 246 | - } |
|
| 242 | +private function makeQueryPart(string $sQueryPart, string $sKey, string $sValue): string |
|
| 243 | +{ |
|
| 244 | +return $sValue === '' && strpos($sQueryPart, "$sKey=") === false ? |
|
| 245 | +rawurlencode($sKey) : rawurlencode($sKey) . '=' . rawurlencode($sValue); |
|
| 246 | +} |
|
| 247 | 247 | |
| 248 | - /** |
|
| 248 | +/** |
|
| 249 | 249 | * @param string $sQueryPart |
| 250 | 250 | * @param array $aServerParams |
| 251 | 251 | * |
| 252 | 252 | * @return string |
| 253 | 253 | */ |
| 254 | - private function parseQueryPart(string $sQueryPart, array $aServerParams): string |
|
| 255 | - { |
|
| 256 | - $aQueryParts = []; |
|
| 257 | - parse_str($sQueryPart, $aQueryParts); |
|
| 258 | - if(empty($aQueryParts)) |
|
| 259 | - { |
|
| 260 | - // Couldn't break up the query, but there's one there. |
|
| 261 | - // Possibly "http://url/page.html?query1234" type of query? |
|
| 262 | - // Try to get data from the server environment var. |
|
| 263 | - parse_str($aServerParams['QUERY_STRING'] ?? '', $aQueryParts); |
|
| 264 | - } |
|
| 265 | - if(($aQueryParts)) |
|
| 266 | - { |
|
| 267 | - $aNewQueryParts = []; |
|
| 268 | - foreach($aQueryParts as $sKey => $sValue) |
|
| 269 | - { |
|
| 270 | - $aNewQueryParts[] = $this->makeQueryPart($sQueryPart, $sKey, $sValue); |
|
| 271 | - } |
|
| 272 | - return '?' . implode('&', $aNewQueryParts); |
|
| 273 | - } |
|
| 274 | - return trim($sQueryPart); |
|
| 275 | - } |
|
| 254 | +private function parseQueryPart(string $sQueryPart, array $aServerParams): string |
|
| 255 | +{ |
|
| 256 | +$aQueryParts = []; |
|
| 257 | +parse_str($sQueryPart, $aQueryParts); |
|
| 258 | +if(empty($aQueryParts)) |
|
| 259 | +{ |
|
| 260 | +// Couldn't break up the query, but there's one there. |
|
| 261 | +// Possibly "http://url/page.html?query1234" type of query? |
|
| 262 | +// Try to get data from the server environment var. |
|
| 263 | +parse_str($aServerParams['QUERY_STRING'] ?? '', $aQueryParts); |
|
| 264 | +} |
|
| 265 | +if(($aQueryParts)) |
|
| 266 | +{ |
|
| 267 | +$aNewQueryParts = []; |
|
| 268 | +foreach($aQueryParts as $sKey => $sValue) |
|
| 269 | +{ |
|
| 270 | + $aNewQueryParts[] = $this->makeQueryPart($sQueryPart, $sKey, $sValue); |
|
| 271 | +} |
|
| 272 | +return '?' . implode('&', $aNewQueryParts); |
|
| 273 | +} |
|
| 274 | +return trim($sQueryPart); |
|
| 275 | +} |
|
| 276 | 276 | |
| 277 | - /** |
|
| 277 | +/** |
|
| 278 | 278 | * Make the specified URL suitable for redirect |
| 279 | 279 | * |
| 280 | 280 | * @param string $sURL The relative or fully qualified URL |
@@ -282,23 +282,23 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | - public function redirect(string $sURL, array $aServerParams): string |
|
| 286 | - { |
|
| 287 | - // We need to parse the query part so that the values are rawurlencode()'ed. |
|
| 288 | - // Can't just use parse_url() cos we could be dealing with a relative URL which parse_url() can't deal with. |
|
| 289 | - $sURL = trim($sURL); |
|
| 290 | - $nQueryStart = strpos($sURL, '?', strrpos($sURL, '/')); |
|
| 291 | - if($nQueryStart === false) |
|
| 292 | - { |
|
| 293 | - return $sURL; |
|
| 294 | - } |
|
| 295 | - $nQueryStart++; |
|
| 296 | - $nQueryEnd = strpos($sURL, '#', $nQueryStart); |
|
| 297 | - if($nQueryEnd === false) |
|
| 298 | - { |
|
| 299 | - $nQueryEnd = strlen($sURL); |
|
| 300 | - } |
|
| 301 | - $sQueryPart = substr($sURL, $nQueryStart, $nQueryEnd - $nQueryStart); |
|
| 302 | - return str_replace('?' . $sQueryPart, $this->parseQueryPart($sQueryPart, $aServerParams), $sURL); |
|
| 303 | - } |
|
| 285 | +public function redirect(string $sURL, array $aServerParams): string |
|
| 286 | +{ |
|
| 287 | +// We need to parse the query part so that the values are rawurlencode()'ed. |
|
| 288 | +// Can't just use parse_url() cos we could be dealing with a relative URL which parse_url() can't deal with. |
|
| 289 | +$sURL = trim($sURL); |
|
| 290 | +$nQueryStart = strpos($sURL, '?', strrpos($sURL, '/')); |
|
| 291 | +if($nQueryStart === false) |
|
| 292 | +{ |
|
| 293 | +return $sURL; |
|
| 294 | +} |
|
| 295 | +$nQueryStart++; |
|
| 296 | +$nQueryEnd = strpos($sURL, '#', $nQueryStart); |
|
| 297 | +if($nQueryEnd === false) |
|
| 298 | +{ |
|
| 299 | +$nQueryEnd = strlen($sURL); |
|
| 300 | +} |
|
| 301 | +$sQueryPart = substr($sURL, $nQueryStart, $nQueryEnd - $nQueryStart); |
|
| 302 | +return str_replace('?' . $sQueryPart, $this->parseQueryPart($sQueryPart, $aServerParams), $sURL); |
|
| 303 | +} |
|
| 304 | 304 | } |