Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
setup new middleware (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEssex authored Nov 5, 2023
1 parent 82f8d55 commit 4c3ebf8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 70 deletions.
8 changes: 8 additions & 0 deletions .cubex/paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"excludeFromSitemap": false,
"changeFrequency": "monthly",
"history": []
},
"/secure": {
"title": null,
"lastModified": null,
"priority": 1,
"excludeFromSitemap": false,
"changeFrequency": "monthly",
"history": []
}
}
}
2 changes: 1 addition & 1 deletion public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>http://cubexbase.local-host.xyz:6090/</loc><priority>1</priority><changefreq>monthly</changefreq></url></urlset>
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>http://cubexbase.local-host.xyz:6090/</loc><priority>1</priority><changefreq>monthly</changefreq></url><url><loc>http://cubexbase.local-host.xyz:6090/secure</loc><priority>1</priority><changefreq>monthly</changefreq></url></urlset>
20 changes: 12 additions & 8 deletions src/Http/Controllers/SecureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@

namespace CubexBase\Application\Http\Controllers;

use Cubex\Middleware\MiddlewareHandler;
use CubexBase\Application\Context\AppContext;
use CubexBase\Application\Http\Layout\LayoutController;
use CubexBase\Application\Http\Middleware\ExampleMiddleware;
use Packaged\Context\Context;
use Packaged\Routing\Handler\FuncHandler;
use Symfony\Component\HttpFoundation\Response;

class SecureController extends LayoutController
{
protected function _middleware(): array
{
return [
ExampleMiddleware::class,
];
}

protected function _generateRoutes()
{
yield self::_route('$', 'secure');
}

public function getSecure(AppContext $ctx)
{
return 'This should never be seen';
return Response::create('This should never be seen');
}

public function handle(Context $c): Response
{
$middleware = new MiddlewareHandler(new FuncHandler(fn(Context $c) => parent::handle($c)));
$middleware->add(new ExampleMiddleware());
return $middleware->handle($c);
}
}
1 change: 0 additions & 1 deletion src/Http/Layout/WithErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ abstract class WithErrorController extends AuthedController implements WithConte
use GetTranslatorTrait;
use TranslatableTrait;
use WithContextTrait;
use WithMiddlewareTrait;

protected function _getHandler(Context $context): callable|string|Handler
{
Expand Down
13 changes: 0 additions & 13 deletions src/Http/Middleware/AbstractMiddleware.php

This file was deleted.

17 changes: 13 additions & 4 deletions src/Http/Middleware/ExampleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

namespace CubexBase\Application\Http\Middleware;

use Cubex\Middleware\Middleware;
use Packaged\Context\Context;
use Packaged\Http\Responses\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class ExampleMiddleware extends AbstractMiddleware
class ExampleMiddleware extends Middleware
{
public function process(&$response): bool
public function handle(Context $c): Response
{
$response = RedirectResponse::create('/');
return false;
// example middleware
echo "<pre>Pre Middleware</pre><br>";
$response = $this->next($c);
echo $response->getContent();
echo "<br><pre>Post Middleware</pre>";

// redirect to home page
return RedirectResponse::create('/');
}
}
43 changes: 0 additions & 43 deletions src/Http/Middleware/WithMiddlewareTrait.php

This file was deleted.

0 comments on commit 4c3ebf8

Please sign in to comment.