Testing and Tooling

Generators

make:control and make:perimeter scaffold the controls and the perimeter classes, from stubs that you can publish and change.
php artisan make:perimeter ClientPerimeter
php artisan make:perimeter EditorialPerimeter --hooks
php artisan make:control PostControl --model=Post --perimeters=ClientPerimeter --perimeters=EditorialPerimeter
php artisan make:control CommentControl --parent=post

make:control

Writes a control into app/Access/Controls.

OptionEffect
--model, -mThe model of the control: --model=Post for App\Models\Post, or a fully qualified class such as --model='Domain\Blog\Post'. Without it, the model is named after the control: App\Models\Post for PostControl.
--perimeters, -pA perimeter class of app/Access/Perimeters, repeatable. The control gets an allowed(), should() and query() callback for each one, which refuse everything until you write them, except the callbacks of the hooks that the class overrides.
--parentA belongsTo relation of the model, repeatable: writes a ThroughParent entry for it.
  • The command refuses, and writes nothing, when the model is not an Eloquent model class.
  • The perimeters are listed as loose perimeters, which add up: group the levels of a hierarchy in Levels::of() yourself.
  • A perimeter class whose constructor requires arguments, or is not public, is left out with a warning: list it in the control with its named constructor.
  • The control declares no boundary: add a boundary() method when the model needs one.

See Controls.

make:perimeter

Writes a perimeter class into app/Access/Perimeters.

  • Without option, the class is empty: its rules are the callbacks declared in the control.
  • --hooks generates the protected hooks allows(), includes() and scope(), which refuse everything until you write them, for a rule shared by several controls. Remove includes() to check the rows in SQL.

See Perimeter classes.

Stubs

Publish the stubs to change what the commands write:

php artisan stub:publish
StubUsed by
stubs/control.stubmake:control
stubs/perimeter.plain.stubmake:perimeter
stubs/perimeter.hooks.stubmake:perimeter --hooks

A published stub replaces the one of the package. After an upgrade, publish them again with php artisan stub:publish --force, or apply the changes of the package to your copies.