Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Faker\Provider;
4
 
5
class Person extends Base
6
{
7
    public const GENDER_MALE = 'male';
8
    public const GENDER_FEMALE = 'female';
9
 
10
    protected static $titleFormat = [
11
        '{{titleMale}}',
12
        '{{titleFemale}}',
13
    ];
14
 
15
    protected static $firstNameFormat = [
16
        '{{firstNameMale}}',
17
        '{{firstNameFemale}}',
18
    ];
19
 
20
    protected static $maleNameFormats = [
21
        '{{firstNameMale}} {{lastName}}',
22
    ];
23
 
24
    protected static $femaleNameFormats = [
25
        '{{firstNameFemale}} {{lastName}}',
26
    ];
27
 
28
    protected static $firstNameMale = [
29
        'John',
30
    ];
31
 
32
    protected static $firstNameFemale = [
33
        'Jane',
34
    ];
35
 
36
    protected static $lastName = ['Doe'];
37
 
38
    protected static $titleMale = ['Mr.', 'Dr.', 'Prof.'];
39
 
40
    protected static $titleFemale = ['Mrs.', 'Ms.', 'Miss', 'Dr.', 'Prof.'];
41
 
42
    /**
43
     * @param string|null $gender 'male', 'female' or null for any
44
     *
45
     * @return string
46
     *
47
     * @example 'John Doe'
48
     */
49
    public function name($gender = null)
50
    {
51
        if ($gender === static::GENDER_MALE) {
52
            $format = static::randomElement(static::$maleNameFormats);
53
        } elseif ($gender === static::GENDER_FEMALE) {
54
            $format = static::randomElement(static::$femaleNameFormats);
55
        } else {
56
            $format = static::randomElement(array_merge(static::$maleNameFormats, static::$femaleNameFormats));
57
        }
58
 
59
        return $this->generator->parse($format);
60
    }
61
 
62
    /**
63
     * @param string|null $gender 'male', 'female' or null for any
64
     *
65
     * @return string
66
     *
67
     * @example 'John'
68
     */
69
    public function firstName($gender = null)
70
    {
71
        if ($gender === static::GENDER_MALE) {
72
            return static::firstNameMale();
73
        }
74
 
75
        if ($gender === static::GENDER_FEMALE) {
76
            return static::firstNameFemale();
77
        }
78
 
79
        return $this->generator->parse(static::randomElement(static::$firstNameFormat));
80
    }
81
 
82
    /**
83
     * @return string
84
     */
85
    public static function firstNameMale()
86
    {
87
        return static::randomElement(static::$firstNameMale);
88
    }
89
 
90
    /**
91
     * @return string
92
     */
93
    public static function firstNameFemale()
94
    {
95
        return static::randomElement(static::$firstNameFemale);
96
    }
97
 
98
    /**
99
     * @example 'Doe'
100
     *
101
     * @return string
102
     */
103
    public function lastName()
104
    {
105
        return static::randomElement(static::$lastName);
106
    }
107
 
108
    /**
109
     * @example 'Mrs.'
110
     *
111
     * @param string|null $gender 'male', 'female' or null for any
112
     *
113
     * @return string
114
     */
115
    public function title($gender = null)
116
    {
117
        if ($gender === static::GENDER_MALE) {
118
            return static::titleMale();
119
        }
120
 
121
        if ($gender === static::GENDER_FEMALE) {
122
            return static::titleFemale();
123
        }
124
 
125
        return $this->generator->parse(static::randomElement(static::$titleFormat));
126
    }
127
 
128
    /**
129
     * @example 'Mr.'
130
     *
131
     * @return string
132
     */
133
    public static function titleMale()
134
    {
135
        return static::randomElement(static::$titleMale);
136
    }
137
 
138
    /**
139
     * @example 'Mrs.'
140
     *
141
     * @return string
142
     */
143
    public static function titleFemale()
144
    {
145
        return static::randomElement(static::$titleFemale);
146
    }
147
}