Completed
Push — master ( fd34d5...86b52b )
by Eymen
8s
created

Image::getContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Passbook package.
5
 *
6
 * (c) Eymen Gunay <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Passbook\Pass;
13
14
/**
15
 * Image
16
 *
17
 * Must be one of the following values:
18
 * background - The image displayed as the background of the front of the pass.
19
 * footer - The image displayed on the front of the pass near the barcode.
20
 * icon - The pass’s icon. This is displayed in notifications and in emails that have a pass attached, and on the lock screen.
21
 * logo - The image displayed on the front of the pass in the top left.
22
 * strip - The image displayed behind the primary fields on the front of the pass.
23
 * thumbnail - An additional image displayed on the front of the pass. For example, on a membership card, the thumbnail could be used to a picture of the cardholder.
24
 *
25
 * @author Eymen Gunay <[email protected]>
26
 */
27
class Image extends \SplFileObject implements ImageInterface
28
{
29
    /**
30
     * Image context. Must be one of the following values:
31
     * thumbnail, icon, background, logo, footer, strip
32
     * @var string
33
     */
34
    protected $context;
35
36
    /**
37
     * All of the pass’s images are loaded using standard UIImage image-loading methods.
38
     * This means, for example, the file name of high resolution versions of the image ends with @2x.png/@3x.png.
39
     * @var integer
40
     */
41
    protected $density;
42
43
    /**
44
     * Force "png" extension in case of dynamic conversion of the file, i.e. by CDN.
45
     *
46
     * @var bool
47
     */
48
    protected $forceExtension;
49
50
    public function __construct($filename, $context, $forceExtension = false)
51
    {
52
        parent::__construct($filename);
53
54
        $this->context = $context;
55
        $this->forceExtension = $forceExtension;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function setContext($context)
62
    {
63
        $this->context = $context;
64
65
        return $this;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getContext()
72
    {
73
        return $this->context;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function setDensity($density)
80
    {
81
        $this->density = $density;
82
83
        return $this;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function getDensity()
90
    {
91
        return $this->density;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function getExtension()
98
    {
99
        if ($this->forceExtension) {
100
            return 'png';
101
        }
102
103
        // Image pathname can be URL not only local file location
104
        return pathinfo(parse_url($this->getPathname(), PHP_URL_PATH), PATHINFO_EXTENSION);
105
    }
106
}
107