From d94d5ec1cb26c40cf3f48105d2149479ff530c13 Mon Sep 17 00:00:00 2001 From: romanb Date: Sat, 23 Sep 2006 14:31:17 +0000 Subject: [PATCH] - 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 --- Doctrine/Compiler.php | 31 +++++++++++++++++++++---------- tools/cli/bundle.php | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 tools/cli/bundle.php diff --git a/Doctrine/Compiler.php b/Doctrine/Compiler.php index 51842c78e..014db4ee0 100644 --- a/Doctrine/Compiler.php +++ b/Doctrine/Compiler.php @@ -41,9 +41,12 @@ class Doctrine_Compiler { "Exception", "Access", "Null", + "Identifier", + "Repository", "Record", "Record_Iterator", "Collection", + "Collection_Immediate", "Validator", "Hydrate", "Query", @@ -57,12 +60,16 @@ class Doctrine_Compiler { "RawSql", "EventListener_Interface", "EventListener", + "EventListener_Empty", "Relation", "ForeignKey", "LocalKey", "Association", "DB", - "DBStatement"); + "DBStatement", + "Connection", + "Connection_UnitOfWork", + "Connection_Transaction"); /** * getRuntimeClasses @@ -81,7 +88,7 @@ class Doctrine_Compiler { * @throws Doctrine_Exception * @return void */ - public static function compile() { + public static function compile($target = null) { $path = Doctrine::getPath(); $classes = self::$classes; @@ -93,11 +100,13 @@ class Doctrine_Compiler { $class = 'Doctrine_'.$class; $file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php"; + + echo "Adding $file" . PHP_EOL; if( ! file_exists($file)) throw new Doctrine_Exception("Couldn't compile $file. File $file does not exists."); - self::autoload($class); + Doctrine::autoload($class); $refl = new ReflectionClass ( $class ); $lines = file( $file ); @@ -111,15 +120,17 @@ class Doctrine_Compiler { } - $file = $path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php'; - if (!is_writable($file)) - throw new Doctrine_Exception("Couldn't write compiled data. $file is not writable"); + 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) - $fp = fopen($file, 'w'); + $fp = @fopen($target, 'w'); + 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, " "; + 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