Correct for use Majestic namespace
This commit is contained in:
@ -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 {
|
@ -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)
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace dimti\Image;
|
||||
|
||||
abstract class ImageCollection extends ArrayIterator
|
||||
abstract class ImageCollection extends \ArrayIterator
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
@ -11,7 +11,7 @@ abstract class ImageCollection extends ArrayIterator
|
||||
/**
|
||||
* @param array|null $data
|
||||
* @param mixed $owner
|
||||
* @throws ErrorException
|
||||
* @throws \ErrorException
|
||||
* TODO: рефакторить этот метод
|
||||
*/
|
||||
public function __construct($data = null, $owner = null)
|
||||
@ -25,17 +25,17 @@ abstract class ImageCollection extends ArrayIterator
|
||||
if (!is_array($data)) {
|
||||
$data = json_decode($data, true);
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
ErrorMessage::log('Unable to convert json-string to array.');
|
||||
\ErrorMessage::log('Unable to convert json-string to array.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!isset($data['order']) || !isset($data['files'])) {
|
||||
ErrorMessage::log('Incorrect format for create ImageCollection.');
|
||||
\ErrorMessage::log('Incorrect format for create ImageCollection.');
|
||||
return;
|
||||
}
|
||||
foreach ($data['order'] as $original_filename) {
|
||||
if (!isset($data['files'][$original_filename])) {
|
||||
ErrorMessage::log('Unable to fetch image "' . $original_filename . '" from ImageCollection.');
|
||||
\ErrorMessage::log('Unable to fetch image "' . $original_filename . '" from ImageCollection.');
|
||||
continue;
|
||||
}
|
||||
$image_instance = $class::getInstance($data['files'][$original_filename]);
|
@ -9,7 +9,7 @@ class ImageVariant extends File
|
||||
public $size;
|
||||
|
||||
/**
|
||||
* @param $class string|StdClass
|
||||
* @param $class string|\StdClass
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getIsClass($class)
|
@ -11,16 +11,16 @@ abstract class Upload
|
||||
|
||||
public static function &getGreagwarImage($file_path)
|
||||
{
|
||||
$greagwar_image = new GreagwarImage($file_path);
|
||||
$config_upload = Config::get('Upload');
|
||||
$greagwar_image = new \GreagwarImage($file_path);
|
||||
$config_upload = \Majestic\Config::get('Upload');
|
||||
$dir_image_cache = $config_upload ? $config_upload->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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dimti/Image",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"description": "Image lib",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
Reference in New Issue
Block a user