Download the PHP package runopencode/traitor-bundle without Composer

On this page you can find all versions of the php package runopencode/traitor-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 traitor-bundle

Traitor bundle

Packagist Scrutinizer Code Quality Build Status Code Coverage Build Status

SensioLabsInsight

*Symfony service container compiler pass which defines additional setter injection of services/parameters/values based on used traits in service classes.

Before you start using this bundle please read following article (if you have not already): http://symfony.com/doc/current/components/dependency_injection/types.html, it is imperative that you fully understand types of injection because this bundle promotes setter injection (which is considered as non-preferred method when comparing to constructor injection) in order to get higher level of productivity.

We would like you to read carefully this "readme" file as well and understand what this bundle does, with all its benefits and drawbacks, before using it, especially if you are not experienced developer with proficiency in computer science.

How this bundle works?

In one sentence: If your class is registered as service in service container and if that class uses traits like, per example, \Psr\Log\LoggerAwareTrait, this bundle will redefine your service adding a method call in its definition, injecting appropriate service, as per example, a logger.

So, instead of defining setter injection for your service, it is sufficient enough to use some kind of provided, or user defined, *AwareTrait and this bundle will provide appropriate injection (if it is configured properly, of course).

Why would you consider such method of defining setter injection?

Consider that you already have defined services in your service container which requires additional injection of, per example, services that will be used in your code.

Per example:

class MyService 
{
    public function __construct() {  }
}

And your services.yml:

services:
    my_service
        class: MyService

In order to inject, per example, a logger service into your service, you would have to modify your class, with, per example, a constructor injection:

class MyService 
{
    protected $logger

    public function __construct(\Psr\Log\LoggerInterface $logger) 
    {
        $this->logger = $logger;
    }
}        

And you would have to modify services.yml as well:

services:
    my_service
        class: MyService
        argumets: [ '@logger' ]

In example above, a good practice of service injection is exercised. However, sometimes, this good practice can not be satisfied within a reasonable amount of time and effort.

Traitor bundle in the rescue

Instead of doing as in example stated above, how about to just use some trait, and some kind of "magic" will to the rest of it? Our previous example would be as easy as doing the following:

class MyService 
{
    use \Psr\Log\LoggerAwareTrait;

    public function __construct() {  }
}

And this is just good enough - you just use appropriate trait, and compiler pass within this bundle will provide your service class with appropriate setter injection.

Motivation for developing this bundle

Best example, which was a motivation to build this kind of bundle, is GeneratorBundle: https://github.com/symfony2admingenerator/GeneratorBundle.

Namely, GeneratorBundle generates all CRUD bits for you, which includes a form types as well, which are (as per courtesy of authors of this awesome library) already properly registered in service container with tag form.type, and, as good as it is, sometimes can be an issue to inject additional required services, which happens quite often.

In order to do such injection, you would have to identify the name of service under which your form type has been registered, and modify that service by either overriding its definition via configuration file in, per example, app/config/services.yml (thanks to configuration cascade) or through compiler pass.

However, we have figure out that either of that approaches just takes too much time when we worked on project in which there were app. 50 form types in need of injection of additional services.

So, we needed a solution that will handle this more elegantly, with less effort.

There are other similar solutions out there as well, like JMSDiExtraBundle which allows you to achieve the same via annotations.

Why this bundle should be used carefully?

Having in mind all dangers stated above, this bundle can help you a lot in certain use cases, giving you a flexibility and productivity at the cost of good coding practice, and you should use this bundle in such occurrences.

Please note that this bundle should not be used for redistributable Symfony bundles, for obvious reasons.

Configuration

Require this bundle via composer, composer require runopencode/traitor-bundle and register it in your AppKernel.php:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [

            ...

            new RunOpenCode\Bundle\Traitor\TraitorBundle()

            ...

        ];
        return $bundles;
    }

}

and configure it, example of full configuration is given bellow:

runopencode_traitor:
    use_common_traits: false             
    inject:
        'Full\Qualified\Trait\Namespace':
            - [ 'setterMethodName', [ '@service_name', 'or_parameter_value' ]]
            - { method: 'otherSetterMethodName', arguments: [ '@service_name', 'or_parameter_value' ] }
    filters:
        tags: [ 'form.type', 'other_tag' ]
        namespaces: [ '\Namespace\Prefix1', 'Namespace\Prefix2' ]
    exclude:
        tags: [ 'tag.to.exclude' ]
        services: [ 'my.service.to_exclude' ]
        classes: [ '\Exclude\Services\ThatUsesThisClass', '\Or\Uses\ThisClass' ]
        namespaces: [ '\Exclude\AllServices\WithClasses\WithinThisNamespace\' ]

XML configuration

You can, of course, configure bundle via XML configuration (preferred way), and in doing so, there is XML Schema file available to you for validation and intelli sense for your configration.

Provided common traits

As previously mentioned, this bundle provides you with common traits which you may or may not use, however, if you are using them, make sure that in your configuration set use_common_traits to true, and inject map will be appended with following definitions as well:

'Symfony\Component\DependencyInjection\ContainerAwareTrait': ['setContainer', ['@service_container']]
'Psr\Log\LoggerAwareTrait': ['setLogger', ['@logger']]
'RunOpenCode\Bundle\Traitor\Traits\DoctrineAwareTrait': ['setDoctrine', ['@doctrine']]
'RunOpenCode\Bundle\Traitor\Traits\EventDispatcherAwareTrait': ['setEventDispatcher', ['@event_dispatcher']]
'RunOpenCode\Bundle\Traitor\Traits\FilesystemAwareTrait': ['setFilesystem', ['@filesystem']]
'RunOpenCode\Bundle\Traitor\Traits\KernelAwareTrait': ['setKernel', ['@kernel']]
'RunOpenCode\Bundle\Traitor\Traits\MailerAwareInterface': ['setMailer', ['@mailer']]
'RunOpenCode\Bundle\Traitor\Traits\PropertyAccessorAwareTrait': ['setPropertyAccessor', ['@property_accessor']]
'RunOpenCode\Bundle\Traitor\Traits\RequestStackAwareTrait': ['setRequestStack', ['@request_stack']]
'RunOpenCode\Bundle\Traitor\Traits\RouterAwareTrait': ['setRouter', ['@router']]
'RunOpenCode\Bundle\Traitor\Traits\AuthorizationCheckerAwareTrait': ['setAuthorizationChecker', ['@security.authorization_checker']]
'RunOpenCode\Bundle\Traitor\Traits\SessionAwareTrait': ['setSession', ['@session']]
'RunOpenCode\Bundle\Traitor\Traits\TwigAwareTrait': ['setTwig', ['@twig']]
'RunOpenCode\Bundle\Traitor\Traits\TranslatorAwareTrait': ['setTranslator', ['@translator']]
'RunOpenCode\Bundle\Traitor\Traits\ValidatorAwareTrait': ['setValidator', ['@validator']]
'RunOpenCode\Bundle\Traitor\Traits\TokenStorageAwareTrait': ['setTokenStorage', ['@security.token_storage']]

In general, common traits will help you to boost your productivity when injecting following services:


All versions of traitor-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
symfony/framework-bundle Version ~2.8|~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 runopencode/traitor-bundle contains the following files

Loading the files please wait ....