Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude([
'runtime',
'vendor',
])
->in(__DIR__ . '/lib');

$rules = [
'@Symfony' => true,
'phpdoc_inline_tag' => false,
'single_import_per_statement' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'phpdoc_no_package' => false,
];

if (class_exists('\\PhpCsFixer\\Fixer\\ControlStructure\\YodaStyleFixer')) {
$rules['yoda_style'] = false;
}

return PhpCsFixer\Config::create()->setRules($rules)->setFinder($finder);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"symfony/console": "^3.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16@dev"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 6 additions & 8 deletions lib/Handler/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ interface HandlerInterface
*/
public function canHandleFile($file);

/**
* Записывает файл в очередь на обработку.
*
* @param string $file Путь к файлу
*
* @return void
*/
public function queueFile($file);
/**
* Записывает файл в очередь на обработку.
*
* @param string $file Путь к файлу
*/
public function queueFile($file);

/**
* Обрабатывает файлы в очереди.
Expand Down
6 changes: 5 additions & 1 deletion lib/Handler/HandlerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class HandlerProcessor
/** @var array Стандартные обработчики */
private $defaultHandlers = [
'image' => '\\Dumkaaa\\BxOptimize\\Handler\\ImageHandler',
'css' => '\\Dumkaaa\\BxOptimize\\Handler\\CssHandler',
'css' => '\\Dumkaaa\\BxOptimize\\Handler\\CssHandler',
];

/** @var array Включенные обработчики */
Expand All @@ -17,6 +17,8 @@ class HandlerProcessor
* Включаем либо обработчики из переданного набора, либо все стандартные.
*
* @param array $handlers
*
* @throws \Exception
*/
public function __construct(array $handlers)
{
Expand All @@ -29,6 +31,8 @@ public function __construct(array $handlers)
* Включает обработчики из массива.
*
* @param array $handlers
*
* @throws \Exception
*/
public function enableHandlers(array $handlers)
{
Expand Down
88 changes: 42 additions & 46 deletions lib/Handler/HandlerTools.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,68 @@
<?php


namespace Dumkaaa\BxOptimize\Handler;


class HandlerTools
{
public static $handlers = [
"win" => [
"gif" => "gifsicle.exe",
"png" => "optipng.exe",
"jpg" => "jpegtran.exe",
"jpeg" => "jpegtran.exe",
"pngquant" => "pngquant.exe",
"webp" => "cwebp.exe",
'win' => [
'gif' => 'gifsicle.exe',
'png' => 'optipng.exe',
'jpg' => 'jpegtran.exe',
'jpeg' => 'jpegtran.exe',
'pngquant' => 'pngquant.exe',
'webp' => 'cwebp.exe',
],
"darwin" => [
"gif" => "gifsicle-mac",
"png" => "optipng-mac",
"jpg" => "jpegtran-mac",
"jpeg" => "jpegtran-mac",
"pngquant" => "pngquant-mac",
"webp" => "cwebp-mac9",
'darwin' => [
'gif' => 'gifsicle-mac',
'png' => 'optipng-mac',
'jpg' => 'jpegtran-mac',
'jpeg' => 'jpegtran-mac',
'pngquant' => 'pngquant-mac',
'webp' => 'cwebp-mac9',
],
"sunos" => [
"gif" => "gifsicle-sol",
"png" => "optipng-sol",
"jpg" => "jpegtran-sol",
"jpeg" => "jpegtran-sol",
"pngquant" => "pngquant-sol",
"webp" => "cwebp-sol",
'sunos' => [
'gif' => 'gifsicle-sol',
'png' => 'optipng-sol',
'jpg' => 'jpegtran-sol',
'jpeg' => 'jpegtran-sol',
'pngquant' => 'pngquant-sol',
'webp' => 'cwebp-sol',
],
"freebsd" =>[
"gif" => "gifsicle-fbsd",
"png" => "optipng-fbsd",
"jpg" => "jpegtran-fbsd",
"jpeg" => "jpegtran-fbsd",
"pngquant" => "pngquant-fbsd",
"webp" => "cwebp-fbsd",
'freebsd' => [
'gif' => 'gifsicle-fbsd',
'png' => 'optipng-fbsd',
'jpg' => 'jpegtran-fbsd',
'jpeg' => 'jpegtran-fbsd',
'pngquant' => 'pngquant-fbsd',
'webp' => 'cwebp-fbsd',
],
"linux" => [
"gif" => "gifsicle-linux",
"png" => "optipng-linux",
"jpg" => "jpegtran-linux",
"jpeg" => "jpegtran-linux",
"pngquant" => "pngquant-linux",
"webp" => "cwebp-linux",
'linux' => [
'gif' => 'gifsicle-linux',
'png' => 'optipng-linux',
'jpg' => 'jpegtran-linux',
'jpeg' => 'jpegtran-linux',
'pngquant' => 'pngquant-linux',
'webp' => 'cwebp-linux',
],
];

public static function getBinaryHandler($type) {

public static function getBinaryHandler($type)
{
$handlers = self::getBinaryHandlers();

$handlerPath = dirname(dirname(__DIR__)) . '/bin/';

return isset($handlers[$type]) ? $handlerPath . $handlers[$type] : false;

}

public static function getBinaryHandlers() {

public static function getBinaryHandlers()
{
$os = strtolower(PHP_OS);
if (substr($os, 0, 3) == "win") {
$os = "win";
if (substr($os, 0, 3) == 'win') {
$os = 'win';
}

return isset(self::$handlers[$os]) ? self::$handlers[$os] : [];
}

}
}
9 changes: 3 additions & 6 deletions lib/Handler/ImageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,24 @@ public function handleQueue()
}

foreach ($this->files as $file) {

$command = false;

$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));

if ($handlers[$ext]) {

switch ($ext) {
case 'png':
$command = sprintf($this->args[$ext], escapeshellarg($file));
break;
case 'jpg':
case 'jpeg':
$command = sprintf($this->args[$ext], escapeshellarg($file), escapeshellarg($file . ".original"));
$command = sprintf($this->args[$ext], escapeshellarg($file), escapeshellarg($file . '.original'));
break;
}
if (!file_exists($file . ".original") && $command) {
copy($file, $file . ".original");
if (!file_exists($file . '.original') && $command) {
copy($file, $file . '.original');
exec($handlers[$ext] . $command);
}

} else {
echo "Не найден бинарный обработчик для файла: $file\n";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class Installer
{
protected static $tools = [
'gif' => 'gifsicle',
'png' => 'optipng',
'jpg' => 'jpegtran',
'gif' => 'gifsicle',
'png' => 'optipng',
'jpg' => 'jpegtran',
'pngquant' => 'pngquant',
];

Expand Down