Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Changed namespace, added latest defer.js (1.1.12) #54

Merged
merged 1 commit into from
Dec 24, 2020
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.php_cs.cache
composer.phar
/node_modules/
/vendor/
/cache/
/.scannerwork
120 changes: 56 additions & 64 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@
* @copyright 2019 AppSeeds
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$header = <<<'EOF'
A PHP helper class to efficiently defer JavaScript for your website.
@@ -25,82 +23,75 @@ A PHP helper class to efficiently defer JavaScript for your website.
EOF;

$rules = [
'@PHP56Migration' => true,
'@PHP70Migration' => true,
'@PHP71Migration' => true,
'@Symfony' => true,
'@PSR2' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'fully_qualified_strict_types' => true,
'header_comment' => ['header' => $header, 'comment_type' => 'PHPDoc', 'location' => 'after_open', 'separate' => 'both'],
'heredoc_to_nowdoc' => true,
'increment_style' => ['style' => 'post'],
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'method_chaining_indentation' => true,
'multiline_comment_opening_closing' => true,
'native_function_invocation' => false,
'no_alternative_syntax' => true,
'no_blank_lines_before_namespace' => false,
'no_binary_string' => true,
'no_empty_phpdoc' => true,
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_internal_class' => true,
'php_unit_ordered_covers' => true,
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_separation' => false,
'phpdoc_summary' => false,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types_order' => true,
'return_assignment' => false,
'semicolon_after_instruction' => true,
'single_line_comment_style' => false,
'single_quote' => true,
'yoda_style' => false,
'blank_line_before_statement' => [
'@Symfony' => true,
'@PSR2' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'braces' => ['allow_single_line_closure' => true],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'fully_qualified_strict_types' => true,
'header_comment' => ['header' => $header, 'comment_type' => 'PHPDoc'],
'heredoc_to_nowdoc' => true,
'increment_style' => ['style' => 'post'],
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'method_chaining_indentation' => true,
'multiline_comment_opening_closing' => true,
'native_function_invocation' => false,
'no_alternative_syntax' => true,
'no_blank_lines_before_namespace' => false,
'no_binary_string' => true,
'no_empty_phpdoc' => true,
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_internal_class' => true,
'php_unit_ordered_covers' => true,
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_separation' => false,
'phpdoc_summary' => false,
'phpdoc_types_order' => true,
'return_assignment' => false,
'semicolon_after_instruction' => true,
'single_line_comment_style' => false,
'single_quote' => true,
'yoda_style' => false,
'blank_line_before_statement' => [
'statements' => [
'continue', 'declare', 'return', 'throw', 'try',
'declare', 'for', 'foreach', 'goto', 'if',
],
],
'no_extra_blank_lines' => [
'no_extra_blank_lines' => [
'tokens' => [
'continue', 'extra', 'return', 'throw', 'use',
'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block',
],
],
'braces' => [
'allow_single_line_closure' => true,
],
'binary_operator_spaces' => [
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'align_single_space',
'=' => 'align_single_space',
'=' => 'align_single_space_minimal',
'=>' => 'align_single_space_minimal',
],
],
];

$finder = Finder::create()
$finder = \PhpCsFixer\Finder::create()
->in(__DIR__)
->name('*.php')
->exclude('.idea')
@@ -110,7 +101,8 @@ $finder = Finder::create()
->ignoreDotFiles(true)
->ignoreVCS(true);

return Config::create()
return \PhpCsFixer\Config::create()
->setFinder($finder)
->setRules($rules)
->setUsingCache(true);
->setLineEnding("\n")
->setUsingCache(false);
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ composer require shinsenter/defer.php
require_once __DIR__ . '/vendor/shinsenter/defer.php/defer.php';

// Create a Defer object
$defer = new \shinsenter\Defer();
$defer = new \AppSeeds\Defer();

// Read HTML source from file
$html_source = file_get_contents('mypage.html');
@@ -65,7 +65,7 @@ require_once __DIR__ . '/vendor/shinsenter/defer.php/defer.php';
// Create a function for output optimization
function deferjs_optimization($html) {
// Create a Defer object
$defer = new \shinsenter\Defer();
$defer = new \AppSeeds\Defer();

// Then get the optimized output
return $defer->fromHtml($html)->toHtml();
@@ -91,7 +91,7 @@ ob_end_flush();
require_once __DIR__ . '/vendor/shinsenter/defer.php/defer.php';

// Create a Defer object
$defer = new \shinsenter\Defer();
$defer = new \AppSeeds\Defer();

// Library injection
$defer->append_defer_js = false;
@@ -145,7 +145,7 @@ In some regions, you may want to serve defer.js library locally due to [The Gene
require_once __DIR__ . '/vendor/shinsenter/defer.php/defer.php';

// Create a Defer object
$defer = new \shinsenter\Defer();
$defer = new \AppSeeds\Defer();
$defer->manually_add_deferjs = true;

// Then get the optimized output
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"autoload": {
"files": [],
"psr-4": {
"shinsenter\\": "src/"
"AppSeeds\\": "src/"
}
},
"authors": [
@@ -49,9 +49,7 @@
],
"scripts":
{
"css": "cleancss -o public/styles.min.css assets/styles.css",
"js": "uglifyjs --config-file=.uglifyjs -o public/helpers.min.js assets/helpers.js",
"helper": ["@css","@js"],
"helper": "npm run js && npm run css",
"fixer": "php-cs-fixer fix --show-progress=estimating --verbose",
"test": "php test/test.php"
},
@@ -69,5 +67,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"type": "library",
"license": "MIT"
"license": "MIT",
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17"
}
}
2,010 changes: 2,000 additions & 10 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion defer.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
$vendorDir = dirname(dirname($baseDir));
$autoload = '/autoload.php';

if (!class_exists('shinsenter\Defer')) {
if (!class_exists('AppSeeds\Defer')) {
if (file_exists($libDir . $autoload)) {
require_once $libDir . $autoload;
} elseif (file_exists($vendorDir . $autoload)) {
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"devDependencies": {
"clean-css-cli": "^4.3.0",
"uglify-js": "^3.12.3"
},
"scripts": {
"css": "cleancss -o public/styles.min.css assets/styles.css",
"js": "uglifyjs --config-file .uglifyjs -o public/helpers.min.js assets/helpers.js"
}
}
2 changes: 1 addition & 1 deletion src/Defer.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

class Defer extends DeferInterface
{
2 changes: 1 addition & 1 deletion src/DeferCache.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

class DeferCache
{
2 changes: 1 addition & 1 deletion src/DeferException.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

use Exception;

2 changes: 1 addition & 1 deletion src/DeferHttpRequest.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

class DeferHttpRequest
{
40 changes: 20 additions & 20 deletions src/DeferInterface.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

if (!defined('DEFER_JS_ROOT')) {
define('DEFER_JS_ROOT', dirname(__DIR__));
@@ -83,8 +83,8 @@ abstract class DeferInterface
const INLINE_CSS_URL = DEFER_JS_ROOT . '/public/styles.min.css';

// For splash screen
const SLASH_TEMPLATE = DEFER_SLASH_TEMPLATE;
const SLASH_HIDE_SCRIPT = DEFER_SLASH_HIDE_SCRIPT;
const SLASH_TEMPLATE = DEFER_SLASH_TEMPLATE;
const SLASH_HIDE_SCRIPT = DEFER_SLASH_HIDE_SCRIPT;

// Polyfill & library's fingerprint
const POLYFILL_URL = 'https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver';
@@ -94,23 +94,23 @@ abstract class DeferInterface
const SVG_PLACEHOLDER = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 %d %d'></svg>";

// Content tags
const AUDIO_TAG = 'audio';
const BR_TAG = 'br';
const BODY_TAG = 'body';
const EMBED_TAG = 'embed';
const FRAME_TAG = 'frame';
const HEAD_TAG = 'head';
const IFRAME_TAG = 'iframe';
const IMG_TAG = 'img';
const INPUT_TAG = 'input';
const LINK_TAG = 'link';
const META_TAG = 'meta';
const NOSCRIPT_TAG = 'noscript';
const PICTURE_TAG = 'picture';
const SCRIPT_TAG = 'script';
const SOURCE_TAG = 'source';
const STYLE_TAG = 'style';
const VIDEO_TAG = 'video';
const AUDIO_TAG = 'audio';
const BR_TAG = 'br';
const BODY_TAG = 'body';
const EMBED_TAG = 'embed';
const FRAME_TAG = 'frame';
const HEAD_TAG = 'head';
const IFRAME_TAG = 'iframe';
const IMG_TAG = 'img';
const INPUT_TAG = 'input';
const LINK_TAG = 'link';
const META_TAG = 'meta';
const NOSCRIPT_TAG = 'noscript';
const PICTURE_TAG = 'picture';
const SCRIPT_TAG = 'script';
const SOURCE_TAG = 'source';
const STYLE_TAG = 'style';
const VIDEO_TAG = 'video';

// LINK tag's rel attribute
const REL_DNSPREFETCH = 'dns-prefetch';
6 changes: 3 additions & 3 deletions src/DeferOptimizer.php
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

use AppSeeds\Helpers\JsMin;
use DOMElement;
use Exception;
use shinsenter\Helpers\JsMin;

trait DeferOptimizer
{
@@ -840,7 +840,7 @@ protected function addBackgroundColor($node)
$placeholder = 'background-color:hsl(' . rand(1, 360) . ',30%,96%);';
}

$style = (string) $node->getAttribute(static::ATTR_STYLE);
$style = (string) $node->getAttribute(static::ATTR_STYLE);
$node->setAttribute(static::ATTR_STYLE, $placeholder . $style);
}
}
42 changes: 21 additions & 21 deletions src/DeferOptions.php
Original file line number Diff line number Diff line change
@@ -11,34 +11,34 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

trait DeferOptions
{
public $options = [
// Debug optimized tags (instead of optimized HTML)
'debug_mode' => false,
'no_defer_parameter' => 'nodefer',
'debug_mode' => false,
'no_defer_parameter' => 'nodefer',

// Disable libxml errors and warnings
'hide_warnings' => true,
'hide_warnings' => true,

// manually add deferjs
'manually_add_deferjs' => false,
'manually_add_deferjs' => false,

// Library injection
'append_defer_js' => false,
'default_defer_time' => 10,
'append_defer_js' => false,
'default_defer_time' => 10,

// Splash screen
'custom_splash_screen' => '',
'custom_splash_screen' => '',

// Page optimizations
'enable_preloading' => true,
'enable_dns_prefetch' => true,
'fix_render_blocking' => true,
'minify_output_html' => true,
'add_missing_meta_tags' => true,
'enable_preloading' => true,
'enable_dns_prefetch' => true,
'fix_render_blocking' => true,
'minify_output_html' => true,
'add_missing_meta_tags' => true,

// Tag optimizations
'enable_defer_css' => true,
@@ -49,28 +49,28 @@ trait DeferOptions
'enable_defer_fallback' => true,

// Web-font optimizations
'defer_web_fonts' => true,
'web_fonts_patterns' => [
'defer_web_fonts' => true,
'web_fonts_patterns' => [
'(font-?awesome).*?\.css',
'fonts\.google(apis)?\.com',
'(gadget|popup|modal|icons)[^\/]*\.css',
'_debugbar.*stylesheets',
],

// Custom loader scripts
'loader_scripts' => [],
'loader_scripts' => [],

// Blacklist patterns
'do_not_optimize' => [
'do_not_optimize' => [
'document\.write\s*\(',
'(jquery([-_][\d\.]+)?(\.min)?\.js|jquery-core)',
],

// Content placeholders
'use_css_fadein_effects' => true,
'use_color_placeholder' => false,
'empty_gif' => '',
'empty_src' => 'about:blank',
'use_css_fadein_effects' => true,
'use_color_placeholder' => false,
'empty_gif' => '',
'empty_src' => 'about:blank',
];

protected $backup_options;
2 changes: 1 addition & 1 deletion src/DeferParser.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter;
namespace AppSeeds;

trait DeferParser
{
12 changes: 6 additions & 6 deletions src/Helpers/JsMin.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* @see https://github.com/shinsenter/defer.php/blob/develop/README.md
*/

namespace shinsenter\Helpers;
namespace AppSeeds\Helpers;

/*
* JsMin.php - modified PHP implementation of Douglas Crockford's JsMin.
@@ -81,11 +81,11 @@ class JsMin
const ACTION_DELETE_A = 2;
const ACTION_DELETE_A_B = 3;

protected $a = '';
protected $b = '';
protected $input = '';
protected $inputIndex = 0;
protected $inputLength = 0;
protected $a = '';
protected $b = '';
protected $input = '';
protected $inputIndex = 0;
protected $inputLength = 0;
protected $lookAhead;

protected $output = '';
2 changes: 1 addition & 1 deletion test/helpers.php
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ function debug()
}

if (!empty($msgs)) {
echo($text . implode("\n", $msgs)) . "\n";
echo ($text . implode("\n", $msgs)) . "\n";
}

$last_time = new DateTime();
2 changes: 1 addition & 1 deletion test/test.php
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@

// $_GET['nodefer'] = true;

$defer = new shinsenter\Defer();
$defer = new AppSeeds\Defer();

// Set test options
$defer->debug_mode = false;