|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
|
6
|
|
|
use Doctrine\Common\Annotations\SimpleAnnotationReader; |
|
7
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
|
8
|
|
|
use Illuminate\Config\Repository as Config; |
|
|
|
|
|
|
9
|
|
|
use Illuminate\Foundation\Application; |
|
|
|
|
|
|
10
|
|
|
use Illuminate\Routing\Router; |
|
11
|
|
|
use Illuminate\Support\ServiceProvider; |
|
12
|
|
|
use Terranet\Administrator\Architect; |
|
13
|
|
|
use Terranet\Administrator\Contracts\Services\Finder; |
|
14
|
|
|
use Terranet\Administrator\Schema; |
|
15
|
|
|
use Terranet\Localizer\Locale; |
|
16
|
|
|
|
|
17
|
|
|
class ContainersServiceProvider extends ServiceProvider |
|
18
|
|
|
{ |
|
19
|
|
|
protected $containers = [ |
|
20
|
|
|
'AdminConfig' => 'scaffold.config', |
|
21
|
|
|
'AdminResource' => 'scaffold.module', |
|
22
|
|
|
'AdminModel' => 'scaffold.model', |
|
23
|
|
|
'AdminSchema' => 'scaffold.schema', |
|
24
|
|
|
'AdminTranslations' => 'scaffold.translations', |
|
25
|
|
|
'AdminAnnotations' => 'scaffold.annotations', |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
public function register() |
|
29
|
|
|
{ |
|
30
|
|
|
foreach (array_keys($this->containers) as $container) { |
|
31
|
|
|
$method = "register{$container}"; |
|
32
|
|
|
|
|
33
|
|
|
\call_user_func_array([$this, $method], []); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function registerAdminAnnotations() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->app->singleton('scaffold.annotations', function () { |
|
40
|
|
|
AnnotationRegistry::registerUniqueLoader('class_exists'); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$reader = new SimpleAnnotationReader(); |
|
43
|
|
|
$reader->addNamespace('\\Terranet\\Administrator\\Annotations'); |
|
44
|
|
|
|
|
45
|
|
|
return $reader; |
|
46
|
|
|
}); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function registerAdminConfig() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->app->singleton('scaffold.config', function ($app) { |
|
52
|
|
|
$config = $app['config']['administrator']; |
|
53
|
|
|
|
|
54
|
|
|
return new Config((array) $config); |
|
55
|
|
|
}); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function registerAdminTranslations() |
|
59
|
|
|
{ |
|
60
|
|
|
// Draft: Mui configuration |
|
61
|
|
|
// Goal: sometimes there is a case when few content managers (admins) override the same translatable content (files, db, etc...) |
|
62
|
|
|
// This service allows to make some locales readonly: |
|
63
|
|
|
// 1. they are available in UI in order to preserve the context |
|
64
|
|
|
// 2. they are protected from saving process |
|
65
|
|
|
// Making locale(s) Readonly remains for Dev's side: the recommended way - use a custom Middleware. |
|
66
|
|
|
// ex.: app('scaffold.translations')->setReadonly([1, 2, 3]) |
|
67
|
|
|
$this->app->singleton('scaffold.translations', function ($app) { |
|
68
|
|
|
return new class() { |
|
69
|
|
|
protected $readonly = []; |
|
70
|
|
|
|
|
71
|
|
|
public function __construct() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->setReadonly(config('administrator.translations.readonly', [])); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Set ReadOnly locales. |
|
78
|
|
|
* |
|
79
|
|
|
* @param array $readonly |
|
80
|
|
|
* @return self |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setReadonly(array $readonly = []): self |
|
83
|
|
|
{ |
|
84
|
|
|
$this->readonly = (array) $readonly; |
|
85
|
|
|
|
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Check if a Locale is ReadOnly. |
|
91
|
|
|
* |
|
92
|
|
|
* @param $locale |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function readonly($locale) |
|
96
|
|
|
{ |
|
97
|
|
|
if ($locale instanceof Locale) { |
|
98
|
|
|
$locale = $locale->id(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return \in_array((int) $locale, $this->readonly, true); |
|
102
|
|
|
} |
|
103
|
|
|
}; |
|
104
|
|
|
}); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
protected function registerAdminResource() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->app->singleton('scaffold.module', function (Application $app) { |
|
110
|
|
|
/** @var Router $router */ |
|
111
|
|
|
$router = $app['router']->current(); |
|
112
|
|
|
|
|
113
|
|
|
if (in_array($router->getName(), ['scaffold.settings.edit', 'scaffold.settings.update'], true)) { |
|
114
|
|
|
return Architect::resourceForKey('settings'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if ($key = $router->parameter('module')) { |
|
118
|
|
|
return Architect::resourceForKey($key); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
}); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
protected function registerAdminModel() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->app->singleton('scaffold.model', function (Application $app) { |
|
126
|
|
|
/** @var int $id */ |
|
127
|
|
|
$id = (int) $app['router']->current()->parameter('id'); |
|
128
|
|
|
|
|
129
|
|
|
/** @var Finder $finder */ |
|
130
|
|
|
$finder = app('scaffold.module')->finder(); |
|
|
|
|
|
|
131
|
|
|
if ($id && $finder) { |
|
132
|
|
|
return $finder->find($id); |
|
133
|
|
|
} |
|
134
|
|
|
}); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
protected function registerAdminSchema() |
|
138
|
|
|
{ |
|
139
|
|
|
$this->app->singleton('scaffold.schema', function (Application $app) { |
|
140
|
|
|
/** @var AbstractSchemaManager $schema */ |
|
141
|
|
|
if ($schema = $app['db']->connection()->getDoctrineSchemaManager()) { |
|
142
|
|
|
// fix dbal missing types |
|
143
|
|
|
$platform = $schema->getDatabasePlatform(); |
|
144
|
|
|
$platform->registerDoctrineTypeMapping('enum', 'string'); |
|
145
|
|
|
$platform->registerDoctrineTypeMapping('set', 'string'); |
|
146
|
|
|
|
|
147
|
|
|
return new Schema($schema); |
|
148
|
|
|
} |
|
149
|
|
|
}); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths