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

Commit

Permalink
Fixes for currentURL
Browse files Browse the repository at this point in the history
Use _cubex where available
  • Loading branch information
MrEssex committed Nov 7, 2023
1 parent 4c3ebf8 commit ad58aee
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 50 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Context/AppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function _initialize(): void
*
* @return LinkBuilder
*/
public function linkBuilder(string $path = '', array $query = []): LinkBuilder
public function www(string $path = '', array $query = []): LinkBuilder
{
return LinkBuilder::fromRequest($this->request(), $path, $query)->setSubDomain('www');
}
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Layout/DefaultLayout/Layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ $store = Dispatch::instance()->store();
<head>
<meta charset="UTF-8">

<link rel="icon" href="<?= $ctx->linkBuilder('/favicon.ico?v=1.0') ?>">
<link rel="icon" href="<?= $ctx->linkBuilder('/icon.svg') ?>" type="image/svg+xml">
<link rel="apple-touch-icon" href="<?= $ctx->linkBuilder('/icon.png') ?>">
<link type="text/plain" rel="author" href="<?= $ctx->linkBuilder('/humans.txt') ?>">
<link rel="manifest" href="<?= $ctx->linkBuilder('/site.webmanifest') ?>">
<link rel="icon" href="<?= $ctx->www('/favicon.ico?v=1.0') ?>">
<link rel="icon" href="<?= $ctx->www('/icon.svg') ?>" type="image/svg+xml">
<link rel="apple-touch-icon" href="<?= $ctx->www('/icon.png') ?>">
<link type="text/plain" rel="author" href="<?= $ctx->www('/humans.txt') ?>">
<link rel="manifest" href="<?= $ctx->www('/site.webmanifest') ?>">

<?php if($this->seoProvider): ?>
<?= $this->seoProvider ?>
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Layout/LayoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace CubexBase\Application\Http\Layout;

use Cubex\CubexAware;
use CubexBase\Application\Http\Layout\DefaultLayout\Layout;
use CubexBase\Application\Http\Views\AbstractView;
use CubexBase\Application\MainApplication;
Expand Down Expand Up @@ -67,11 +66,12 @@ protected function _isAppropriateResponse($result): bool

public function getTheme()
{
$ctx = $this->getContext();
if($ctx instanceof CubexAware)
$cubex = $this->_cubex();
if($cubex)
{
return $ctx->getCubex()->resolve(Layout::class);
return $cubex->resolve(Layout::class);
}

return Layout::withContext($this);
}
}
7 changes: 2 additions & 5 deletions src/Http/Layout/WithErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace CubexBase\Application\Http\Layout;

use Cubex\Controller\AuthedController;
use Cubex\Cubex;
use Cubex\CubexAware;
use Cubex\I18n\GetTranslatorTrait;
use CubexBase\Application\Context\AppContext;
use CubexBase\Application\Http\Middleware\WithMiddlewareTrait;
Expand Down Expand Up @@ -34,10 +32,9 @@ protected function _processHandler(Context $c, $handler, &$response): bool
{
while(is_callable($handler))
{
/** @var Cubex $cubex */
if($c instanceof CubexAware)
$cubex = $this->_cubex();
if($cubex)
{
$cubex = @$c->getCubex();
$handler = $cubex->resolveMethod($handler[0], $handler[1]);
}
}
Expand Down
41 changes: 17 additions & 24 deletions src/MainApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,8 @@ protected function _setupApplication(): void
{
$ctx = $this->getContext();
$ctx->prepareTranslator('/translations/', $ctx->matches(ExpectEnvironment::local()));

if(!$this->getCubex() instanceof Cubex)
{
return;
}

$this->getCubex()->listen(
$cubex = @$this->getCubex();
$cubex->listen(
ResponsePreSendHeadersEvent::class,
function (ResponsePreSendHeadersEvent $event) {
$this->_setupHeaders($event);
Expand All @@ -183,7 +178,7 @@ function (ResponsePreSendHeadersEvent $event) {
// Dont generate sitemap on api requests
if($ctx->matches(ExpectEnvironment::local()) && !str_starts_with($ctx->request()->path(), '/api'))
{
SitemapListener::with($this->getCubex(), $ctx);
SitemapListener::with($cubex, $ctx);
}
}

Expand All @@ -203,11 +198,17 @@ protected function _setupHeaders(ResponsePreSendHeadersEvent $event): SResponse
$response->headers->set('Access-Control-Allow-Origin', $ctx->request()->headers->get('origin'));
}

$url = 'http://www.cubexbase.local-host.xyz:6090';
$currentUrl = $ctx->request()->urlSprintf();
$schema = $ctx->request()->getScheme();
if(!str_contains($currentUrl, $schema . '://www'))
{
$currentUrl = str_replace($schema . '://', $schema . '://www.', $currentUrl);
}

$csp = new ContentSecurityPolicy([
ContentSecurityPolicy::DEFAULT_SRC => ["'self'"],
ContentSecurityPolicy::IMG_SRC => ["'self'", $url],
ContentSecurityPolicy::SCRIPT_SRC => ["'self'", "'unsafe-inline'", "'unsafe-eval'"],
ContentSecurityPolicy::DEFAULT_SRC => ["'self'", $currentUrl],
ContentSecurityPolicy::IMG_SRC => ["'self'", $currentUrl],
ContentSecurityPolicy::SCRIPT_SRC => ["'self'", "'unsafe-inline'", "'unsafe-eval'", $currentUrl],
ContentSecurityPolicy::OBJECT_SRC => ["'none'"],
ContentSecurityPolicy::FRAME_ANCESTORS => ["'none'"],
]);
Expand All @@ -224,20 +225,12 @@ protected function _defaultHandler(): Handler
protected function _setupCookies(ResponsePreSendHeadersEvent $event)
{
$response = $event->getResponse();
/** @var AppContext $ctx */
$ctx = $event->getContext();
$cubex = @$this->getCubex();

// Add flash messages to cookies
$flash = $ctx->getCubex()->retrieve(FlashMessageProvider::class);
if($flash->hasMessages())
{
$response->headers->setCookie(
$flash->toCookie()
);
}
else
{
$flash = $cubex->retrieve(FlashMessageProvider::class);
$flash->hasMessages() ?
$response->headers->setCookie($flash->toCookie()) :
$response->headers->clearCookie('flash');
}
}
}

0 comments on commit ad58aee

Please sign in to comment.