| Conditions | 5 |
| Paths | 7 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function load($path) |
||
| 28 | { |
||
| 29 | if (false !== strpos($path, '../')) { |
||
| 30 | throw new Exception\InvalidArgumentException( |
||
| 31 | sprintf('Source image was searched with "%s" out side of the defined root path', $path) |
||
| 32 | ); |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($this->rootPath === null) { |
||
| 36 | $absolutePath = $path; |
||
| 37 | } else { |
||
| 38 | $absolutePath = $this->rootPath . '/' . ltrim($path, '/'); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (!file_exists($absolutePath)) { |
||
| 42 | throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $absolutePath)); |
||
| 43 | } |
||
| 44 | |||
| 45 | $contents = file_get_contents($absolutePath); |
||
| 46 | |||
| 47 | if (!function_exists('exif_imagetype')) { |
||
| 48 | return $contents; |
||
| 49 | } |
||
| 50 | |||
| 51 | $extension = pathinfo($absolutePath, PATHINFO_EXTENSION); |
||
| 52 | $mimeType = image_type_to_mime_type(exif_imagetype($absolutePath)); |
||
| 53 | |||
| 54 | return new Binary($contents, $mimeType, $extension); |
||
| 55 | } |
||
| 56 | } |
||
| 57 |