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\en_CA;
4
 
5
/**
6
 * Extend US class since most fields share the same format
7
 */
8
class Address extends \Faker\Provider\en_US\Address
9
{
10
    protected static $postcode = ['?#? #?#', '?#?-#?#', '?#?#?#'];
11
 
12
    protected static $postcodeLetters = ['A', 'B', 'C', 'E', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'V', 'X', 'Y'];
13
 
14
    protected static $province = [
15
        'Alberta',
16
        'British Columbia',
17
        'Manitoba',
18
        'New Brunswick', 'Newfoundland and Labrador', 'Northwest Territories', 'Nova Scotia', 'Nunavut',
19
        'Ontario',
20
        'Prince Edward Island',
21
        'Quebec',
22
        'Saskatchewan',
23
        'Yukon Territory',
24
    ];
25
 
26
    protected static $provinceAbbr = [
27
        'AB', 'BC', 'MB', 'NB', 'NL', 'NT', 'NS', 'NU', 'ON', 'PE', 'QC', 'SK', 'YT',
28
    ];
29
 
30
    protected static $addressFormats = [
31
        "{{streetAddress}}\n{{city}}, {{provinceAbbr}}  {{postcode}}",
32
    ];
33
 
34
    /**
35
     * @example 'Ontario'
36
     */
37
    public static function province()
38
    {
39
        return static::randomElement(static::$province);
40
    }
41
 
42
    /**
43
     * @example 'ON'
44
     */
45
    public static function provinceAbbr()
46
    {
47
        return static::randomElement(static::$provinceAbbr);
48
    }
49
 
50
    /**
51
     * Returns a postalcode-safe letter
52
     *
53
     * @example A1B 2C3
54
     */
55
    public static function randomPostcodeLetter()
56
    {
57
        return static::randomElement(static::$postcodeLetters);
58
    }
59
 
60
    /**
61
     * @example A1B 2C3
62
     */
63
    public static function postcode()
64
    {
65
        $string = static::randomElement(static::$postcode);
66
 
67
        $string = preg_replace_callback('/\#/u', [static::class,  'randomDigit'], $string);
68
        $string = preg_replace_callback('/\?/u', [static::class, 'randomPostcodeLetter'], $string);
69
 
70
        return static::toUpper($string);
71
    }
72
}