Source for file AddHeader.php

Documentation is available at AddHeader.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6. * ScriptReorganizer Type Decorator :: AddHeader
  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 Type_Decorator
  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: AddHeader.php 37 2005-11-15 05:00:00Z stefanorausch $
  22. * @link http://pear.php.net/package/ScriptReorganizer
  23. * @filesource
  24. */
  25.  
  26. /**
  27. * Depends on <kbd>ScriptReorganizer_Type</kbd>
  28. */
  29. require_once 'ScriptReorganizer/Type.php';
  30.  
  31. /**
  32. * Extends <kbd>ScriptReorganizer_Type_Decorator</kbd>
  33. */
  34. require_once 'ScriptReorganizer/Type/Decorator.php';
  35.  
  36. /**
  37. * Throws <kbd>ScriptReorganizer_Type_Decorator_Exception</kbd>
  38. */
  39. require_once 'ScriptReorganizer/Type/Decorator/Exception.php';
  40.  
  41. /**
  42. * Decorator for adding a header to the script to reorganize
  43. *
  44. * If the optional/overriding header contains EOL control characters, these will be
  45. * converted to the one being used in the main content during the optimization, if
  46. * needed.
  47. *
  48. * ANN: Decoration of a directly sequencing Pharize-Decorator is not allowed.
  49. *
  50. * @category Tools
  51. * @package ScriptReorganizer
  52. * @subpackage Type_Decorator
  53. * @author Stefano F. Rausch <stefano@rausch-e.net>
  54. * @copyright 2005 Stefano F. Rausch <stefano@rausch-e.net>
  55. * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  56. * @version Release: 0.4.0
  57. * @link http://pear.php.net/package/ScriptReorganizer
  58. */
  59. class ScriptReorganizer_Type_Decorator_AddHeader extends ScriptReorganizer_Type_Decorator
  60. {
  61. // {{{ public function __construct( ScriptReorganizer_Type $type, $header = '' )
  62. /**
  63. * Constructor
  64. *
  65. * @param ScriptReorganizer_Type $type a <kbd>ScriptReorganizer_Type</kbd> to
  66. * decorate
  67. * @param string $header a string representing the (optional) default header to
  68. * prepend
  69. * @throws {@link ScriptReorganizer_Type_Decorator_Exception ScriptReorganizer_Type_Decorator_Exception}
  70. */
  71. public function __construct( ScriptReorganizer_Type $type, $header = '' )
  72. {
  73. if ( class_exists( 'ScriptReorganizer_Type_Decorator_Pharize', false ) ) {
  74. if ( $type instanceof ScriptReorganizer_Type_Decorator_Pharize ) {
  75. throw new ScriptReorganizer_Type_Decorator_Exception(
  76. 'Decoration of a directly sequencing Pharize-Decorator not allowed'
  77. );
  78. }
  79. }
  80. parent::__construct( $type );
  81. $this->header = null === $header ? '' : $header;
  82. }
  83. // }}}
  84. // {{{ public function reformat( $header = null )
  85. /**
  86. * Reorganizes the script's content by applying the chosen
  87. * {@link ScriptReorganizer_Strategy Strategy}
  88. *
  89. * @param string $header a string representing the (optional) overriding header
  90. * to prepend
  91. * @return void
  92. * @throws {@link ScriptReorganizer_Type_Decorator_Exception ScriptReorganizer_Type_Decorator_Exception}
  93. */
  94. public function reformat( $header = null )
  95. {
  96. if ( null !== $header ) {
  97. $this->header = $header;
  98. }
  99. if ( !is_string( $this->header ) ) {
  100. throw new ScriptReorganizer_Type_Decorator_Exception (
  101. 'Argument $header for AddHeader-Decorator not of type string'
  102. );
  103. }
  104. $content = $this->_getContent();
  105. $eolOfContent = $this->getEolIdentifier( $content );
  106. $eolOfHeader = $this->getEolIdentifier( $this->header );
  107. if ( $eolOfHeader != $eolOfContent ) {
  108. $this->header = str_replace( $eolOfHeader, $eolOfContent, $this->header );
  109. }
  110. parent::reformat();
  111. $this->_setContent( $this->header . $this->_getContent() );
  112. }
  113. // }}}
  114. // {{{ private properties
  115. /**
  116. * Holds the header to prepend
  117. *
  118. * @var string
  119. */
  120. private $header = null;
  121. // }}}
  122.  
  123. }
  124.  
  125. /*
  126. * Local variables:
  127. * tab-width: 4
  128. * c-basic-offset: 4
  129. * c-hanging-comment-ender-p: nil
  130. * End:
  131. */
  132.  
  133. ?>

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