1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oscer\Cms\Core\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Config\Repository; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use Oscer\Cms\Core\Options\Models\Option; |
9
|
|
|
use Oscer\Cms\Frontend\Contracts\Theme; |
10
|
|
|
|
11
|
|
|
class ResolveOptionsCommand extends Command |
12
|
|
|
{ |
13
|
|
|
protected $signature = 'cms:options:resolve'; |
14
|
|
|
|
15
|
|
|
protected $description = 'Resolve all options from the configuration and the theme'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Execute the console command. |
19
|
|
|
* |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function handle(Theme $theme, Repository $config) |
23
|
|
|
{ |
24
|
|
|
$resolvedOptions = new Collection(); |
25
|
|
|
$tabsWithOptions = collect(array_merge( |
26
|
|
|
$config->get('cms.options'), |
27
|
|
|
['theme' => $theme->getOptions()] |
28
|
|
|
)); |
29
|
|
|
$tabsWithOptions->each(function (array $options, string $tab) use ($resolvedOptions) { |
30
|
|
|
foreach ($options as $key => $specification) { |
31
|
|
|
$resolvedOptions->add(Option::query()->updateOrCreate(['key' => "{$tab}.{$key}"], [ |
32
|
|
|
'key' => "{$tab}.{$key}", |
33
|
|
|
'type' => $specification['type'], |
34
|
|
|
'label' => isset($specification['label']) ? $specification['label'] : null, |
35
|
|
|
])); |
36
|
|
|
} |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
/** @var Collection $resolvedOptionKeys */ |
40
|
|
|
$resolvedOptionKeys = $resolvedOptions->map->key; |
|
|
|
|
41
|
|
|
|
42
|
|
|
if ($resolvedOptions->count() < Option::query()->count()) { |
43
|
|
|
Option::all()->filter(function (Option $option) use ($resolvedOptionKeys) { |
44
|
|
|
return ! $resolvedOptionKeys->contains($option->key); |
45
|
|
|
})->each->delete(); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.