fakerino/symfony-fakerino

Fake data generator symfony bundle

Installs: 51

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 1

Type:symfony-bundle

0.1.1 2015-06-16 20:23 UTC

This package is not auto-updated.

Last update: 2024-11-09 16:53:26 UTC


README

#FakerinoBundle

Latest Stable Version Travis Ci License

The FakerinoBundle provides integration of Fakerino into the Symfony2 framework.
This bundle also include a Fakerino Twig extension.

More information in the official documentation.

Installation

###1. Install symfony-fakerino Add the following dependency to your projects composer.json file:

    "require": {
        "fakerino/symfony-fakerino": "~0.1"
    }

###2. Install the ODS data sample (optional but suggested) Install the ODS data sample using one of the below options:

2.1 Install and update automatically adding a script to your composer.json (suggested way):
  "scripts": {
        "post-install-cmd": "vendor/fakerino/fakerino/build/ods vendor/fakerino/fakerino/data",
        "post-update-cmd": "vendor/fakerino/fakerino/build/ods vendor/fakerino/fakerino/data"
    }

NOTE: add as first script to be executed. #####2.2 Run the command manually (after the fakerino composer installation):

$ vendor/fakerino/fakerino/build/ods vendor/fakerino/fakerino/data

3. Initializing the bundle

To initialize the bundle, you'll need to add it in your app/AppKernel.php.

public function registerBundles()
{
    // ...
  $bundles = array(
           new Fakerino\Bundle\FakerinoBundle\FakerinoBundle(),
    // ...
}

4. Configuration (optional)

If the configuration is not set, Fakerino will use the default values.
Configuration example config.yml:

fakerino:
    config:
        locale: en-GB
        fake:
            fakeMale:
              - titlemale
              - nameMale
              - surname
            fakeFemale:
              - titlefemale
              - namefemale
              - surname
        database:
            dbname: mydb
            user: username
            password: password
            host: localhost
            driver: pdo_mysql

Example

Controller

<?php
namespace Acme\DemoBundle\Controller;

use Fakerino\Core\FakeDataFactory;
use Symfony\Component\HttpFoundation\Response;
use Twig_Environment;

class HelloController
{
    public function __construct(FakeDataFactory $fakerino, Twig_Environment $twig)
    {
        $this->fakerino = $fakerino;
        $this->twig = $twig;
    }

    public function helloAction()
    {
        $person = $this->fakerino->fake('fakeFemale');
        $duty = $this->fakerino->fakeTemplate('<p>Remeber the appointment with {{ surname }} in {{ country }}</p>');

        return new Response('<html><body> Hello '.$person.'!'.$duty.'</body></html>');
    }

    public function twigAction()
    {
        return new Response(
            $this->twig->render('AcmeDemoBundle:Demo:my_fakerino_demo.html.twig')
        );
    }
}  

Twig file

{# Resources/view/Demo/my_fakerino_demo.html.twig #}

Hello Mr {{fake('surname')}}

Service configuration

//config/services.xml
<service id="hello_service" class="Acme\DemoBundle\Controller\HelloController">
    <argument type="service" id="fakerino" />
    <argument type="service" id="twig" />
</service>

For more information about the service configuration and the controller used in this example, please read about:
Service Container and Controller as a Service on the official Symfony documentation.

Outputs

Output of helloAction(), will changes at every page refresh:

Hello Ms Adeline Douglas !

Remeber the appointment with Watts in Cyprus

Output of twigAction(), will changes at every page refresh:

Hello Mr Wallace