ROLE_ADMIN says who someone is, a scope like users:write says what they can do. This aligns with modern OAuth2 and OpenAPI standards.
ScopeInterface
The contract for all scope objects.Methods
getName(): string: Returns the unique string identifier for the scope (e.g.,read:orders).getDescription(): ?string: Returns an optional human-readable description. This is used when generating OpenAPI documentation.
Scope Value Object
A standard implementation ofScopeInterface.
Usage
Why use Objects instead of Strings?
Using objects for scopes provides several benefits over simple strings:- Type Safety: You can type-hint
ScopeInterfacein your methods. - Metadata: You can attach descriptions, which are automatically included in your generated OpenAPI
securitydefinitions. - Extensibility: You can create custom scope classes that hold additional logic or metadata.
Defining Scopes on Routes
When defining aRoute, you use Scope objects within a SecurityRequirementObject.