You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB

11 years ago
  1. <?php
  2. abstract class Image extends File
  3. {
  4. public $width;
  5. public $height;
  6. public $type;
  7. public $size;
  8. public $original_filename;
  9. /**
  10. * @var ImageVariant[]
  11. */
  12. public $variants = array();
  13. protected static $max_width;
  14. protected static $max_height;
  15. protected static $sizes = array();
  16. protected static $watermarks = array();
  17. public static function getClassName()
  18. {
  19. return get_called_class();
  20. }
  21. /**
  22. * @param $class string|StdClass
  23. * @throws ErrorException
  24. */
  25. public static function checkSubClass($class)
  26. {
  27. if (!self::getIsSubClass($class)) {
  28. throw new ErrorException('Class "' . $class . '" mast be extend of "Image".');
  29. }
  30. }
  31. /**
  32. * @param $class string|StdClass
  33. * @return bool
  34. */
  35. public static function getIsSubClass($class)
  36. {
  37. $parent_class = get_parent_class($class);
  38. if ($parent_class == __CLASS__) {
  39. return true;
  40. }
  41. if (get_parent_class($parent_class)) {
  42. return self::getIsSubClass($parent_class);
  43. }
  44. return false;
  45. }
  46. public static function getSizes()
  47. {
  48. return static::$sizes;
  49. }
  50. public static function getWatermark($size)
  51. {
  52. return (isset(static::$watermarks[$size])) ? static::$watermarks[$size] : false;
  53. }
  54. public static function getMaxWidth()
  55. {
  56. return static::$max_width;
  57. }
  58. public static function getMaxHeight()
  59. {
  60. return static::$max_height;
  61. }
  62. /**
  63. * @param $size
  64. * @param $force_create
  65. * @return ImageVariant
  66. */
  67. public function getVariant($size, $force_create = false)
  68. {
  69. return parent::getImageVariant($size, $force_create);
  70. }
  71. }