Commit ba737729 authored by romanb's avatar romanb

Fixes to the compiler.

parent 9589f486
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_Compiler * Doctrine_Compiler
* This class can be used for compiling the entire Doctrine framework into a single file * This class can be used for compiling the entire Doctrine framework into a single file
* *
* @package Doctrine * @package Doctrine
* @author Konsta Vesterinen * @author Konsta Vesterinen
* @license LGPL * @license LGPL
*/ */
class Doctrine_Compiler { class Doctrine_Compiler {
/** /**
* @var array $classes an array containing all runtime classes of Doctrine framework * @var array $classes an array containing all runtime classes of Doctrine framework
*/ */
private static $classes = array( private static $classes = array(
"Doctrine", "Doctrine",
"Configurable", "Configurable",
"Overloadable", "Overloadable",
"Access", "Access",
"Manager", "Manager",
"Table", "Table",
"Table_Exception", "Table_Exception",
"Iterator", "Exception",
"Exception",
"Null",
"Null", "Identifier",
"Identifier", "Record",
"Repository", "Record_Exception",
"Record", "Record_Iterator",
"Record_Exception", "Collection",
"Record_Iterator", "Collection_Immediate",
"Collection", "Validator",
"Collection_Immediate", "Validator_Exception",
"Validator", "Validator_Notnull",
"Validator_Exception", "Validator_Nospace",
"Validator_Notnull", "Validator_Range",
"Validator_Nospace", "Validator_Regexp",
"Validator_Range", "Validator_Country",
"Validator_Regexp", "Validator_Notblank",
"Validator_Country", "Validator_Creditcard",
"Validator_Notblank", "Validator_Date",
"Validator_Creditcard", "Validator_Ip",
"Validator_Date", "Validator_Unique",
"Validator_Ip", "Validator_Usstate",
"Validator_Unique", "Validator_Htmlcolor",
"Validator_Usstate", "Validator_Email",
"Validator_Htmlcolor", "Hydrate",
"Validator_Email", "Query",
"Hydrate", "Query_Part",
"Query", "Query_From",
"Query_Part", "Query_Orderby",
"Query_From", "Query_Groupby",
"Query_Orderby", "Query_Condition",
"Query_Groupby", "Query_Where",
"Query_Condition", "Query_Having",
"Query_Where", "Query_Exception",
"Query_Having", "RawSql",
"Query_Exception", "RawSql_Exception",
"RawSql", "EventListener_Interface",
"RawSql_Exception", "EventListener",
"EventListener_Interface", "EventListener_Empty",
"EventListener", "EventListener_Chain",
"EventListener_Empty", "Relation",
"EventListener_Chain", "Relation_ForeignKey",
"Relation", "Relation_LocalKey",
"Relation_ForeignKey", "Relation_Association",
"Relation_LocalKey", "DB",
"Relation_Association", "DBStatement",
"DB", "Connection",
"DBStatement", "Connection_Exception",
"Connection", "Connection_UnitOfWork",
"Connection_Exception", "Connection_Transaction");
"Connection_UnitOfWork",
"Connection_Transaction"); /**
* getRuntimeClasses
/** * returns an array containing all runtime classes of Doctrine framework
* getRuntimeClasses *
* returns an array containing all runtime classes of Doctrine framework * @return array
* */
* @return array public static function getRuntimeClasses() {
*/ return self::$classes;
public static function getRuntimeClasses() { }
return self::$classes; /**
} * method for making a single file of most used doctrine runtime components
/** * including the compiled file instead of multiple files (in worst
* method for making a single file of most used doctrine runtime components * cases dozens of files) can improve performance by an order of magnitude
* including the compiled file instead of multiple files (in worst *
* cases dozens of files) can improve performance by an order of magnitude * @throws Doctrine_Compiler_Exception if something went wrong during the compile operation
* * @return void
* @throws Doctrine_Compiler_Exception if something went wrong during the compile operation */
* @return void public static function compile($target = null) {
*/ $path = Doctrine::getPath();
public static function compile($target = null) {
$path = Doctrine::getPath(); $classes = self::$classes;
$classes = self::$classes; $ret = array();
$ret = array(); foreach($classes as $class) {
if($class !== 'Doctrine')
foreach($classes as $class) { $class = 'Doctrine_'.$class;
if($class !== 'Doctrine')
$class = 'Doctrine_'.$class; $file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php";
$file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php"; echo "Adding $file" . PHP_EOL;
echo "Adding $file" . PHP_EOL; if( ! file_exists($file))
throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists.");
if( ! file_exists($file))
throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists."); Doctrine::autoload($class);
$refl = new ReflectionClass ( $class );
Doctrine::autoload($class); $lines = file( $file );
$refl = new ReflectionClass ( $class );
$lines = file( $file ); $start = $refl -> getStartLine() - 1;
$end = $refl -> getEndLine();
$start = $refl -> getStartLine() - 1;
$end = $refl -> getEndLine(); $ret = array_merge($ret,
array_slice($lines,
$ret = array_merge($ret, $start,
array_slice($lines, ($end - $start)));
$start,
($end - $start))); }
} if ($target == null) {
$target = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
if ($target == null) { }
$target = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
} // first write the 'compiled' data to a text file, so
// that we can use php_strip_whitespace (which only works on files)
// first write the 'compiled' data to a text file, so $fp = @fopen($target, 'w');
// that we can use php_strip_whitespace (which only works on files)
$fp = @fopen($target, 'w'); if ($fp === false)
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target");
if ($fp === false)
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target"); fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }".
fwrite($fp, "<?php". implode('', $ret)
" class InvalidKeyException extends Exception { }". );
implode('', $ret) fclose($fp);
);
fclose($fp); $stripped = php_strip_whitespace($target);
$fp = @fopen($target, 'w');
$stripped = php_strip_whitespace($target); if ($fp === false)
$fp = @fopen($target, 'w'); throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file");
if ($fp === false) fwrite($fp, $stripped);
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file"); fclose($fp);
fwrite($fp, $stripped); }
fclose($fp); }
}
}
...@@ -15,6 +15,8 @@ set_include_path(get_include_path() . PATH_SEPARATOR . $doctrineBaseDir); ...@@ -15,6 +15,8 @@ set_include_path(get_include_path() . PATH_SEPARATOR . $doctrineBaseDir);
require_once 'Doctrine.php'; require_once 'Doctrine.php';
require_once 'Doctrine/Compiler.php'; require_once 'Doctrine/Compiler.php';
spl_autoload_register(array('Doctrine', 'autoload'));
echo "Bundling classes ..." . PHP_EOL; echo "Bundling classes ..." . PHP_EOL;
Doctrine_Compiler::compile($targetDir); Doctrine_Compiler::compile($targetDir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment