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
use Faker\Calculator\Ean;
6
use Faker\Calculator\Isbn;
7
 
8
/**
9
 * @see http://en.wikipedia.org/wiki/EAN-13
10
 * @see http://en.wikipedia.org/wiki/ISBN
11
 */
12
class Barcode extends Base
13
{
14
    private function ean($length = 13)
15
    {
16
        $code = static::numerify(str_repeat('#', $length - 1));
17
 
18
        return $code . Ean::checksum($code);
19
    }
20
 
21
    /**
22
     * Utility function for computing EAN checksums
23
     *
24
     * @deprecated Use \Faker\Calculator\Ean::checksum() instead
25
     *
26
     * @param string $input
27
     *
28
     * @return int
29
     */
30
    protected static function eanChecksum($input)
31
    {
32
        return Ean::checksum($input);
33
    }
34
 
35
    /**
36
     * ISBN-10 check digit
37
     *
38
     * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits
39
     * @deprecated Use \Faker\Calculator\Isbn::checksum() instead
40
     *
41
     * @param string $input ISBN without check-digit
42
     *
43
     * @throws \LengthException When wrong input length passed
44
     *
45
     * @return string
46
     */
47
    protected static function isbnChecksum($input)
48
    {
49
        return Isbn::checksum($input);
50
    }
51
 
52
    /**
53
     * Get a random EAN13 barcode.
54
     *
55
     * @return string
56
     *
57
     * @example '4006381333931'
58
     */
59
    public function ean13()
60
    {
61
        return $this->ean(13);
62
    }
63
 
64
    /**
65
     * Get a random EAN8 barcode.
66
     *
67
     * @return string
68
     *
69
     * @example '73513537'
70
     */
71
    public function ean8()
72
    {
73
        return $this->ean(8);
74
    }
75
 
76
    /**
77
     * Get a random ISBN-10 code
78
     *
79
     * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
80
     *
81
     * @return string
82
     *
83
     * @example '4881416324'
84
     */
85
    public function isbn10()
86
    {
87
        $code = static::numerify(str_repeat('#', 9));
88
 
89
        return $code . Isbn::checksum($code);
90
    }
91
 
92
    /**
93
     * Get a random ISBN-13 code
94
     *
95
     * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
96
     *
97
     * @return string
98
     *
99
     * @example '9790404436093'
100
     */
101
    public function isbn13()
102
    {
103
        $code = '97' . self::numberBetween(8, 9) . static::numerify(str_repeat('#', 9));
104
 
105
        return $code . Ean::checksum($code);
106
    }
107
}