#FakerinoBundle
The FakerinoBundle provides integration of Fakerino into the Symfony2 framework. This bundle also include a Fakerino Twig extension.
More information in the official documentation.
###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:
"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
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(),
// ...
}
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
<?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')
);
}
}
{# Resources/view/Demo/my_fakerino_demo.html.twig #}
Hello Mr {{fake('surname')}}
//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.
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