PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.5
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.5
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / vendor / codeinwp / optimole-sdk / src / ValueObject / Position.php

Position.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 4.2.5, at vendor/codeinwp/optimole-sdk/src/ValueObject/Position.php

98 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 declare(strict_types=1);
4
5 /*
6 * This file is part of Optimole PHP SDK.
7 *
8 * (c) Optimole Team <friends@optimole.com>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
12 */
13
14 namespace Optimole\Sdk\ValueObject;
15
16 use Optimole\Sdk\Exception\InvalidArgumentException;
17
18 final class Position
19 {
20 /**
21 * Center.
22 */
23 public const CENTER = 'ce';
24
25 /**
26 * Right Edge.
27 */
28 public const EAST = 'ea';
29
30 /**
31 * Top edge.
32 */
33 public const NORTH = 'no';
34
35 /**
36 * Top left corner.
37 */
38 public const NORTH_EAST = 'nowe';
39
40 /**
41 * Top right corner.
42 */
43 public const NORTH_WEST = 'noea';
44
45 /**
46 * Bottom Edge.
47 */
48 public const SOUTH = 'so';
49
50 /**
51 * Bottom right corner.
52 */
53 public const SOUTH_EAST = 'soea';
54
55 /**
56 * Bottom left corner.
57 */
58 public const SOUTH_WEST = 'sowe';
59
60 /**
61 * Left edge.
62 */
63 public const WEST = 'we';
64
65 /**
66 * The position.
67 */
68 private string $position;
69
70 /**
71 * Constructor.
72 */
73 public function __construct(string $position)
74 {
75 if (!self::isValid($position)) {
76 throw new InvalidArgumentException(sprintf('Position "%s" is invalid.', $position));
77 }
78
79 $this->position = $position;
80 }
81
82 /**
83 * Convert the position to its string representation.
84 */
85 public function __toString(): string
86 {
87 return $this->position;
88 }
89
90 /**
91 * Validates if the given value is one of the defined position constants.
92 */
93 public static function isValid($value): bool
94 {
95 return in_array($value, (new \ReflectionClass(__CLASS__))->getConstants());
96 }
97 }
98