| @@ 16-78 (lines=63) @@ | ||
| 13 | * |
|
| 14 | * @package CloudControl\Cms\services |
|
| 15 | */ |
|
| 16 | class FileService |
|
| 17 | { |
|
| 18 | private static $instance; |
|
| 19 | /** |
|
| 20 | * @var Storage |
|
| 21 | */ |
|
| 22 | protected $storage; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * FileService constructor. |
|
| 26 | */ |
|
| 27 | protected function __construct() |
|
| 28 | {} |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @return FileService |
|
| 32 | */ |
|
| 33 | public static function getInstance() |
|
| 34 | { |
|
| 35 | if (!self::$instance instanceof FileService) { |
|
| 36 | self::$instance = new FileService(); |
|
| 37 | } |
|
| 38 | return self::$instance; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @param $filePath |
|
| 43 | * @return File |
|
| 44 | */ |
|
| 45 | public static function get($filePath) |
|
| 46 | { |
|
| 47 | $instance = self::getInstance(); |
|
| 48 | return $instance->getFileByPath($filePath); |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @return string |
|
| 53 | */ |
|
| 54 | public function __toString() |
|
| 55 | { |
|
| 56 | return print_r(self::$instance, true); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * @param $filePath |
|
| 61 | * @return File |
|
| 62 | */ |
|
| 63 | protected function getFileByPath($filePath) |
|
| 64 | { |
|
| 65 | $file = $this->storage->getFiles()->getFileByName($filePath); |
|
| 66 | return new File($file); |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @param Storage $storage |
|
| 71 | */ |
|
| 72 | public function init(Storage $storage) |
|
| 73 | { |
|
| 74 | $this->storage = $storage; |
|
| 75 | } |
|
| 76 | ||
| 77 | ||
| 78 | } |
|
| @@ 17-77 (lines=61) @@ | ||
| 14 | * Singleton |
|
| 15 | * @package CloudControl\Cms\services |
|
| 16 | */ |
|
| 17 | class ImageService |
|
| 18 | { |
|
| 19 | private static $instance; |
|
| 20 | /** |
|
| 21 | * @var Storage |
|
| 22 | */ |
|
| 23 | protected $storage; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * ImageService constructor. |
|
| 27 | */ |
|
| 28 | protected function __construct() |
|
| 29 | {} |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @return ImageService |
|
| 33 | */ |
|
| 34 | public static function getInstance() |
|
| 35 | { |
|
| 36 | if (!self::$instance instanceof ImageService) { |
|
| 37 | self::$instance = new ImageService(); |
|
| 38 | } |
|
| 39 | return self::$instance; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param $imagePath |
|
| 44 | * @return Image |
|
| 45 | */ |
|
| 46 | public static function get($imagePath) |
|
| 47 | { |
|
| 48 | $instance = self::getInstance(); |
|
| 49 | return $instance->getImageByPath($imagePath); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @return string |
|
| 54 | */ |
|
| 55 | public function __toString() |
|
| 56 | { |
|
| 57 | return print_r(self::$instance, true); |
|
| 58 | } |
|
| 59 | ||
| 60 | /** |
|
| 61 | * @param $imagePath |
|
| 62 | * @return Image |
|
| 63 | */ |
|
| 64 | protected function getImageByPath($imagePath) |
|
| 65 | { |
|
| 66 | $image = $this->storage->getImages()->getImageByName($imagePath); |
|
| 67 | return new Image($image); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @param Storage $storage |
|
| 72 | */ |
|
| 73 | public function init(Storage $storage) |
|
| 74 | { |
|
| 75 | $this->storage = $storage; |
|
| 76 | } |
|
| 77 | } |
|