Skip to content

Commit

Permalink
Version 2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhirtz committed Apr 15, 2024
1 parent 274159c commit 1d902e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.1 (Apr 15, 2024)

- Extracted draft domain creating from `Request` to `Url::draft()`

## 2.3.0 (Apr 5, 2024)

- Added `DashboardController::$roles` to allow adjusting the admin dashboard roles, defaults to the roles used in the
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/Url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace davidhirtz\yii2\skeleton\helpers;

use Yii;
use yii\helpers\BaseUrl;

class Url extends BaseUrl
{
public static function draft(string $url): string
{
$request = Yii::$app->getRequest();

if ($request->draftSubdomain === false) {
return $url;
}

return !$request->getIsDraft() || !str_contains($url, $request->draftSubdomain)
? preg_replace('#^((https?://)(www.)?)#', "$2$request->draftSubdomain.", $url)
: $url;
}
}
14 changes: 2 additions & 12 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace davidhirtz\yii2\skeleton\web;

use davidhirtz\yii2\skeleton\helpers\ArrayHelper;
use davidhirtz\yii2\skeleton\helpers\Url;
use Yii;

/**
Expand Down Expand Up @@ -82,18 +83,7 @@ public function getProductionHostInfo(): string
*/
public function getDraftHostInfo(): false|string
{
if (!$this->draftSubdomain) {
return false;
}

if ($this->_draftHostInfo === null) {
$hostInfo = (string)$this->getHostInfo();

$this->_draftHostInfo = !$this->getIsDraft() || !str_contains($hostInfo, $this->draftSubdomain)
? preg_replace('#^((https?://)(www.)?)#', "$2$this->draftSubdomain.", $hostInfo)
: $this->getHostInfo();
}

$this->_draftHostInfo ??= Url::draft((string)$this->getHostInfo());
return $this->_draftHostInfo;
}

Expand Down

0 comments on commit 1d902e4

Please sign in to comment.