Skip to content

Commit

Permalink
Merge pull request #78 from hexadog/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
gaetan-hexadog authored Jan 4, 2024
2 parents c1237f6 + 7296907 commit 0665f13
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 785 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0|^10.0",
"laravel/pint": "^1.10",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.3"
},
"autoload": {
Expand Down
1,371 changes: 620 additions & 751 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function page_title(string $title, bool $withAppName = true, string $separator =
/**
* Set theme.
*/
function theme(string $themeName = null): Hexadog\ThemesManager\Theme
function theme(?string $themeName = null): Hexadog\ThemesManager\Theme
{
if ($themeName) {
\Theme::set($themeName);
Expand Down
6 changes: 4 additions & 2 deletions src/Components/PageTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public function __construct(mixed $title = null, mixed $withAppName = true, mixe
$title = View::getSection('title');
}

if (! empty($title) && $withAppName) {
if ($invert) {
if (! empty($title)) {
if (! filter_var($withAppName, FILTER_VALIDATE_BOOLEAN)) {
$this->title = $title;
} elseif ($invert) {
$this->title = $title . ' ' . trim(e($separator)) . ' ' . config('app.name');
} else {
$this->title = config('app.name') . ' ' . trim(e($separator)) . ' ' . $title;
Expand Down
6 changes: 4 additions & 2 deletions src/Events/ThemeDisabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Hexadog\ThemesManager\Events;

use Hexadog\ThemesManager\Theme;

class ThemeDisabled
{
public array|string $theme;
public Theme $theme;

public function __construct($theme)
public function __construct(Theme $theme)
{
$this->theme = $theme;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Events/ThemeDisabling.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Hexadog\ThemesManager\Events;

use Hexadog\ThemesManager\Theme;

class ThemeDisabling
{
public array|string $theme;
public Theme $theme;

public function __construct($theme)
public function __construct(Theme $theme)
{
$this->theme = $theme;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Events/ThemeEnabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Hexadog\ThemesManager\Events;

use Hexadog\ThemesManager\Theme;

class ThemeEnabled
{
public array|string $theme;
public Theme $theme;

public function __construct($theme)
public function __construct(Theme $theme)
{
$this->theme = $theme;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Events/ThemeEnabling.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Hexadog\ThemesManager\Events;

use Hexadog\ThemesManager\Theme;

class ThemeEnabling
{
public array|string $theme;
public Theme $theme;

public function __construct($theme)
public function __construct(Theme $theme)
{
$this->theme = $theme;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Helpers/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Json
/**
* The constructor.
*/
public function __construct(string $path, Filesystem $filesystem = null)
public function __construct(string $path, ?Filesystem $filesystem = null)
{
$this->path = $path;
$this->filesystem = $filesystem ? $filesystem : new Filesystem();
Expand Down Expand Up @@ -103,7 +103,7 @@ public function setPath(string $path): Json
/**
* Make new instance.
*/
public static function make(string $path, Filesystem $filesystem = null): Json
public static function make(string $path, ?Filesystem $filesystem = null): Json
{
return new self($path, $filesystem);
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getAttributes(): array
/**
* Convert the given array data to pretty json.
*/
public function toJsonPretty(array $data = null): false|string
public function toJsonPretty(?array $data = null): false|string
{
return json_encode($data ? $data : $this->attributes, JSON_PRETTY_PRINT);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/ThemeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ThemeLoader
/**
* Handle an incoming request.
*/
public function handle(Request $request, \Closure $next, string $theme = null)
public function handle(Request $request, \Closure $next, ?string $theme = null)
{
// Do not load theme if API request or App is running in console
if ($request->expectsJson() || app()->runningInConsole()) {
Expand Down
27 changes: 12 additions & 15 deletions src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
use Hexadog\ThemesManager\Traits\HasViews;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\File;

final class Theme
{
Expand Down Expand Up @@ -57,8 +57,7 @@ final class Theme
/**
* The theme screenshot.
*/

protected string $screenshot = "";
protected string $screenshot = '';

/**
* The theme statud (enabled or not).
Expand Down Expand Up @@ -95,15 +94,15 @@ public static function make(...$arguments): self
/**
* Get path.
*/
public function getPath(string $path = null): string
public function getPath(?string $path = null): string
{
return $this->path . $path;
}

/**
* Get assets path.
*/
public function getAssetsPath(string $path = null): string
public function getAssetsPath(?string $path = null): string
{
return Config::get('themes-manager.symlink_path', 'themes') . '/' . mb_strtolower($this->vendor) . '/' . mb_strtolower($this->name) . ($path ? '/' . $path : '');
}
Expand Down Expand Up @@ -180,7 +179,7 @@ public function setPath(string $path): self
/**
* Set theme vendor.
*/
public function setVendor(string $vendor = null): self
public function setVendor(?string $vendor = null): self
{
if (Str::contains($vendor, '/')) {
$this->vendor = dirname($vendor);
Expand Down Expand Up @@ -226,11 +225,9 @@ public function getParent(): ?Theme
return $this->parent;
}


/**
* Set theme screenshot.
*/

public function setScreenshot(string $screenshot): self
{

Expand All @@ -239,7 +236,7 @@ public function setScreenshot(string $screenshot): self
return $this;
}

public function getScreenshotName(): string|null
public function getScreenshotName(): ?string
{
return $this->screenshot;
}
Expand All @@ -249,11 +246,11 @@ public function getScreenshotImageUrl(): string
return $this->url($this->screenshot);
}

public function getScreenshotImageBase64(): string|null
public function getScreenshotImageBase64(): ?string
{
$screenshotImage = $this->getAssetsPath($this->screenshot);

if (!is_file($screenshotImage)) {
if (! is_file($screenshotImage)) {
return null;
}

Expand Down Expand Up @@ -284,13 +281,13 @@ public function disable(bool $withEvent = true): Theme
// Check if current is active and currently enabled
if ($this->enabled()) {
if ($withEvent) {
event(new ThemeDisabling($this->name));
event(new ThemeDisabling($this));
}

$this->enabled = false;

if ($withEvent) {
event(new ThemeDisabled($this->name));
event(new ThemeDisabled($this));
}
}

Expand All @@ -305,15 +302,15 @@ public function enable(bool $withEvent = true): Theme
// Check if current is active and currently disabled
if ($this->disabled()) {
if ($withEvent) {
event(new ThemeEnabling($this->name));
event(new ThemeEnabling($this));
}

$this->enabled = true;
$this->loadViews();
$this->loadTranlastions();

if ($withEvent) {
event(new ThemeEnabled($this->name));
event(new ThemeEnabled($this));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ThemesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function all(): Collection
/**
* Check if theme with given name exists.
*/
public function has(string $name = null): bool
public function has(?string $name = null): bool
{
return ! is_null($this->findByName($name, null));
}

/**
* Get theme by name (or return all themes if no name given).
*/
public function get(string $name = null): ?Theme
public function get(?string $name = null): ?Theme
{
return $this->findByName($name, null);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function url(string $asset, bool $absolute = true): ?string
* If no vendor provided and name not prefixed by vendor
* the first theme with given name is returned.
*/
public function findByName(string $name, string $vendor = null): ?Theme
public function findByName(string $name, ?string $vendor = null): ?Theme
{
// normalize theme name
$name = str_replace(['-theme', 'theme-'], '', $name);
Expand Down

0 comments on commit 0665f13

Please sign in to comment.