-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support parse asset tag via middleware
- Loading branch information
Showing
5 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Constracts; | ||
|
||
use Psr\Http\Server\MiddlewareInterface; | ||
|
||
interface MiddlewareConstract extends MiddlewareInterface | ||
{ | ||
public function getPriority(): int; | ||
} |
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,62 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use App\Constracts\MiddlewareConstract; | ||
use App\Core\HookManager; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Slim\Psr7\Response; | ||
|
||
class AssetsMiddleware implements MiddlewareConstract | ||
{ | ||
public function getPriority(): int | ||
{ | ||
return 9999; | ||
} | ||
|
||
protected function getHeadAssets() | ||
{ | ||
ob_start(); | ||
HookManager::executeAction('head'); | ||
return ob_get_clean(); | ||
} | ||
|
||
protected function getOpenBodyTags() | ||
{ | ||
ob_start(); | ||
HookManager::executeAction('start_body'); | ||
return ob_get_clean(); | ||
} | ||
|
||
protected function getFooterAssets() | ||
{ | ||
ob_start(); | ||
HookManager::executeAction('footer'); | ||
return ob_get_clean(); | ||
} | ||
|
||
// Replace template tags by action hooks | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$response = $handler->handle($request); | ||
|
||
$template = (string) $response->getBody(); | ||
|
||
$template = str_replace([ | ||
'<!--asset:head-->', | ||
'<!--asset:start_body-->', | ||
'<!--asset:footer-->' | ||
], [ | ||
$this->getHeadAssets(), | ||
$this->getOpenBodyTags(), | ||
$this->getFooterAssets() | ||
], $template); | ||
|
||
$response = new Response(); | ||
$response->getBody()->write($template); | ||
|
||
return $response; | ||
} | ||
} |
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
Submodule dashboard
updated
from 7c01e4 to fe55df
Submodule react
updated
from 126082 to aeaa4a