snapshot of https://github.com/krayin/laravel-crm.git (2.2, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Admin | Playwright Tests / Admin | Playwright Tests | Shard 1 Of 6 (push) Failing after 37s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 2 Of 6 (push) Failing after 7s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 4 Of 6 (push) Failing after 7s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 6 Of 6 (push) Failing after 6s
Linting Tests / PHP 8.3 test on ubuntu-latest (push) Failing after 5s
CI / PHP 8.3 test on ubuntu-latest (push) Failing after 6s
Skills Consistency / validate-skills (push) Successful in 10s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 3 Of 6 (push) Failing after 7s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 5 Of 6 (push) Failing after 6s
Some checks failed
Admin | Playwright Tests / Admin | Playwright Tests | Shard 1 Of 6 (push) Failing after 37s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 2 Of 6 (push) Failing after 7s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 4 Of 6 (push) Failing after 7s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 6 Of 6 (push) Failing after 6s
Linting Tests / PHP 8.3 test on ubuntu-latest (push) Failing after 5s
CI / PHP 8.3 test on ubuntu-latest (push) Failing after 6s
Skills Consistency / validate-skills (push) Successful in 10s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 3 Of 6 (push) Failing after 7s
Admin | Playwright Tests / Admin | Playwright Tests | Shard 5 Of 6 (push) Failing after 6s
This commit is contained in:
188
packages/Webkul/Core/src/SystemConfig.php
Normal file
188
packages/Webkul/Core/src/SystemConfig.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Webkul\Core;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Webkul\Core\Repositories\CoreConfigRepository;
|
||||
use Webkul\Core\SystemConfig\Item;
|
||||
|
||||
class SystemConfig
|
||||
{
|
||||
/**
|
||||
* Items array.
|
||||
*/
|
||||
public array $items = [];
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(protected CoreConfigRepository $coreConfigRepository) {}
|
||||
|
||||
/**
|
||||
* Add Item.
|
||||
*/
|
||||
public function addItem(Item $item): void
|
||||
{
|
||||
$this->items[] = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all configuration items.
|
||||
*/
|
||||
public function getItems(): Collection
|
||||
{
|
||||
if (! $this->items) {
|
||||
$this->prepareConfigurationItems();
|
||||
}
|
||||
|
||||
return collect($this->items)
|
||||
->sortBy('sort');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Core Config
|
||||
*/
|
||||
private function retrieveCoreConfig(): array
|
||||
{
|
||||
static $items;
|
||||
|
||||
if ($items) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
return $items = config('core_config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare configuration items.
|
||||
*/
|
||||
public function prepareConfigurationItems()
|
||||
{
|
||||
$configWithDotNotation = [];
|
||||
|
||||
foreach ($this->retrieveCoreConfig() as $item) {
|
||||
$configWithDotNotation[$item['key']] = $item;
|
||||
}
|
||||
|
||||
$configs = Arr::undot(Arr::dot($configWithDotNotation));
|
||||
|
||||
foreach ($configs as $configItem) {
|
||||
$subConfigItems = $this->processSubConfigItems($configItem);
|
||||
|
||||
$this->addItem(new Item(
|
||||
children: $subConfigItems,
|
||||
fields: $configItem['fields'] ?? null,
|
||||
icon: $configItem['icon'] ?? null,
|
||||
key: $configItem['key'],
|
||||
name: trans($configItem['name']),
|
||||
route: $configItem['route'] ?? null,
|
||||
info: trans($configItem['info']) ?? null,
|
||||
sort: $configItem['sort'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process sub config items.
|
||||
*/
|
||||
private function processSubConfigItems($configItem): Collection
|
||||
{
|
||||
return collect($configItem)
|
||||
->sortBy('sort')
|
||||
->filter(fn ($value) => is_array($value) && isset($value['name']))
|
||||
->map(function ($subConfigItem) {
|
||||
$configItemChildren = $this->processSubConfigItems($subConfigItem);
|
||||
|
||||
return new Item(
|
||||
children: $configItemChildren,
|
||||
fields: $subConfigItem['fields'] ?? null,
|
||||
icon: $subConfigItem['icon'] ?? null,
|
||||
key: $subConfigItem['key'],
|
||||
name: trans($subConfigItem['name']),
|
||||
info: trans($subConfigItem['info']) ?? null,
|
||||
route: $subConfigItem['route'] ?? null,
|
||||
sort: $subConfigItem['sort'] ?? null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active configuration item.
|
||||
*/
|
||||
public function getActiveConfigurationItem(): ?Item
|
||||
{
|
||||
if (! $slug = request()->route('slug')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$activeItem = $this->getItems()->where('key', $slug)->first() ?? null;
|
||||
|
||||
if (! $activeItem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($slug2 = request()->route('slug2')) {
|
||||
$activeItem = $activeItem->getChildren()[$slug2];
|
||||
}
|
||||
|
||||
return $activeItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config field.
|
||||
*/
|
||||
public function getConfigField(string $fieldName): ?array
|
||||
{
|
||||
foreach ($this->retrieveCoreConfig() as $coreData) {
|
||||
if (! isset($coreData['fields'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($coreData['fields'] as $field) {
|
||||
$name = $coreData['key'].'.'.$field['name'];
|
||||
|
||||
if ($name == $fieldName) {
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default config.
|
||||
*/
|
||||
private function getDefaultConfig(string $field): mixed
|
||||
{
|
||||
$configFieldInfo = $this->getConfigField($field);
|
||||
|
||||
$fields = explode('.', $field);
|
||||
|
||||
array_shift($fields);
|
||||
|
||||
$field = implode('.', $fields);
|
||||
|
||||
return Config::get($field, $configFieldInfo['default'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve information for configuration
|
||||
*/
|
||||
public function getConfigData(string $field): mixed
|
||||
{
|
||||
$coreConfigValue = $this->coreConfigRepository->findOneWhere([
|
||||
'code' => $field,
|
||||
]);
|
||||
|
||||
if (! $coreConfigValue) {
|
||||
return $this->getDefaultConfig($field);
|
||||
}
|
||||
|
||||
return $coreConfigValue->value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user