-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory_Service_Provider.php
More file actions
60 lines (50 loc) · 1.25 KB
/
Copy pathFactory_Service_Provider.php
File metadata and controls
60 lines (50 loc) · 1.25 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Factory_Service_Provider class file.
*
* @package Mantle
*/
// phpcs:ignoreFile: WordPressVIPMinimum.Variables.VariableAnalysis.StaticInsideClosure
namespace Mantle\Database;
use Faker\Factory;
use Faker\Generator as FakerGenerator;
use Mantle\Faker\Faker_Provider;
use Mantle\Support\Service_Provider;
/**
* Database Factory
*/
class Factory_Service_Provider extends Service_Provider {
/**
* The array of resolved Faker instances.
*
* @var \Faker\Generator[]
*/
protected static $fakers = [];
/**
* Register any application services.
*/
public function register(): void {
$this->add_command( Console\Seed_Command::class );
$this->register_mantle_factory();
}
/**
* Register the Mantle factory instance in the container.
*
* @return void
*/
protected function register_mantle_factory() {
$this->app->singleton(
FakerGenerator::class,
function ( $app, $parameters ) {
$locale = config( 'app.faker_locale', Factory::DEFAULT_LOCALE );
if ( ! isset( static::$fakers[ $locale ] ) ) {
static::$fakers[ $locale ] = Factory::create( $locale );
static::$fakers[ $locale ]->addProvider(
new Faker_Provider( static::$fakers[ $locale ] )
);
}
return static::$fakers[ $locale ];
}
);
}
}