-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFakerServiceProvider.php
46 lines (40 loc) · 1.13 KB
/
FakerServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace EmanueleMinotto\FakerServiceProvider;
use Faker\Factory;
use Silex\Application;
use Silex\ServiceProviderInterface;
/**
* A Faker service provider for Silex 1.
*
* @author Emanuele Minotto <[email protected]>
*
* @link http://silex.sensiolabs.org/doc/providers.html#creating-a-provider
*/
class FakerServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['faker'] = null;
$app['faker.providers'] = [];
}
/**
* {@inheritdoc}
*/
public function boot(Application $app)
{
// generator instance
$app['faker'] = $app->share(function ($app) {
return Factory::create($app['locale']);
});
// third-party providers
$providers = array_filter((array) $app['faker.providers'], function ($provider) {
return class_exists($provider) && is_subclass_of($provider, 'Faker\\Provider\\Base');
});
foreach ($providers as $provider) {
$app['faker']->addProvider(new $provider($app['faker']));
}
}
}