ScriptReorganizer
[ class tree: ScriptReorganizer ] [ index: ScriptReorganizer ] [ all elements ]

Source for file Pack.php

Documentation is available at Pack.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * ScriptReorganizer Strategy :: Pack
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This library is free software; you can redistribute it and/or modify it
  11.  * under the terms of the GNU Lesser General Public License as published by the Free
  12.  * Software Foundation; either version 2.1 of the License, or (at your option) any
  13.  * later version.
  14.  *
  15.  * @category   Tools
  16.  * @package    ScriptReorganizer
  17.  * @subpackage Strategy
  18.  * @author     Stefano F. Rausch <stefano@rausch-e.net>
  19.  * @copyright  2005 Stefano F. Rausch <stefano@rausch-e.net>
  20.  * @license    http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  21.  * @version    SVN: $Id: Pack.php 33 2005-11-06 22:05:46Z stefanorausch $
  22.  * @link       http://pear.php.net/package/ScriptReorganizer
  23.  * @filesource
  24.  */
  25.  
  26. /**
  27.  * Implements <kbd>ScriptReorganizer_Strategy</kbd>
  28.  */
  29. require_once 'ScriptReorganizer/Strategy.php';
  30.  
  31. /**
  32.  * Uses <kbd>ScriptReorganizer_Strategy_Quiet</kbd>
  33.  */
  34. require_once 'ScriptReorganizer/Strategy/Quiet.php';
  35.  
  36. /**
  37.  * Advanced strategy
  38.  *
  39.  * Reorganizes scripts by applying the {@link ScriptReorganizer_Strategy_Quiet Quiet}
  40.  * strategy as well as by replacing (1) EOLs according to the pack mode - see below
  41.  * (2) two or more consecutive spaces and/or tabs with a single space char.
  42.  *
  43.  * Multiple consecutive EOLs are replaced either as defined (1) in the default mode
  44.  * by a single EOL or (2) in the extreme mode by a single space char.
  45.  *
  46.  * <b>Warning</b>: With ScriptReorganizer optimized source code the tracking of
  47.  * report error messages of the PHP Engine will definitively get cumbersome, when the
  48.  * extreme mode of the Pack strategy is applied. Reason being: all statements are
  49.  * organized on one line only. It is crucial to throughout test again - not only unit
  50.  * test - the code after optimizing it and before building a release to deploy.
  51.  *
  52.  * If the extreme pack mode strategy is used for packaging, a non-ScriptReorganized
  53.  * source code tree should be shipped together with the optimized one, to enable
  54.  * third parties to track down undiscoverd bugs.
  55.  *
  56.  * @category   Tools
  57.  * @package    ScriptReorganizer
  58.  * @subpackage Strategy
  59.  * @author     Stefano F. Rausch <stefano@rausch-e.net>
  60.  * @copyright  2005 Stefano F. Rausch <stefano@rausch-e.net>
  61.  * @license    http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  62.  * @version    Release: @package_version@
  63.  * @link       http://pear.php.net/package/ScriptReorganizer
  64.  */
  65. class ScriptReorganizer_Strategy_Pack implements ScriptReorganizer_Strategy
  66. {
  67.     // {{{ public function __construct( $oneLiner = false )
  68.     
  69.     /**
  70.      * Constructor
  71.      *
  72.      * @param boolean $oneLiner true, if the script's packing should result in only
  73.      *         one line of code - extreme pack mode; otherwise false - default pack
  74.      *         mode
  75.      */
  76.     public function __construct$oneLiner = false )
  77.     {
  78.         $this->oneLiner $oneLiner ? true : false;
  79.         $this->quiet = new ScriptReorganizer_Strategy_Quiet;
  80.     }
  81.     
  82.     // }}}
  83.     
  84.     // {{{ public function reformat( & $content, $eol )
  85.     
  86.     /**
  87.      * Performs the main reorganization of the script's content
  88.      *
  89.      * @param  string &$content a string representing the script's content
  90.      * @param  string $eol a string representing the EOL identifier to use
  91.      * @return string a string representing the reorganized content
  92.      */
  93.     public function reformat$content$eol )
  94.     {
  95.         $multiSpacesAndOrTabs '"[ \t]+"';
  96.         
  97.         $result $this->quiet->reformat$content$eol );
  98.         
  99.         if $this->oneLiner {
  100.             $result str_replace$eol' '$result );
  101.         else {
  102.             $result preg_replace'"[' $eol ']+[ \t]+"'$eol $result );
  103.             $result str_replace$eol $eol$eol$result );
  104.         }
  105.         
  106.         $result preg_replace$multiSpacesAndOrTabs' '$result );
  107.         
  108.         return $result;
  109.     }
  110.     
  111.     // }}}
  112.     
  113.     // {{{ private properties
  114.     
  115.     /**
  116.      * Holds the indicator for extreme packing
  117.      *
  118.      * @var boolean 
  119.      */
  120.     private $oneLiner = false;
  121.     
  122.     /**
  123.      * Holds the helper strategy
  124.      *
  125.      * @var ScriptReorganizer_Strategy_Quiet 
  126.      */
  127.     private $quiet = null;
  128.     
  129.     // }}}
  130. }
  131.  
  132. /*
  133.  * Local variables:
  134.  * tab-width: 4
  135.  * c-basic-offset: 4
  136.  * c-hanging-comment-ender-p: nil
  137.  * End:
  138.  */
  139.  
  140. ?>

Documentation generated on Mon, 11 Mar 2019 14:10:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.