1
0
mirror of synced 2024-12-13 06:46:03 +03:00

- 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
This commit is contained in:
romanb 2006-09-23 14:31:17 +00:00
parent 110a6764e8
commit d94d5ec1cb
2 changed files with 46 additions and 10 deletions

View File

@ -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 {
"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 {
* @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 {
$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 {
} }
$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 {
); );
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);

25
tools/cli/bundle.php Normal file
View File

@ -0,0 +1,25 @@
<?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);
?>