Browse Source

Updated the documentation

master
Cédric Belin 7 months ago
parent
commit
912472843e
4 changed files with 4 additions and 4 deletions
  1. +1
    -1
      lib/server.php
  2. +1
    -1
      test/fast_transformer_test.js
  3. +1
    -1
      test/minifier_test.js
  4. +1
    -1
      test/safe_transformer_test.js

+ 1
- 1
lib/server.php View File

@@ -1 +1 @@
<?php declare(strict_types=1); namespace Gulp\PhpMinify; class Server { function handleError(int $severity, string $message, string $file = __FILE__, int $line = __LINE__): bool { assert(mb_strlen($file) > 0); assert($line > 0); if (error_reporting() & $severity) throw new \ErrorException($message, 0, $severity, $file, $line); return false; } function run(array $args = []): void { set_error_handler([$this, 'handleError']); try { $this->sendResponse($this->processRequest($args)); } catch (\Throwable $e) { $this->sendResponse($e->getMessage(), $e->getCode()); } } function sendResponse(string $body, int $status = 200): void { assert($status >= 100 && $status < 600); http_response_code($status); header('Content-Length: '.strlen($body)); header('Content-Type: text/plain; charset='.mb_internal_encoding()); echo $body; } private function processRequest(array $args): string { if (!isset($args['file']) || !mb_strlen($args['file'])) throw new \LogicException('Bad Request', 400); if (!is_file($args['file'])) throw new \RuntimeException('Not Found', 404); $output = php_strip_whitespace($args['file']); if (!mb_strlen($output)) throw new \RuntimeException('Internal Server Error', 500); return $output; } } (new Server)->run($_GET);
<?php declare(strict_types=1); namespace Gulp\PhpMinify; class Server { function handleError(int $severity, string $message, string $file = __FILE__, int $line = __LINE__): bool { assert(mb_strlen($file) > 0); assert($line > 0); if (error_reporting() & $severity) throw new \ErrorException($message, 0, $severity, $file, $line); return false; } function run(array $args = []): void { set_error_handler([$this, 'handleError']); try { $this->sendResponse($this->processRequest($args)); } catch (\Throwable $e) { $this->sendResponse($e->getMessage(), $e->getCode()); } } function sendResponse(string $body, int $status = 200): void { assert($status >= 100 && $status < 600); http_response_code($status); header('Content-Length: '.strlen($body)); header('Content-Type: text/plain; charset='.mb_internal_encoding()); echo $body; } private function processRequest(array $args): string { if (!isset($args['file']) || !mb_strlen($args['file'])) throw new \LogicException('Bad Request', 400); $file = new \SplFileInfo($args['file']); if (!$file->isReadable()) throw new \RuntimeException('Not Found', 404); $output = php_strip_whitespace($file->getPathname()); if (!mb_strlen($output)) throw new \RuntimeException('Internal Server Error', 500); return $output; } } (new Server)->run($_GET);

+ 1
- 1
test/fast_transformer_test.js View File

@@ -1,7 +1,7 @@
import {strict as assert} from 'assert';
import {FastTransformer} from '../lib/index.js';

/** Tests the features of the {@link FastTransformer} class. */
/** Tests the features of the `FastTransformer` class. */
describe('FastTransformer', function() {
this.retries(2);
this.timeout(30000);


+ 1
- 1
test/minifier_test.js View File

@@ -2,7 +2,7 @@ import {strict as assert} from 'assert';
import File from 'vinyl';
import {Minifier, TransformMode} from '../lib/index.js';

/** Tests the features of the {@link Minifier} class. */
/** Tests the features of the `Minifier` class. */
describe('Minifier', function() {
this.retries(3);
this.timeout(60000);


+ 1
- 1
test/safe_transformer_test.js View File

@@ -1,7 +1,7 @@
import {strict as assert} from 'assert';
import {SafeTransformer} from '../lib/index.js';

/** Tests the features of the {@link SafeTransformer} class. */
/** Tests the features of the `SafeTransformer` class. */
describe('SafeTransformer', function() {
this.retries(2);
this.timeout(30000);


Loading…
Cancel
Save