diff --git a/File.class.php b/File.php similarity index 91% rename from File.class.php rename to File.php index f94e9b4..cbe4c57 100644 --- a/File.class.php +++ b/File.php @@ -38,13 +38,13 @@ abstract class File public function log($message) { - if (Config::get('LOGGING')) { + if (\Majestic\Config::get('LOGGING')) { if (is_null($this->logger)) { - $this->logger = Logger::getInstance(); + $this->logger = \Majestic\Logger\Logger::getInstance(); } $this->logger->log($message); } else { - $this->error_stream = Config::get('ErrorStream', 'php://stderr'); + $this->error_stream = \Majestic\Config::get('ErrorStream', 'php://stderr'); file_put_contents($this->error_stream, PHP_EOL . 'Log ' . '#' . __CLASS__ . ': ' . $message . PHP_EOL, FILE_APPEND); } } @@ -52,7 +52,7 @@ abstract class File /** * @param array|string|null $data * @return Image - * @throws ErrorException + * @throws \ErrorException */ public static function getInstance($data = null) { @@ -86,7 +86,7 @@ abstract class File * @var $this Image */ if (!array_key_exists($size, $this->variants)) { - $original_file_path = Config::get('PATH_WEB_ROOT') . '/' . $this->getWebName(); + $original_file_path = \Majestic\Config::get('PATH_WEB_ROOT') . '/' . $this->getWebName(); if ($force_create && $this->getIsNoEmpty() && file_exists($original_file_path)) { Upload::imageVariant($this, $size); } else { diff --git a/FileHelper.class.php b/FileHelper.php similarity index 100% rename from FileHelper.class.php rename to FileHelper.php diff --git a/Image.class.php b/Image.php similarity index 89% rename from Image.class.php rename to Image.php index 391ab88..4f9693b 100644 --- a/Image.class.php +++ b/Image.php @@ -29,18 +29,18 @@ abstract class Image extends File } /** - * @param $class string|StdClass - * @throws ErrorException + * @param $class string|\StdClass + * @throws \ErrorException */ public static function checkSubClass($class) { if (!self::getIsSubClass($class)) { - throw new ErrorException('Class "' . $class . '" mast be extend of "Image".'); + throw new \ErrorException('Class "' . $class . '" mast be extend of "Image".'); } } /** - * @param $class string|StdClass + * @param $class string|\StdClass * @return bool */ public static function getIsSubClass($class) diff --git a/ImageCollection.class.php b/ImageCollection.php similarity index 81% rename from ImageCollection.class.php rename to ImageCollection.php index 2cc9c43..8bf6e41 100644 --- a/ImageCollection.class.php +++ b/ImageCollection.php @@ -1,7 +1,7 @@ dir_image_cache : self::$dir_image_cache; - $greagwar_image->setCacheDir(Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $dir_image_cache); + $greagwar_image->setCacheDir(\Majestic\Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $dir_image_cache); return $greagwar_image; } public static function getFilePath($image) { - return Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $image->path . DIRECTORY_SEPARATOR . $image->filename; + return \Majestic\Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $image->path . DIRECTORY_SEPARATOR . $image->filename; } /** @@ -37,10 +37,10 @@ abstract class Upload * @var $image Image */ if (is_null($class) || $class == '') { - throw new ErrorException('Class not defined.'); + throw new \ErrorException('Class not defined.'); } if (!is_object($class) && !class_exists($class)) { - throw new ErrorException('Class "' . $class . '" not exists.'); + throw new \ErrorException('Class "' . $class . '" not exists.'); } Image::checkSubClass($class); if (isset($file['error']) && $file['error'] != 0) { @@ -62,7 +62,7 @@ abstract class Upload /** * @param $image Image * @param $size string @ex '1200x960' - * @param $greagwar_image GreagwarImage @deprecated + * @param $greagwar_image \GreagwarImage @deprecated */ public static function imageVariant($image, $size, $greagwar_image = null) { @@ -70,21 +70,21 @@ abstract class Upload $image_variant = new ImageVariant(); $size_parts = explode('x', $size); self::saveImage($image_variant, self::getFilePath($image), $size_parts[0] ? : null, $size_parts[1] ? : null); - if (Config::get('PYTHON_PIL_PASTE') && + if (\Majestic\Config::get('PYTHON_PIL_PASTE') && method_exists($image, 'getWatermark') && $image->getWatermark($size) ) { - $script_file_path = Config::get('PYTHON_PIL_PASTE')->script_file_path; - $pil_options = (isset(Config::get('PYTHON_PIL_PASTE')->pil_options) && Config::get('PYTHON_PIL_PASTE')->pil_options) ? ' ' . implode(' ', Config::get('PYTHON_PIL_PASTE')->pil_options) : ''; + $script_file_path = \Majestic\Config::get('PYTHON_PIL_PASTE')->script_file_path; + $pil_options = (isset(\Majestic\Config::get('PYTHON_PIL_PASTE')->pil_options) && \Majestic\Config::get('PYTHON_PIL_PASTE')->pil_options) ? ' ' . implode(' ', \Majestic\Config::get('PYTHON_PIL_PASTE')->pil_options) : ''; ob_start(); $code = null; $command = $script_file_path . $pil_options . ' ' . self::getFilePath($image_variant) - . ' ' . Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size); + . ' ' . \Majestic\Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size); passthru('exec 2>&1; ' . $command, $code); if ($code !== 0) { - throw new ErrorException('Command PYTHON_PIL_PASTE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); + throw new \ErrorException('Command PYTHON_PIL_PASTE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); } ob_end_clean(); } @@ -94,7 +94,7 @@ abstract class Upload /** * @param $image ImageVariant|Image - * @param $tmp_file_path string|GreagwarImage + * @param $tmp_file_path string|\GreagwarImage * @param null $width * @param null $height * TODO: Возможно, стоит искоренить GreagwarImage @@ -126,9 +126,9 @@ abstract class Upload copy($tmp_file_path, $file_path); } } else { - if (Config::get('PYTHON_PIL_RESIZE')) { - $script_file_path = Config::get( 'PYTHON_PIL_RESIZE' )->script_file_path; - $pil_options = isset( Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) ? ' ' . implode( ' ', Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) : ''; + if (\Majestic\Config::get('PYTHON_PIL_RESIZE')) { + $script_file_path = \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->script_file_path; + $pil_options = isset( \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) ? ' ' . implode( ' ', \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) : ''; // ob_start(); $code = null; $command = $script_file_path @@ -140,7 +140,7 @@ abstract class Upload ob_start(); passthru( 'exec 2>&1; ' . $command, $code ); if ($code !== 0) { - throw new ErrorException('Command PYTHON_PIL_RESIZE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); + throw new \ErrorException('Command PYTHON_PIL_RESIZE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); } ob_end_clean(); } else { @@ -175,7 +175,7 @@ abstract class Upload $output = shell_exec("convert {$file_path} -brightness-contrast {$value} {$file_path} 2>&1"); if (isset($output) && $output) { if (class_exists('ErrorMessage')) { - ErrorMessage::log($output); + \ErrorMessage::log($output); } } } diff --git a/UploadHelper.class.php b/UploadHelper.php similarity index 87% rename from UploadHelper.class.php rename to UploadHelper.php index 3832c96..decd3e6 100644 --- a/UploadHelper.class.php +++ b/UploadHelper.php @@ -7,12 +7,12 @@ abstract class UploadHelper * @param $proportion * @param $file_path * @return bool - * @throws ErrorException + * @throws \ErrorException */ public static function imageCompareAspectRatio($proportion, $file_path) { if (!(file_exists($file_path) && is_readable($file_path) && is_file($file_path))) { - throw new ErrorException('Unable to read file "' . $file_path . '".'); + throw new \ErrorException('Unable to read file "' . $file_path . '".'); } if ($imagesize = getimagesize($file_path)) { $proprtion_parts = explode('x', $proportion); @@ -27,12 +27,12 @@ abstract class UploadHelper * @param $size * @param $file_path * @return bool - * @throws ErrorException + * @throws \ErrorException */ public static function imageCompareSize($size, $file_path) { if (!(file_exists($file_path) && is_readable($file_path) && is_file($file_path))) { - throw new ErrorException('Unable to read file "' . $file_path . '".'); + throw new \ErrorException('Unable to read file "' . $file_path . '".'); } if ($imagesize = getimagesize($file_path)) { $size_parts = explode('x', $size); diff --git a/composer.json b/composer.json index 99b4eab..a33271b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "dimti/Image", - "version": "0.1.3", + "version": "0.1.4", "description": "Image lib", "autoload": { "psr-4": {