Download the PHP package netbull/doctrine-behaviors without Composer

On this page you can find all versions of the php package netbull/doctrine-behaviors. 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 doctrine-behaviors

It looks like the official repo is abandoned, so as a temporary fix this can be used. When this PR #430 is merged and a new version released, this repo can be removed.

Doctrine2 Behaviors

Build Status

This PHP >=7.0 library is a collection of traits and interfaces that add behaviors to Doctrine2 entities and repositories.

It currently handles:

This project is looking for maintainers

We realize we don't have so much time anymore to maintain this project as it should be maintained. Therefore we are looking for maintainers. Open an issue if you want to keep working on this.

Notice:

Some behaviors (translatable, timestampable, softDeletable, blameable, geocodable) need Doctrine subscribers in order to work. Make sure to activate them by reading the Subscribers section.

Installation

Configuration

By default, when integrated with Symfony, all subscribers are enabled (if you don't specify any configuration for the bundle). But you can enable behaviors you need in a whitelist manner:

Subscribers

If you use symfony2, you can easily register them in:

Add to AppKernel

You can also register them using doctrine2 api:

Usage

All you have to do is to define a Doctrine2 entity and use traits:

For some behaviors like tree, you can use repository traits:

Voila!

You now have a working Category that behaves like:

tree:

it is possible to use another identifier than id, simply override getNodeId and return your custom identifier (works great in combination with Sluggable)

translatable:

If you're working on a Category entity, the Translatable behavior expects a CategoryTranslation entity in the same folder of Category entity by default.

The default naming convention (or its customization via trait methods) avoids you to manually handle entity associations. It is handled automatically by the TranslationSubscriber.

In order to use the Translatable trait, you will have to create this CategoryTranslation entity.

The corresponding Category entity needs to use ORMBehaviors\Translatable\Translatable; and should only contain fields that you do not need to translate.

After updating the database, ie. with ./console doctrine:schema:update --force, you can now work on translations using translate or getTranslations methods.

Override

In case you prefer to use a different class name for the translation entity, or want to use a separate namespace, you have 2 ways :

If you want to define a custom translation entity class name globally : Override the trait Translatable and his method getTranslationEntityClass and the trait Translation and his method getTranslatableEntityClass in the translation entity. If you override one, you also need to override the other to return the inverse class.

Example: Let's say you want to create a sub namespace AppBundle\Entity\Translation to stock translations classes then put overrided traits in that folder.

If you use that way make sure you override trait parameters of DoctrineBehaviors :

If you want to define a custom translation entity class name just for a single translatable class : Override the trait method getTranslationEntityClass in the translatable entity and getTranslatableEntityClass in the translation entity. If you override one, you also need to override the other to return the inverse class.

guess the current locale

You can configure the way the subscriber guesses the current locale, by giving a callable as its first argument. This library provides a callable object (Knp\DoctrineBehaviors\ORM\Translatable\CurrentLocaleCallable) that returns the current locale using Symfony2.

proxy translations

An extra feature allows you to proxy translated fields of a translatable entity.

You can use it in the magic __call method of you translatable entity so that when you try to call getName (for example) it will return you the translated value of the name for current locale:

soft-deletable

timestampable

If you wish to change the doctrine type of the database fields that will be created for timestampable models you can set the following parameter like so:

datetimetz here is a useful one to use if you are working with a Postgres database, otherwise you may encounter some timezone issues. For more information on this see: http://doctrine-dbal.readthedocs.org/en/latest/reference/known-vendor-issues.html#datetime-datetimetz-and-time-types

The default type is datetime.

blameable

Blameable is able to track creators and updators of a given entity. A blameable callable is used to get the current user from your application.

In the case you are using a Doctrine Entity to represent your users, you can configure the subscriber to manage automatically the association between this user entity and your entites.

Using symfony2, all you have to do is to configure the DI parameter named %knp.doctrine_behaviors.blameable_subscriber.user_entity% with a fully qualified namespace, for example:

# app/config/config.yml
parameters:
    knp.doctrine_behaviors.blameable_subscriber.user_entity: AppBundle\Entity\User

Then, you can use it like that:

loggable

Loggable is able to track lifecycle modifications and log them using any third party log system. A loggable callable is used to get the logger from anywhere you want.

These messages are then passed to the configured callable. You can define your own, by passing another callable to the LoggableSubscriber:

If you're using symfony, you can also configure which callable to use:

// app/config/config.yml
parameters:
    knp.doctrine_behaviors.loggable_subscriber.logger_callable.class: Your\InvokableClass

geocodable

Geocodable Provides extensions to PostgreSQL platform in order to work with cube and earthdistance extensions.

It allows you to query entities based on geographical coordinates. It also provides an easy entry point to use 3rd party libraries like the excellent geocoder to transform addresses into latitude and longitude.

sluggable

Sluggable generates slugs (uniqueness is not guaranteed) for an entity. Will automatically generate on update/persist (you can disable the on update generation by overriding getRegenerateSlugOnUpdate to return false. You can also override the slug delimiter from the default hyphen by overriding getSlugDelimiter. Slug generation algo can be changed by overriding generateSlugValue. Use cases include SEO (i.e. URLs like http://example.com/post/3/introduction-to-php)

filterable:

Filterable can be used at the Repository level

It allows to simple filter our result

Joined filters example:

and repository:

Now we can filtering using:

callables

Callables are used by some subscribers like blameable and geocodable to fill information based on 3rd party system.

For example, the blameable callable can be any symfony2 service that implements __invoke method or any anonymous function, as soon as they return currently logged in user representation (which means everything, a User entity, a string, a username, ...). For an example of DI service that is invoked, look at the Knp\DoctrineBehaviors\ORM\Blameable\UserCallable class.

In the case of geocodable, you can set it as any service that implements __invoke or anonymous function that returns a Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point object.

Testing

Read the documentation for testing

Maintainers

KNPLabs is looking for maintainers (see why).

If you are interested, feel free to open a PR to ask to be added as a maintainer.

We’ll be glad to hear from you :)


All versions of doctrine-behaviors with dependencies

PHP Build Version
Package Version
Requires php Version ~7.0
doctrine/common Version >=2.2
behat/transliterator Version ~1.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 netbull/doctrine-behaviors contains the following files

Loading the files please wait ....