Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation\Testing;
4
 
5
use Faker\Factory;
6
use Faker\Generator;
7
 
8
trait WithFaker
9
{
10
    /**
11
     * The Faker instance.
12
     *
13
     * @var \Faker\Generator
14
     */
15
    protected $faker;
16
 
17
    /**
18
     * Setup up the Faker instance.
19
     *
20
     * @return void
21
     */
22
    protected function setUpFaker()
23
    {
24
        $this->faker = $this->makeFaker();
25
    }
26
 
27
    /**
28
     * Get the default Faker instance for a given locale.
29
     *
30
     * @param  string|null  $locale
31
     * @return \Faker\Generator
32
     */
33
    protected function faker($locale = null)
34
    {
35
        return is_null($locale) ? $this->faker : $this->makeFaker($locale);
36
    }
37
 
38
    /**
39
     * Create a Faker instance for the given locale.
40
     *
41
     * @param  string|null  $locale
42
     * @return \Faker\Generator
43
     */
44
    protected function makeFaker($locale = null)
45
    {
46
        $locale ??= config('app.faker_locale', Factory::DEFAULT_LOCALE);
47
 
48
        if (isset($this->app) && $this->app->bound(Generator::class)) {
49
            return $this->app->make(Generator::class, ['locale' => $locale]);
50
        }
51
 
52
        return Factory::create($locale);
53
    }
54
}