Skip to content

Commit 007f5c9

Browse files
authored
πŸ› auto control discovery (#20)
1 parent bdd9c1f commit 007f5c9

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

β€Žsrc/Console/ControlMakeCommand.phpβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function buildPerimetersReplacements(array $replace, array $perimeters
116116
$perimetersImplementation = '';
117117

118118
foreach ($perimeters as $perimeter) {
119-
$perimeterClass = $this->rootNamespace().'Access\\Perimeters\\'.$perimeter;
119+
$perimeterClass = '\\'.$this->rootNamespace().'Access\\Perimeters\\'.$perimeter;
120120

121121
$perimetersImplementation .= <<<PERIMETER
122122
$perimeterClass::new()
@@ -129,6 +129,7 @@ protected function buildPerimetersReplacements(array $replace, array $perimeters
129129
->query(function (Builder \$query, Model \$user) {
130130
return \$query;
131131
}),
132+
132133
PERIMETER;
133134
}
134135

β€Žsrc/Controls/Control.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public static function resolveControlName(string $modelName): string
237237
// @TODO: The auto guess here is strange, we specify the models / controls everywhere, is there a better way of doing this ? (In policies guess the model as Laravel is doing ?)
238238
// @TODO: Discussed with Lucas G
239239

240-
if (method_exists($modelName, 'control')) {
240+
if (property_exists($modelName, 'control')) {
241241
return $modelName::control()::class;
242242
}
243243

β€Žsrc/Controls/HasControl.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public static function control()
3333
*/
3434
protected static function newControl(): ?Control
3535
{
36-
return static::$control::new() ?? null;
36+
return property_exists(static::class, 'control') ? static::$control::new() : null;
3737
}
3838
}

β€Žsrc/Controls/HasControlScope.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function addControlled(Builder $builder): void
5454
{
5555
$builder->macro('controlled', function (Builder $builder) {
5656
/** @var Control $control */
57-
$control = $builder->getModel()->newControl();
57+
$control = $builder->getModel()::control();
5858

5959
return $control->queried($builder, Auth::user());
6060
});

0 commit comments

Comments
Β (0)