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: 0.4.0
  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. * Constructor
  70. *
  71. * @param boolean $oneLiner true, if the script's packing should result in only
  72. * one line of code - extreme pack mode; otherwise false - default pack
  73. * mode
  74. */
  75. public function __construct( $oneLiner = false )
  76. {
  77. $this->oneLiner = $oneLiner ? true : false;
  78. $this->quiet = new ScriptReorganizer_Strategy_Quiet;
  79. }
  80. // }}}
  81. // {{{ public function reformat( & $content, $eol )
  82. /**
  83. * Performs the main reorganization of the script's content
  84. *
  85. * @param string &$content a string representing the script's content
  86. * @param string $eol a string representing the EOL identifier to use
  87. * @return string a string representing the reorganized content
  88. */
  89. public function reformat( & $content, $eol )
  90. {
  91. $multiSpacesAndOrTabs = '"[ \t]+"';
  92. $result = $this->quiet->reformat( $content, $eol );
  93. if ( $this->oneLiner ) {
  94. $result = str_replace( $eol, ' ', $result );
  95. } else {
  96. $result = preg_replace( '"[' . $eol . ']+[ \t]+"', $eol , $result );
  97. $result = str_replace( $eol . $eol, $eol, $result );
  98. }
  99. $result = preg_replace( $multiSpacesAndOrTabs, ' ', $result );
  100. return $result;
  101. }
  102. // }}}
  103. // {{{ private properties
  104. /**
  105. * Holds the indicator for extreme packing
  106. *
  107. * @var boolean
  108. */
  109. private $oneLiner = false;
  110. /**
  111. * Holds the helper strategy
  112. *
  113. * @var ScriptReorganizer_Strategy_Quiet
  114. */
  115. private $quiet = null;
  116. // }}}
  117.  
  118. }
  119.  
  120. /*
  121. * Local variables:
  122. * tab-width: 4
  123. * c-basic-offset: 4
  124. * c-hanging-comment-ender-p: nil
  125. * End:
  126. */
  127.  
  128. ?>

Documentation generated on Tue, 22 Nov 2005 01:57:11 +0100 by phpDocumentor 1.3.0RC3