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 | 7 | public function __construct($filename, $context, $forceExtension = false) |
|
51 | { |
||
52 | 7 | parent::__construct($filename); |
|
53 | |||
54 | 7 | $this->context = $context; |
|
55 | 7 | $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 | 7 | public function getContext() |
|
72 | { |
||
73 | 7 | return $this->context; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 2 | public function setDensity($density) |
|
80 | { |
||
81 | 2 | $this->density = $density; |
|
82 | |||
83 | 2 | return $this; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 5 | public function getDensity() |
|
90 | { |
||
91 | 5 | return $this->density; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | 5 | #[\ReturnTypeWillChange] |
|
98 | public function getExtension() |
||
99 | { |
||
100 | 5 | if ($this->forceExtension) { |
|
101 | return 'png'; |
||
102 | } |
||
103 | |||
104 | // Image pathname can be URL not only local file location |
||
105 | 5 | return pathinfo(parse_url($this->getPathname(), PHP_URL_PATH), PATHINFO_EXTENSION); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
106 | } |
||
107 | } |
||
108 |