flyingcolours/common-bundle

Symfony Bundle with commonly used code

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 618

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 1

Type:symfony-bundle


README

Common Symfony classes used throughout the projects

Version Build Status Coverage Status

Installation

composer require flyingcolours/common-bundle "^0.2.0"

This version works with Symfony 4.3, for previous version please check previous versions.

Components

Content Negotiation and Template Resolver Listener

Symfony Event Listener which works out right response content type based on "Accept" header.

# app/config/services.yml

parameters:

    priorities: [ 'application/json', 'text/html' ]

services:
        
    listener.template.resolver:
        class: FlyingColours\CommonBundle\Listener\TemplateResolverListener
        arguments: [ "@sensio_framework_extra.view.guesser" ]
        tags:
            - { name: kernel.event_listener, event: kernel.controller, method: onKernelController }
    
    listener.content.negotiation:
        class: FlyingColours\CommonBundle\Listener\ContentNegotiationListener
        arguments:
            $priorities: "%priorities%"
        tags:
            - { name: kernel.event_listener, event: kernel.view, method: onKernelView }

Persistent Memcached

If you ever experienced problem described here then you want to use this class instead of default Memcached.

# app/config/services.yml

services:

    memcached:
        class: FlyingColours\CommonBundle\Service\PersistentMemcached
        arguments:
            persistent_id: "%session_prefix%"
        calls:
            - [ addServer, [ "%memcached_host%", "%memcached_port%" ]]

    session.handler.memcached:
        class:     Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
        arguments: [ "@memcached", { prefix: "%session_prefix%", expiretime: "%session_expire%" }]

CORS Listener

See this page for details

# app/config/services.yml

services:

    listener.cors.headers:
        class: FlyingColours\CommonBundle\Listener\CorsHeadersListener
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }

Also if you want to implement quick OPTIONS handler without creating special action or controller, you can add additional tag for kernel.request event.

# app/config/services.yml

services:

    listener.cors.headers:
        class: FlyingColours\CommonBundle\Listener\CorsHeadersListener
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 33 }

To use in memory cache just use it in same way as memcached implementation:

services:
    cache.in_memory:
        class: FlyingColours\CommonBundle\Service\InMemoryCache