| 1 | <?php |
||
| 22 | class Box |
||
| 23 | { |
||
| 24 | public $topX; |
||
| 25 | public $topY; |
||
| 26 | public $bottomX; |
||
| 27 | public $bottomY; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * __construct |
||
| 31 | * |
||
| 32 | * Create a box from a string description. |
||
| 33 | * |
||
| 34 | * @access public |
||
| 35 | * @param string $description |
||
| 36 | */ |
||
| 37 | public function __construct($description) |
||
| 38 | { |
||
| 39 | $description = trim($description, ' ()'); |
||
| 40 | $regex = '/([0-9e\-+\.]+), *([0-9e\-+\.]+) *\), *\( *([0-9e\-+\.]+), *([0-9e\-+\.]+)/'; |
||
| 41 | |||
| 42 | if (!preg_match($regex, $description, $matches)) { |
||
| 43 | throw new \InvalidArgumentException( |
||
| 44 | sprintf( |
||
| 45 | "Could not parse box representation '%s'.", |
||
| 46 | $description |
||
| 47 | ) |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | $this->topX = (float) $matches[1]; |
||
| 52 | $this->topY = (float) $matches[2]; |
||
| 53 | $this->bottomX = (float) $matches[3]; |
||
| 54 | $this->bottomY = (float) $matches[4]; |
||
| 55 | |||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * __toString |
||
| 60 | * |
||
| 61 | * Return a string representation of Box. |
||
| 62 | * |
||
| 63 | * @access public |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function __toString() |
||
| 76 | } |
||
| 77 |