Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dpobel/frontendperformanceboost
base: 061d591370
...
head fork: dpobel/frontendperformanceboost
compare: 8a51ffc355
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
135 classes/fepclioptimizer.php
@@ -7,30 +7,127 @@
class fepCliOptimizer
{
+ /**
+ * The setting containing the environement variables to set
+ */
+ const ENV_SETTING = 'Environment';
+
+ /**
+ * The setting containing the command to execute
+ */
+ const COMMAND_SETTING = 'Command';
+
+
+ /**
+ * The eZINI object corresponding to ezjscore.ini
+ *
+ * @var eZINI
+ */
+ protected $ini;
+
+ /**
+ * The section in the ini file containing the setting
+ *
+ * @var string
+ */
+ protected $section;
+
+ /**
+ * The original code size
+ * @see fepCliOptimizer::report()
+ *
+ * @var int
+ */
+ protected $originalCodeSize = 0;
+
+ /**
+ * The optimized code size
+ * @see fepCliOptimizer::report()
+ *
+ * @var int
+ */
+ protected $optimizedCodeSize = 0;
+
+
+ /**
+ * The constructor
+ *
+ * @param eZINI $ini
+ * @param string $section
+ */
+ public function __construct( eZINI $ini, $section )
+ {
+ $this->ini = $ini;
+ $this->section = $section;
+ }
+
+ /**
+ * Returns the name of the debug settings for this optimizer
+ * @see fepCliOptimizer::report() and debug.ini.append.php
+ *
+ * @return string
+ */
+ protected function getDebugSettings()
+ {
+ return strtolower( get_class( $this ) );
+ }
+
+ /**
+ * Returns the command to execute
+ *
+ * @return string
+ */
+ protected function getCommand()
+ {
+ return $this->ini->variable( $this->section, self::COMMAND_SETTING );
+ }
+
+ /**
+ * Returns the environment variables to set while executing the command. If
+ * not variables is set, returns null
+ * @see http://fr.php.net/proc_open
+ *
+ * @return array|null
+ */
+ protected function getEnvironmentVariables()
+ {
+ if ( !$this->ini->hasVariable( $this->section, self::ENV_SETTING ) )
+ {
+ return null;
+ }
+ $env = $this->ini->variable( $this->section, self::ENV_SETTING );
+ if ( empty( $env ) )
+ {
+ return null;
+ }
+ return $env;
+ }
/**
- * Executes the $command, writes the content of $code on the standard
+ * Executes the command, writes the content of $code on the standard
* input of the process and returns the standard output.
- *
- * @param string $command
- * @param string $code
- * @param int $level
+ *
+ * @param string $code
+ * @param int $level
* @return string
- * @throw Exception if the command does not return 0 or if the process can
+ * @throw Exception if the command does not return 0 or if the process can
* not be launched.
*/
- protected static function execute( $command, $code, $level = 2 )
+ public function execute( $code, $level = 2 )
{
+ $this->originalCodeSize = strlen( $code );
$originalSize = strlen( $code );
$pipes = array();
$process = proc_open(
- $command,
+ $this->getCommand(),
array(
0 => array( 'pipe', 'r' ),
1 => array( 'pipe', 'w' ),
2 => array( 'pipe', 'w' )
),
- $pipes
+ $pipes,
+ null,
+ $this->getEnvironmentVariables()
);
if ( !is_resource( $process ) )
{
@@ -55,9 +152,29 @@ protected static function execute( $command, $code, $level = 2 )
{
throw new Exception( 'Returned value is not 0: ' . $return );
}
+ $this->optimizedCodeSize = strlen( $code );
+ $this->report();
return $code;
}
+ /**
+ * Generates a summary of this optimization if the DebugOutput is enabled
+ * if the corresponding conditional debug is enabled.
+ */
+ protected function report()
+ {
+ eZDebugSetting::writeDebug(
+ $this->getDebugSettings(),
+ 'Original size: ' . $this->originalCodeSize, __METHOD__
+ );
+ eZDebugSetting::writeDebug(
+ $this->getDebugSettings(),
+ 'Optimized size: ' . $this->optimizedCodeSize
+ . ' (' . round( $this->optimizedCodeSize * 100/$this->originalCodeSize, 1 ) . '%)',
+ __METHOD__
+ );
+ }
+
}
View
28 classes/fepclosurejavascriptoptimizer.php
@@ -8,42 +8,24 @@
class fepClosureJavaScriptOptimizer extends fepCliOptimizer
{
/**
- * setting to enable conditional debug
- * @see debug.ini.append.php
- */
- const DEBUG_SETTING = 'fep-closure-optimizer';
-
- /**
* Optimizes the JS string by using Google Closure compiler
*
* @param string $code
- * @param int $level
+ * @param int $level
* @return string
*/
public static function optimize( $code, $level = 2 )
{
+
eZDebug::accumulatorStart(
__METHOD__, 'Packer',
'Front end performance boost JS optimizer'
);
- $originalSize = strlen( $code );
- $ini = eZINI::instance( 'ezjscore.ini' );
- $command = $ini->variable( 'GoogleClosure', 'Command' );
- eZDebugSetting::writeDebug(
- self::DEBUG_SETTING, 'Running ' . $command, __METHOD__
- );
- $res = self::execute( $command, $code, $level );
- $optimizedSize = strlen( $res );
- eZDebugSetting::writeDebug(
- self::DEBUG_SETTING, 'Original size: ' . $originalSize, __METHOD__
- );
- eZDebugSetting::writeDebug(
- self::DEBUG_SETTING,
- 'Optimized size: ' . $optimizedSize
- . ' (' . round( $optimizedSize * 100/$originalSize, 1 ) . '%)',
- __METHOD__
+ $optimizer = new self(
+ eZINI::instance( 'ezjscore.ini' ), 'GoogleClosure'
);
+ $res = $optimizer->execute( $code, $level );
eZDebug::accumulatorStop( __METHOD__ );
return $res;
View
27 classes/fepyuicompressorjavascriptoptimizer.php
@@ -8,16 +8,10 @@
class fepYuiCompressorJavaScriptOptimizer extends fepCliOptimizer
{
/**
- * setting to enable conditional debug
- * @see debug.ini.append.php
- */
- const DEBUG_SETTING = 'fep-yuicompressor-optimizer';
-
- /**
* Optimizes the JS string by using Yui Compressor
*
* @param string $code
- * @param int $level
+ * @param int $level
* @return string
*/
public static function optimize( $code, $level = 2 )
@@ -26,24 +20,11 @@ public static function optimize( $code, $level = 2 )
__METHOD__, 'Packer',
'Front end performance boost JS optimizer'
);
- $originalSize = strlen( $code );
- $ini = eZINI::instance( 'ezjscore.ini' );
- $command = $ini->variable( 'YuiCompressor', 'Command' );
- eZDebugSetting::writeDebug(
- self::DEBUG_SETTING, 'Running ' . $command, __METHOD__
- );
- $res = self::execute( $command, $code, $level );
- $optimizedSize = strlen( $res );
- eZDebugSetting::writeDebug(
- self::DEBUG_SETTING, 'Original size: ' . $originalSize, __METHOD__
- );
- eZDebugSetting::writeDebug(
- self::DEBUG_SETTING,
- 'Optimized size: ' . $optimizedSize
- . ' (' . round( $optimizedSize * 100/$originalSize, 1 ) . '%)',
- __METHOD__
+ $optimizer = new self(
+ eZINI::instance( 'ezjscore.ini' ), 'YuiCompressor'
);
+ $res = $optimizer->execute( $code, $level );
eZDebug::accumulatorStop( __METHOD__ );
return $res;
View
2  extension.xml
@@ -34,7 +34,7 @@
<extension name="ezjscore" />
</extends>
<!--
- frontendperformanceboost is compatible with CssInlineImageOptimizer
+ make sure frontendperformanceboost is compatible with CssInlineImageOptimizer
since we reset the array ezjscore.ini/[eZJSCore]/CssInlineImageOptimizer
-->
<uses>
View
4 settings/debug.ini.append.php
@@ -1,7 +1,7 @@
<?php /*
[GeneralCondition]
-fep-closure-optimizer=disabled
-fep-yuicompressor-optimizer=disabled
+fepclosurejavascriptoptimizer=disabled
+fepyuicompressorjavascriptoptimizer=disabled
*/ ?>

No commit comments for this range

Something went wrong with that request. Please try again.