Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jul 2, 2024
1 parent b4893da commit 25acd18
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
7 changes: 1 addition & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,7 @@ parameters:

-
message: "#^Call to an undefined static method Igniter\\\\Flame\\\\Support\\\\Facades\\\\File\\:\\:isDirectory\\(\\)\\.$#"
count: 3
count: 4
path: src/Main/Classes/ThemeManager.php

-
Expand Down Expand Up @@ -3890,11 +3890,6 @@ parameters:
count: 3
path: src/Main/Models/Theme.php

-
message: "#^Call to an undefined static method Igniter\\\\Flame\\\\Support\\\\Facades\\\\File\\:\\:isDirectory\\(\\)\\.$#"
count: 1
path: src/Main/Providers/ThemeServiceProvider.php

-
message: "#^Call to an undefined static method Livewire\\\\Livewire\\:\\:componentHook\\(\\)\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
'text_staff_group' => 'User Group',
'text_location' => 'Location',
'text_set_status' => 'Set Status',
'text_edit_details' => 'Edit Details',
'text_edit_details' => 'My Account',
'text_network_admin' => 'Network Admin',
'text_administration' => 'Administration',
'text_logout' => 'Logout',
Expand Down
9 changes: 9 additions & 0 deletions src/Main/Classes/ThemeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Igniter\System\Classes\PackageManifest;
use Igniter\System\Classes\UpdateManager;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

/**
Expand Down Expand Up @@ -166,6 +167,14 @@ public function bootTheme(Theme $theme)
);
}
}

if (File::isDirectory($theme->getSourcePath())) {
View::addNamespace($theme->getName(), $theme->getSourcePath());

if ($theme->hasParent()) {
View::addNamespace($theme->getParent()->getName(), $theme->getSourcePath());
}
}
}

//
Expand Down
17 changes: 1 addition & 16 deletions src/Main/Providers/ThemeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Igniter\Flame\Igniter;
use Igniter\Flame\Pagic\Model;
use Igniter\Flame\Pagic\Router;
use Igniter\Flame\Support\Facades\File;
use Igniter\Main\Classes\MainController;
use Igniter\Main\Classes\SupportConfigurableComponent;
use Igniter\Main\Classes\Theme;
Expand Down Expand Up @@ -44,25 +43,11 @@ public function boot()
return;
}

($manager = resolve(ThemeManager::class))->bootThemes();
$this->registerThemesViewNamespace($manager->listThemes());
resolve(ThemeManager::class)->bootThemes();

Event::listen('main.controller.beforeRemap', function(MainController $controller) {
$controller->getTheme()?->loadThemeFile();
});
});
}

protected function registerThemesViewNamespace(array $themes)
{
foreach ($themes as $theme) {
if (File::isDirectory($theme->getSourcePath())) {
$this->loadViewsFrom($theme->getSourcePath(), $theme->getName());

if ($theme->hasParent()) {
$this->loadViewsFrom($theme->getSourcePath(), $theme->getParent()->getName());
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/System/Libraries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Country

public const ISO_CODE_3 = 3;

protected string $defaultFormat = "{address_1}\n{address_2}\n{city} {postcode}\n{state}\n{country}";
protected string $defaultFormat = "{address_1}\r\n{address_2}\r\n{city} {postcode}\r\n{state}\r\n{country}";

protected array $requiredAddressKeys = [
'address_1',
Expand Down Expand Up @@ -43,14 +43,14 @@ public function addressFormat(array|Model $address, bool $useLineBreaks = true):
$format = $address['format'];
}

$formattedAddress = str_replace(["\r\n", "\r", "\n"], '<br />',
$formattedAddress = str_replace(["\r\n", "\r", "\n", '\n'], '<br />',
preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br />', trim(str_replace([
'{address_1}', '{address_2}', '{city}', '{postcode}', '{state}', '{country}',
], array_except($address, 'format'), $format)))
);

if (!$useLineBreaks) {
$formattedAddress = str_replace('<br />', ', ', $formattedAddress);
$formattedAddress = str_replace(['<br />', '<br>', '<br/>'], ', ', $formattedAddress);
}

return strip_tags($formattedAddress, '<br>');
Expand Down

0 comments on commit 25acd18

Please sign in to comment.