PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / spatie / image-optimizer / src / Image.php

Image.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at vendor/spatie/image-optimizer/src/Image.php

63 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Spatie\ImageOptimizer;
4
5 use InvalidArgumentException;
6
7 class Image
8 {
9 protected $pathToImage = '';
10 protected const ALLOWED_PROTOCOLS = ['file'];
11
12 protected const WINDOWS_LOCAL_FILENAME_REGEX = '/^[a-z]:(?:[\\\\\/]?(?:[\w\s!#()-]+|[\.]{1,2})+)*[\\\\\/]?/i';
13
14 public function __construct(string $pathToImage)
15 {
16 if (! $this->isProtocolAllowed($pathToImage)) {
17 throw new InvalidArgumentException(\sprintf('The output file scheme is not supported. Expected one of [\'%s\'].', \implode('\', \'', self::ALLOWED_PROTOCOLS)));
18 }
19
20 if (! file_exists($pathToImage)) {
21 throw new InvalidArgumentException("`{$pathToImage}` does not exist");
22 }
23
24 $this->pathToImage = $pathToImage;
25 }
26
27 public function mime(): string
28 {
29 return mime_content_type($this->pathToImage);
30 }
31
32 public function path(): string
33 {
34 return $this->pathToImage;
35 }
36
37 public function extension(): string
38 {
39 $extension = pathinfo($this->pathToImage, PATHINFO_EXTENSION);
40
41 return strtolower($extension);
42 }
43
44 protected function isProtocolAllowed($filename)
45 {
46 if (false === $parsedFilename = \parse_url($filename)) {
47 throw new InvalidArgumentException('The filename is not valid.');
48 }
49
50 $protocol = isset($parsedFilename['scheme']) ? \mb_strtolower($parsedFilename['scheme']) : 'file';
51
52 if (
53 \PHP_OS_FAMILY === 'Windows'
54 && \strlen($protocol) === 1
55 && \preg_match(self::WINDOWS_LOCAL_FILENAME_REGEX, $filename)
56 ) {
57 $protocol = 'file';
58 }
59
60 return \in_array($protocol, self::ALLOWED_PROTOCOLS, true);
61 }
62 }
63