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

Source for file Bcompile.php

Documentation is available at Bcompile.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * ScriptReorganizer Type Decorator :: Bcompile
  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: Bcompile.php 33 2005-11-06 22:05:46Z stefanorausch $
  22.  * @link       http://pear.php.net/package/ScriptReorganizer
  23.  * @since      File available since Release 0.3.0
  24.  * @filesource
  25.  */
  26.  
  27. /**
  28.  * Depends on <kbd>ScriptReorganizer_Type</kbd>
  29.  */
  30. require_once 'ScriptReorganizer/Type.php';
  31.  
  32. /**
  33.  * Extends <kbd>ScriptReorganizer_Type_Decorator</kbd>
  34.  */
  35. require_once 'ScriptReorganizer/Type/Decorator.php';
  36.  
  37. /**
  38.  * Throws <kbd>ScriptReorganizer_Type_Decorator_Exception</kbd>
  39.  */
  40. require_once 'ScriptReorganizer/Type/Decorator/Exception.php';
  41.  
  42. /**
  43.  * Decorator/Adapter for encoding a PHP source file in byte-code
  44.  *
  45.  * If a script or a library is bcompiled, a non-ScriptReorganized source code tree
  46.  * should be shipped together with the optimized one, to enable third parties to
  47.  * track down undiscoverd bugs.
  48.  *
  49.  * ANN: Decoration of a directly sequencing Bcompile-Decorator or Pharize-Decorator
  50.  * is not allowed.
  51.  *
  52.  * @category   Tools
  53.  * @package    ScriptReorganizer
  54.  * @subpackage Type_Decorator
  55.  * @author     Stefano F. Rausch <stefano@rausch-e.net>
  56.  * @copyright  2005 Stefano F. Rausch <stefano@rausch-e.net>
  57.  * @license    http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  58.  * @version    Release: @package_version@
  59.  * @link       http://pear.php.net/package/ScriptReorganizer
  60.  * @since      Class available since Release 0.3.0
  61.  */
  62. {
  63.     // {{{ public function __construct( ScriptReorganizer_Type $type )
  64.     
  65.     /**
  66.      * Constructor
  67.      *
  68.      * @param  ScriptReorganizer_Type $type a <kbd>ScriptReorganizer_Type</kbd> to
  69.      *          decorate
  70.      * @throws {@link ScriptReorganizer_Type_Decorator_Exception ScriptReorganizer_Type_Decorator_Exception}
  71.      */
  72.     public function __constructScriptReorganizer_Type $type )
  73.     {
  74.         $constraint '';
  75.         
  76.         if $type instanceof ScriptReorganizer_Type_Decorator_Bcompile {
  77.             $constraint 'Bcompile-Decorator';
  78.         else if class_exists'ScriptReorganizer_Type_Decorator_Pharize'false ) ) {
  79.             if $type instanceof ScriptReorganizer_Type_Decorator_Pharize {
  80.                 $constraint 'Pharize-Decorator';
  81.             }
  82.         }
  83.         
  84.         if $constraint {
  85.             throw new ScriptReorganizer_Type_Decorator_Exception(
  86.                 'Decoration of a directly sequencing ' $constraint ' not allowed'
  87.             );
  88.         }
  89.         
  90.         if !extension_loaded'bcompiler' ) ) {
  91.             throw new ScriptReorganizer_Type_Decorator_Exception(
  92.                 'PHP Extension bcompiler not loaded'
  93.             );
  94.         }
  95.         
  96.         parent::__construct$type );
  97.     }
  98.     
  99.     // }}}
  100.     
  101.     // {{{ public function save( $file )
  102.     
  103.     /**
  104.      * Saves the reorganized script's content as encoded byte-code to disk
  105.      *
  106.      * @param  string $file a string representing the file's name to save
  107.      * @return void 
  108.      * @throws {@link ScriptReorganizer_Type_Decorator_Exception ScriptReorganizer_Type_Decorator_Exception}
  109.      */
  110.     public function save$file )
  111.     {
  112.         $source 'source.' md5($file);
  113.         
  114.         @file_put_contents$source'<?php ' $this->_getContent(' ?>' );
  115.         
  116.         if is_file$source ) ) {
  117.             if $target @fopen$file'wb' ) ) {
  118.                 bcompiler_write_header$target );
  119.                 bcompiler_write_file$target$source );
  120.                 bcompiler_write_footer$target );
  121.                 
  122.                 @fclose$target );
  123.             }
  124.             
  125.             unlink$source );
  126.         }
  127.         
  128.         if !is_file$file ) ) {
  129.             throw new ScriptReorganizer_Type_Decorator_Exception(
  130.                 'BCompiler file ' $file ' is not writable'
  131.             );
  132.         }
  133.     }
  134.     
  135.     // }}}
  136. }
  137.  
  138. /*
  139.  * Local variables:
  140.  * tab-width: 4
  141.  * c-basic-offset: 4
  142.  * c-hanging-comment-ender-p: nil
  143.  * End:
  144.  */
  145.  
  146. ?>

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