Giter Club home page Giter Club logo

accessiblebundle's Introduction

AccessibleBundle

SensioLabsInsight Dependency Status Latest Stable Version License

AccessibleBundle provides an Accessible integration for your Symfony projects. This will allow you to define your class behavior using powerful annotations.

Here is a (very) basic example:

class Customer
{
  use AutomatedBehaviorTrait;

  /**
   * @Access({Access::GET, Access::SET})
   * @Assert\Email
   */
  private $email;
}


$bob = new Customer();

$bob->setEmail('[email protected]');
$bob->getEmail(); // [email protected]
$bob->setEmail('not an email address'); // throws an InvalidArgumentException

Here the library is used to generate getters and setters, but it can also be used to manage constructors, attributes initialization, collections and associations between classes!

Suggestions and contributions are welcome!

Documentation

This file contains everything you will need to use this bundle. For details on the use of the library, see the Accessible page.

Installation

First add the bundle in your Composer dependencies:

composer require antares/accessible-bundle

Then, register the bundle in your kernel:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new Antares\Bundle\AccessibleBundle\AntaresAccessibleBundle()
    );
}

In order to be compatible with the PropertyAccess component you should also add the following lines in your configuration:

# app/config/config.yml
framework:
  property_access:
    magic_call: true

Configuration

The configuration of this bundle is quite simple, take a look:

# app/config/config.yml
antares_accessible:
    cache:
        enable: true # default: false
    constraints_validation:
        enable: false # default: true
        validate_initialize_values: true # default: %kernel.debug%

Note that you don't need to set the configuration as everything is already configured by default.

Here are the meanings of the configuration values:

  • cache.enable: Do you want a cache driver to be used?
  • constraints_validation.enable: Do you want your class setters to use constraints validation?
  • constraints_validation.validate_initialize_values: Do you want the @Initialize and @InitializeObject values to be validated?

Use a custom cache driver

By default, instances of Doctrine\Common\Cache\PhpFileCache are used. If you have APC enabled, you should replace the cache driver. You can do it like this:

# app/config/services.yml

parameters:
    antares_accessible.cache_driver.class: Doctrine\Common\Cache\ApcCache

services:
    antares_accessible.cache.driver:
        class: "%antares_accessible.cache_driver.class%"
    antares_accessible.annotations.cache_driver:
        class: "%antares_accessible.cache_driver.class%"
  • antares_accessible.cache.driver is the cache driver used by the library
  • antares_accessible.annotations.cache_driver is the cache driver used by the library's annotation reader

Use a custom annotations reader

You can use a custom annotations reader:

# app/config/services.yml

services:
    antares_accessible.annotations.reader:
        class: Doctrine\Common\Annotations\AnnotationReader

Use a custom validator

You can also use a custom constraints validator, for example, if your project already uses the validator service, you can use it also with this library like this:

# app/config/services.yml

services:
    antares_accessible.constraints_validation.validator: '@validator'

accessiblebundle's People

Contributors

antarestupin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

accessiblebundle's Issues

Unrecognized option "antares_accessible" under "framework" -symfony 2.2

Boss thanks alot for the awesome bundle but am having configuration error "Unrecognized option "antares_accessible" under "framework" and am using symfony 3.2
framework:
#esi: ~
translator: { fallbacks: ['%locale%', 'en'] }
secret: '%secret%'
router:
resource: '%kernel.root_dir%/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: '%locale%'
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
assets: ~
property_access:
magic_call: true
antares_accessible:
cache.enable: true # default: false
constraints_validation.enable: false # default: true
constraints_validation.validate_initialize_values: true # default: %kernel.debug%

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.