Commit d94d5ec1 authored by romanb's avatar romanb

- Fixes and changes to Doctrine_Compiler

- Added a small cli script to run the compiler from the command line. The script requires the Doctrine base directory (the directory where Doctrine.php and the Doctrine folder is in) and the target file as its parameters.

Example: ./dev/Doctrine/ ./dev/myproject/BundledClasses.php
parent 110a6764
...@@ -41,9 +41,12 @@ class Doctrine_Compiler { ...@@ -41,9 +41,12 @@ class Doctrine_Compiler {
"Exception", "Exception",
"Access", "Access",
"Null", "Null",
"Identifier",
"Repository",
"Record", "Record",
"Record_Iterator", "Record_Iterator",
"Collection", "Collection",
"Collection_Immediate",
"Validator", "Validator",
"Hydrate", "Hydrate",
"Query", "Query",
...@@ -57,12 +60,16 @@ class Doctrine_Compiler { ...@@ -57,12 +60,16 @@ class Doctrine_Compiler {
"RawSql", "RawSql",
"EventListener_Interface", "EventListener_Interface",
"EventListener", "EventListener",
"EventListener_Empty",
"Relation", "Relation",
"ForeignKey", "ForeignKey",
"LocalKey", "LocalKey",
"Association", "Association",
"DB", "DB",
"DBStatement"); "DBStatement",
"Connection",
"Connection_UnitOfWork",
"Connection_Transaction");
/** /**
* getRuntimeClasses * getRuntimeClasses
...@@ -81,7 +88,7 @@ class Doctrine_Compiler { ...@@ -81,7 +88,7 @@ class Doctrine_Compiler {
* @throws Doctrine_Exception * @throws Doctrine_Exception
* @return void * @return void
*/ */
public static function compile() { public static function compile($target = null) {
$path = Doctrine::getPath(); $path = Doctrine::getPath();
$classes = self::$classes; $classes = self::$classes;
...@@ -94,10 +101,12 @@ class Doctrine_Compiler { ...@@ -94,10 +101,12 @@ class Doctrine_Compiler {
$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;
if( ! file_exists($file)) if( ! file_exists($file))
throw new Doctrine_Exception("Couldn't compile $file. File $file does not exists."); throw new Doctrine_Exception("Couldn't compile $file. File $file does not exists.");
self::autoload($class); Doctrine::autoload($class);
$refl = new ReflectionClass ( $class ); $refl = new ReflectionClass ( $class );
$lines = file( $file ); $lines = file( $file );
...@@ -111,15 +120,17 @@ class Doctrine_Compiler { ...@@ -111,15 +120,17 @@ class Doctrine_Compiler {
} }
$file = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php'; if ($target == null) {
if (!is_writable($file)) $target = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
throw new Doctrine_Exception("Couldn't write compiled data. $file is not writable"); }
// first write the 'compiled' data to a text file, so // first write the 'compiled' data to a text file, so
// that we can use php_strip_whitespace (which only works on files) // that we can use php_strip_whitespace (which only works on files)
$fp = fopen($file, 'w'); $fp = @fopen($target, 'w');
if ($fp === false) if ($fp === false)
throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file"); throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $target");
fwrite($fp, "<?php". fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }". " class InvalidKeyException extends Exception { }".
" class DQLException extends Exception { }". " class DQLException extends Exception { }".
...@@ -127,8 +138,8 @@ class Doctrine_Compiler { ...@@ -127,8 +138,8 @@ class Doctrine_Compiler {
); );
fclose($fp); fclose($fp);
$stripped = php_strip_whitespace( $file ); $stripped = php_strip_whitespace($target);
$fp = fopen($file, 'w'); $fp = @fopen($target, 'w');
if ($fp === false) if ($fp === false)
throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file"); throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file");
fwrite($fp, $stripped); fwrite($fp, $stripped);
......
<?php
/**
* Small command line script to bundle Doctrine classes.
*/
if (count($argv) < 2) {
echo "Usage: bundle.php <Doctrine basedir> <Target dir>";
exit(1);
}
$doctrineBaseDir = $argv[1];
$targetDir = $argv[2];
set_include_path(get_include_path() . PATH_SEPARATOR . $doctrineBaseDir);
require_once 'Doctrine.php';
require_once 'Doctrine/Compiler.php';
echo "Bundling classes ..." . PHP_EOL;
Doctrine_Compiler::compile($targetDir);
echo "Bundle complete." . PHP_EOL;
exit(0);
?>
\ No newline at end of file
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