Download the PHP package nexara/api-platform-voter without Composer

On this page you can find all versions of the php package nexara/api-platform-voter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package api-platform-voter

Nexara API Platform Voter

Packagist Version Packagist Downloads License

A Symfony bundle that enforces consistent voter-based authorization for API Platform 3 resources.

Features

Core Features

Advanced Features (v0.3+)

Requirements

Installation

The bundle will be automatically registered in config/bundles.php.

Quick Start

1. Mark Your Resource as Protected

Add the #[Secured] attribute to your API Platform resource:

2. Create a Voter

Use the maker command to generate a voter:

Or create one manually with 3 configuration modes (v0.3+):

Mode 1: Auto-Configuration (Recommended)

Mode 2: Fluent Builder (Modern)

Mode 3: Manual (Backward Compatible)

3. That's It!

Your API Platform resource is now protected by the voter. All CRUD operations will be automatically checked.

Operation Mapping

The bundle automatically maps API Platform operations to voter attributes:

Operation HTTP Method Voter Attribute Voter Method Subject
Collection GET GET /articles article:list canList() null
Collection POST POST /articles article:create canCreate() New object
Item GET GET /articles/{id} article:read canRead($object) Object
Item PUT/PATCH PUT /articles/{id} article:update canUpdate($new, $previous) [$new, $previous]
Item DELETE DELETE /articles/{id} article:delete canDelete($object) Object
Custom operation POST /articles/{id}/publish article:publish canPublish($object, $previous) Object or [$new, $previous]

Custom Operations

For custom operations, implement a method following the naming convention can{OperationName}:

Voter Configuration Modes (v0.3+)

The unified CrudVoter supports 3 configuration modes:

1. Auto-Configuration (Zero Config)

2. Fluent Builder (Modern API)

3. Manual Configuration (Backward Compatible)

Migration from v0.2.x: See VOTER_MIGRATION_GUIDE.md

Configuration

Create config/packages/nexara_api_platform_voter.yaml:

Attribute Options

#[Secured] Parameters

Advanced Usage

Accessing the User

Inject Symfony's Security service to access the current user:

Comparing Previous and New Objects

For UPDATE operations, you receive both the new and previous state:

Multiple Resource Classes

A single voter can handle multiple resource classes:

GraphQL Support

For GraphQL APIs, use GraphQLCrudVoter with field-level authorization:

Multi-Tenancy

For multi-tenant applications, use TenantAwareVoterTrait:

Debug & Troubleshooting

Visualize voter decision chains:

Enable debug mode in configuration:

Testing

Testing Your Voters

The bundle provides powerful testing utilities with full role hierarchy support:

Using VoterTestTrait

Using SecurityBuilder

Using VoterTestCase

Running Tests

The bundle includes a comprehensive test suite:

Console Commands

Validate Voter Implementations

Validates:

Analyze Migration from Native Security

Provides:

Quality Assurance

This bundle maintains high code quality standards:

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details.

Security

If you discover a security vulnerability, please review our Security Policy.

License

This bundle is released under the MIT License.

Credits

Developed and maintained by Nexara s.r.o.

Support


All versions of api-platform-voter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
symfony/framework-bundle Version ^6.4 || ^7.0
symfony/security-bundle Version ^6.4 || ^7.0
symfony/cache Version ^6.4 || ^7.0
psr/cache Version ^3.0
api-platform/core Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nexara/api-platform-voter contains the following files

Loading the files please wait ...