Download the PHP package mikamatto/entity-targeting-bundle without Composer

On this page you can find all versions of the php package mikamatto/entity-targeting-bundle. 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 entity-targeting-bundle

EntityTargetingBundle

Overview

The EntityTargetingBundle is a flexible service designed to manage a set of entities based on specified criteria. This bundle is intentionally designed to be bare, allowing developers to provide the entities themselves, as well as any CRUD operations or actions to display and manage those entities. This approach maximizes decoupling and flexibility, enabling developers to tailor the service to their specific application needs.

For example, suppose you have a set of messages you want to display at the top of your main page, but in a selective way based on who is making the request. You may want to display a certain message to guests, perhaps to persuade them to join. Alternatively, you might want to show a completely different message to registered users who belong to a specific group, informing them about a promotion running just for them. Additionally, you may need to display another message to users who haven’t confirmed their details, indicating that their account may be closed if they don't do it.

By using this bundle, you can assign criteria to each message without writing extensive logic to handle each case. The logic for determining eligibility comes built-in and operates transparently, allowing you to focus on delivering relevant content to your users.

Features

Installation

To install the bundle, run the following command:

If you're using Symfony Flex, the bundle will be enabled automatically. Otherwise, you may need to manually enable it in your config/bundles.php:

Configuration

To configure the bundle, you need to set up the parameters in your config/packages/entity_targeting.yaml:

Example usage

Using the bundle is extremely simple:

Here's a basic example using a standard service class:

We can pass in any custom params which will be passed into the repository method getEntities().

Interfaces

CriteriaAwareInterface

The CriteriaAwareInterface is designed for entities that will be managed by the EntityTargetingBundle. Implementing this interface enables the bundle to determine the eligibility of each entity based on defined criteria.

CriteriaRepositoryInterface

The CriteriaRepositoryInterface allows for repository classes to be compatible with the EntityTargetingBundle. Any repository managing entities targeted by this bundle should implement this interface, ensuring the bundle can fetch entities based on criteria configurations seamlessly.

Any custom parameters can be passed into the $params array.

TargetCriteriaInterface

The TargetCriteriaInterface defines the structure for all criteria that can be applied to target entities based on specific parameters and conditions. Implementing this interface allows the creation of custom targeting logic by defining eligibility criteria and associating entities with a particular criterion.

Explanation of Methods

This interface enables the definition of reusable, custom criteria within the bundle, while still supporting native, configurable criteria like guests_only and user_roles.

Natively Available Criteria

This bundle provides some native criteria to handle common use cases out of the box. Each criterion has specific requirements for its parameters.

Guests Only Criterion

The guests_only criterion targets non-authenticated users (i.e., users who are not logged in).

User Roles Criterion

The user_roles criterion targets users based on their assigned roles, with an option to consider Symfony’s role hierarchy.

Define Your Own Custom Made Criteria

To create your own criteria, implement the TargetingCriterionInterface. Your custom criteria should define how to determine eligibility based on the entity and user context.

Example:

List Registered Criteria

In order to list all the available criteria (for example, for populating a selector with options), a service which returns an array of the objects tagged as app.targeting_criterion is available at Mikamatto\EntityTargetingBundle\Service\TargetingCriteriaProvider

The TargetingCriteriaProvider service enables you to retrieve a list of registered targeting criteria in a structured format, which is helpful for managing and displaying available criteria options within your application.

This service leverages the #[AutowireIterator] attribute to automatically inject all services tagged with app.targeting_criterion, making it easy to register and retrieve criteria dynamically.

Usage

To use this service, ensure that your criteria classes are tagged with app.targeting_criterion in the service configuration:

The listCriteria() method on TargetingCriteriaProvider returns all registered criteria as an array, with each criterion containing:

Example output:

This service provides a consistent and extensible way to manage and display all available targeting criteria within the application. By adding new criteria classes and tagging them with app.targeting_criterion, they will automatically be included in the output from listCriteria() without any additional configuration.

Example Usage

Suppose we create a Notification entity that implements the CriteriaAwareInterface to target specific users based on roles. Here’s a simple example of such an entity:

// Example of a CriterionAware entity targeting guests only:

Example of a CriterionAware entity targeting users with certain roles:

This design allows easy configuration of native or custom criteria in your application. Custom criteria can also be added by implementing the TargetCriteriaInterface and registering them with the bundle.

License

This bundle is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or suggestions.


All versions of entity-targeting-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
symfony/framework-bundle Version ^6.1|^7.0
symfony/dependency-injection Version ^6.1|^7.0
symfony/security-core Version ^6.1|^7.0
symfony/cache Version ^6.1|^7.0
doctrine/orm Version ^3.2
doctrine/doctrine-bundle Version ^2.8
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 mikamatto/entity-targeting-bundle contains the following files

Loading the files please wait ....