Download the PHP package ccmbenchmark/ting_bundle without Composer
On this page you can find all versions of the php package ccmbenchmark/ting_bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ccmbenchmark/ting_bundle
More information about ccmbenchmark/ting_bundle
Files in ccmbenchmark/ting_bundle
Package ting_bundle
Short Description Symfony bundle for ccmbenchmark/ting. Provides an interface to use a lightweight datamapper in symfony.
License Apache-2.0
Informations about the package ting_bundle
Installation
-
Require Ting Bundle with
- Load Bundles in AppKernel.php
Table of contents
- Configuration
- Main configuration
- About public properties
- Declare metadata with attributes
- Using Ting as a User Provider
- Declare a unique constraint
- Using Ting as a Value Resolver
Configuration
Main configuration
About public properties
Public properties can be used in your entities, however for PHP < 8.4, you should declare a setter to notify the property change.
PHP < 8.4:
For PHP >= 8.4, you may use a property hook instead. This hook will be bypassed by Ting for hydratation.
A note about uninitialized typed properties
- When persisting an entity with uninitialized typed property, the property will be ignored ; a default value must be defined in your database for this column to prevent a failure
- You cannot access an uninitialized typed property, PHP will trigger an error
Declare metadata with attributes
Attributes are provided to declare an entity. Relevant attributes are available in CCMBenchmark\TingBundle\Schema
.
Table
- Full name:
CCMBenchmark\TingBundle\Schema\Table
- This attribute must be added to your class, with all relevant options (table, connection, etc.).
Column
- Full name:
CCMBenchmark\TingBundle\Schema\Column
- This attribute must be added to every property mapped to the database. Serialization is inferred from the type, if available.
Full example
Using Ting as a User Provider
User providers (re)load users from a storage based on a "user identifier" (extract from symfony documentation).
Ting can be used as a User Provider, it's automatically registered by the bundle as the provider ting
. To do so, update your security configuration.
Your entity will have to implements the following interfaces: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface
(for password authenticated users) and Symfony\Component\Security\Core\User\UserInterface
(common to all kind of users).
It needs to implement __serialize
too.
Declare a Unique constraint in a table
If you use the component symfony/validator
, you may need to ensure that a value (or a combination of them) is unique in your table.
You can use the Constraint CCMBenchmark\TingBundle\Validator\Constraints\UniqueEntity
to do so. In can be used as an annotation, or as an attribute.
Example:
With that example you can assert, when creating a new user, that the email address is unique:
Using Ting as a Value Resolver
This bundle automatically registers a Value Resolver.
You can automatically map request parameters to entities:
- Declare a parameter in your route (i.e:
/api/users/{userId}
), using the property in your entity you'll use to fetch data (in this case:userId
) - Map it to your action parameters:
- Add it to your signature:
public function getUser(User $user)
- Update the route to do the mapping:
/api/users/{userId:user}
(in this case: theUser
havinguserId
matching the request will be fetched and injected to your action with the argument$user
)
- Add it to your signature:
For more advanced use cases, you can leverage:
- The Expression Language component
- The
CCMBenchmark\TingBundle\Attribute\MapEntity
attribute
Example:
All versions of ting_bundle with dependencies
ccmbenchmark/ting Version ^3.11
doctrine/cache Version ^1.10
symfony/validator Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/http-kernel Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/dependency-injection Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/config Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/stopwatch Version ^4.4 || ^5.0 || ^6.0 || ^7.0