minor changes to Doctrine::compile(), adding extra error handling and improving docs
This commit is contained in:
parent
1a265b0750
commit
ae534f69ff
26
Doctrine.php
26
Doctrine.php
@ -386,7 +386,6 @@ final class Doctrine {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* method for making a single file of most used doctrine runtime components
|
* method for making a single file of most used doctrine runtime components
|
||||||
*
|
|
||||||
* including the compiled file instead of multiple files (in worst
|
* including the compiled file instead of multiple files (in worst
|
||||||
* cases dozens of files) can improve performance by an order of magnitude
|
* cases dozens of files) can improve performance by an order of magnitude
|
||||||
*
|
*
|
||||||
@ -453,24 +452,31 @@ final class Doctrine {
|
|||||||
$start,
|
$start,
|
||||||
($end - $start)));
|
($end - $start)));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = self::$path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
|
$file = self::$path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
|
||||||
|
if (!is_writable($file))
|
||||||
|
throw new Doctrine_Exception("Couldn't write compiled data. $file is not writable");
|
||||||
|
|
||||||
$fp = fopen($file, 'w+');
|
// first write the 'compiled' data to a text file, so
|
||||||
fwrite($fp, "<?php
|
// that we can use php_strip_whitespace (which only works on files)
|
||||||
".implode('', $ret)."
|
$fp = fopen($file, 'w');
|
||||||
class InvalidKeyException extends Exception { }
|
if ($fp === false)
|
||||||
class DQLException extends Exception { }
|
throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file");
|
||||||
?>");
|
fwrite($fp, "<?php ".implode('', $ret).
|
||||||
|
"\nclass InvalidKeyException extends Exception { }".
|
||||||
|
"\nclass DQLException extends Exception { }"
|
||||||
|
);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$stripped = php_strip_whitespace( $file );
|
|
||||||
|
|
||||||
$fp = fopen($file, 'w+');
|
$stripped = php_strip_whitespace( $file );
|
||||||
|
$fp = fopen($file, 'w');
|
||||||
|
if ($fp === false)
|
||||||
|
throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file");
|
||||||
fwrite($fp, $stripped);
|
fwrite($fp, $stripped);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* simple autoload function
|
* simple autoload function
|
||||||
* returns true if the class was loaded, otherwise false
|
* returns true if the class was loaded, otherwise false
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
<p>
|
||||||
|
Compiling is a method for making a single file of most used doctrine runtime components
|
||||||
|
including the compiled file instead of multiple files (in worst cases dozens of files)
|
||||||
|
can improve performance by an order of magnitude.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
In cases where this might fail, a Doctrine_Exception is throw detailing the error.
|
||||||
|
</p>
|
Loading…
Reference in New Issue
Block a user