Skip to content

Commit

Permalink
thusfar
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmagicii committed Jun 23, 2024
1 parent e312010 commit d3b52c8
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/Nether/Avenue/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class Library
extends Nether\Common\Library {

public const
ConfRouteFile = 'Nether.Avenue.RouteFile',
ConfRouteRoot = 'Nether.Avenue.RouteRoot',
ConfWebRoot = 'Nether.Avenue.WebRoot',
ConfDomainLvl = 'Nether.Avenue.DomainLvl',
ConfDomainSep = 'Nether.Avenue.DomainSep',
ConfVerbRewrite = 'Nether.Avenue.VerbRewrite';
ConfRouteFile = 'Nether.Avenue.RouteFile',
ConfRouteRoot = 'Nether.Avenue.RouteRoot',
ConfWebRoot = 'Nether.Avenue.WebRoot',
ConfDomainLvl = 'Nether.Avenue.DomainLvl',
ConfDomainSep = 'Nether.Avenue.DomainSep',
ConfVerbRewrite = 'Nether.Avenue.VerbRewrite',
ConfExtraDataArgs = 'Nether.Avenue.Route.ExtraDataArgs';

public const
RouteSourceScan = 'dirscan',
Expand Down
30 changes: 30 additions & 0 deletions src/Nether/Avenue/Meta/ExtraDataArgs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Nether\Avenue\Meta;

use Attribute;
use ReflectionMethod;
use ReflectionAttribute;
use Nether\Common\Prototype\MethodInfo;
use Nether\Common\Prototype\MethodInfoInterface;

#[Attribute(Attribute::TARGET_METHOD)]
class ExtraDataArgs
implements MethodInfoInterface {

public function
__Construct() {



return;
}

public function
OnMethodInfo(MethodInfo $Info, ReflectionMethod $RefMethod, ReflectionAttribute $RefAttrib):
void {

return;
}

}
5 changes: 4 additions & 1 deletion src/Nether/Avenue/Meta/RouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public function
keep it around for reuse later in the event route acceptance succeeds.
//*/

return new ($this->Class)($this, $Req, $Resp);
/** @var Route $Output */
$Output = new ($this->Class)($this, $Req, $Resp);

return $Output;
}

public function
Expand Down
2 changes: 1 addition & 1 deletion src/Nether/Avenue/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function
////////

$this->Path = $Path;
$this->Query = new Datafilter($_GET);
$this->Query = new Datafilter($Vars);

return $this;
}
Expand Down
16 changes: 14 additions & 2 deletions src/Nether/Avenue/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,18 @@ protected function
perform route handler execution.
//*/

$Route = $Handler->GetRouteInstance($this->Request, $this->Response);
$MethodInfo = $Route::GetMethodInfo($Handler->Method);

$Extraspand = (FALSE
|| Library::Get(Library::ConfExtraDataArgs)
|| $MethodInfo->HasAttribute(Meta\ExtraDataArgs::class)
);

////////

$this->CurrentHandler = $Handler;
$this->CurrentRoute = $Handler->GetRouteInstance($this->Request, $this->Response);
$this->CurrentRoute = $Route;

$this->Response->CaptureBegin();
$this->CurrentRoute->OnReady($ExtraData);
Expand All @@ -420,7 +430,9 @@ protected function
////////

try {
$this->CurrentRoute->{$Handler->Method}(...$Handler->GetMethodArgValues($ExtraData, TRUE));
$this->CurrentRoute->{$Handler->Method}(
...$Handler->GetMethodArgValues($ExtraData, $Extraspand
));
}

//catch(ArgumentCountError $Err) {
Expand Down
2 changes: 1 addition & 1 deletion src/Nether/Avenue/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static public function
if(!array_key_exists(++$T, $Tokens))
break;

if($Tokens[$T]->Is(['(']))
if($Tokens[$T]->Is(['(', ')']))
break;

if(!$Tokens[$T]->Is(T_STRING))
Expand Down
2 changes: 2 additions & 0 deletions tests/Nether/Avenue/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Nether\Avenue\Error\RouteMissingWillAnswerRequest;
use Nether\Common\Datastore;

new \Nether\Avenue\Library([]);

class RouterTest
extends PHPUnit\Framework\TestCase {

Expand Down
52 changes: 52 additions & 0 deletions tests11/Router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Nether\Common;
use NetherTestSuite\Avenue\zRoutes;

new Avenue\Library([]);

class RouterTest
extends PHPUnit\Framework\TestCase {

Expand Down Expand Up @@ -184,4 +186,54 @@ public function
return;
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

#[PHPUnit\Framework\Attributes\Test]
public function
TestExtraDataArgExpansion():
void {

$ExtraData = new Avenue\Struct\ExtraData;
$Router = static::PrepareRouter();

////////

$ExtraData->Clear();
$Router->Response->Clear();
$Router->Request->ParseRequest('GET', 'nether.local', '/eda/false?one=1&two=second');
$Handler = $Router->Select($ExtraData);

$Router->Execute($Handler, $ExtraData);
$Result = Common\Filters\Text::TrimmedNullable($Router->Response->Content);

$this->AssertEquals('ExtraDataArgs=FALSE', $Result);
$this->AssertTrue($ExtraData->HasKey('One'));
$this->AssertEquals('1', $ExtraData->Get('One'));
$this->AssertTrue($ExtraData->HasKey('Two'));
$this->AssertEquals('second', $ExtraData->Get('Two'));

////////

$ExtraData->Clear();
$Router->Response->Clear();
$Router->Request->ParseRequest('GET', 'nether.local', '/eda/true?one=1&two=second');
$Handler = $Router->Select($ExtraData);

$Router->Execute($Handler, $ExtraData);
$Result = Common\Filters\Text::TrimmedNullable($Router->Response->Content);

$this->AssertEquals('ExtraDataArgs=TRUE, 1, second', $Result);
$this->AssertTrue($ExtraData->HasKey('One'));
$this->AssertEquals('1', $ExtraData->Get('One'));
$this->AssertTrue($ExtraData->HasKey('Two'));
$this->AssertEquals('second', $ExtraData->Get('Two'));

////////

$Router->Response->Clear();

return;
}

};
44 changes: 44 additions & 0 deletions tests11/zRoutes/AnRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace NetherTestSuite\Avenue\zRoutes;

use Nether\Avenue;
use Nether\Common;

class AnRoute
extends Avenue\Route {

#[Avenue\Meta\RouteHandler('/eda/false')]
#[Avenue\Meta\ConfirmWillAnswerRequest('ExtraDataArgsWillAnswerRequest')]
public function
ExtraDataArgsFalse(?Avenue\Struct\ExtraData $Data):
void {

echo 'ExtraDataArgs=FALSE';

return;
}

#[Avenue\Meta\RouteHandler('/eda/true')]
#[Avenue\Meta\ConfirmWillAnswerRequest('ExtraDataArgsWillAnswerRequest')]
#[Avenue\Meta\ExtraDataArgs]
public function
ExtraDataArgsTrue(int $One, string $Two):
void {

printf('ExtraDataArgs=TRUE, %d, %s', $One, $Two);

return;
}

protected function
ExtraDataArgsWillAnswerRequest(?Avenue\Struct\ExtraData $Data):
int {

$Data['One'] = (int)$this->Request->Query->Get('One');
$Data['Two'] = (string)$this->Request->Query->Get('Two');

return Avenue\Response::CodeOK;
}

};

0 comments on commit d3b52c8

Please sign in to comment.