示例#1
0
 /**
  * Returns the stream with an additional linebreak.
  *
  * @return the resulting stream, or -1
  *         if the end of the resulting stream has been reached
  *
  * @throws IOException if the underlying stream throws an IOException
  *                        during reading
  */
 function read($len = null)
 {
     if ($this->processed === true) {
         return -1;
         // EOF
     }
     // Read
     $php = null;
     while (($buffer = $this->in->read($len)) !== -1) {
         $php .= $buffer;
     }
     if ($php === null) {
         // EOF?
         return -1;
     }
     if (empty($php)) {
         $this->log("File is empty!", Project::MSG_WARN);
         return '';
         // return empty string
     }
     // write buffer to a temporary file, since php_strip_whitespace() needs a filename
     $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
     file_put_contents($file->getAbsolutePath(), $php);
     $output = file_get_contents($file->getAbsolutePath()) . "\r\n";
     unlink($file->getAbsolutePath());
     $this->processed = true;
     return $output;
 }
示例#2
0
 /**
  * Returns the stream without require_once statements.
  *
  * @return the resulting stream, or -1
  *         if the end of the resulting stream has been reached
  *
  * @throws IOException if the underlying stream throws an IOException
  *                        during reading
  */
 function read($len = null)
 {
     if ($this->processed === true) {
         return -1;
         // EOF
     }
     // Read
     $php = null;
     while (($buffer = $this->in->read($len)) !== -1) {
         $php .= $buffer;
     }
     if ($php === null) {
         // EOF?
         return -1;
     }
     if (empty($php)) {
         $this->log("File is empty!", Project::MSG_WARN);
         return '';
         // return empty string
     }
     // write buffer to a temporary file, since php_strip_whitespace() needs a filename
     $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
     file_put_contents($file->getAbsolutePath(), $php);
     $output = $php;
     $matches = array();
     if (preg_match_all('|/\\*\\*(.*?)\\*/\\s+(require_once \'.*?\';\\s*)?|s', $output, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             list($all, $docblock, $require) = $match;
             if (strstr($docblock, '@see')) {
                 // Remove docblock and require_once, if it contains @see
                 $output = str_replace($all, '', $output);
             } else {
                 // Just remove require_once statement
                 $output = str_replace($require, '', $output);
             }
         }
     }
     $output = preg_replace("/(^\\s*require_once.*?;\\s*\$\\s)/sm", "", $output);
     unlink($file->getAbsolutePath());
     $this->processed = true;
     return $output;
 }
示例#3
0
 /**
  * try and create a temp file in our temp dir; this
  * checks that it has space and access.
  * We also do some clock reporting.
  *
  * @param PrintStream $out
  */
 private static function doReportTempDir(PrintStream $out)
 {
     $tempdir = PhingFile::getTempDir();
     if ($tempdir == null) {
         $out->println("Warning: php.tmpdir is undefined");
         return;
     }
     $out->println("Temp dir is " . $tempdir);
     $tempDirectory = new PhingFile($tempdir);
     if (!$tempDirectory->exists()) {
         $out->println("Warning, php.tmpdir directory does not exist: " . $tempdir);
         return;
     }
     $now = time();
     $tempFile = PhingFile::createTempFile('diag', 'txt', $tempDirectory);
     $fileWriter = new FileWriter($tempFile);
     $fileWriter->write('some test text');
     $fileWriter->close();
     $filetime = $tempFile->lastModified();
     $tempFile->delete();
     $out->println("Temp dir is writeable");
     $drift = $filetime - $now;
     $out->println("Temp dir alignment with system clock is " . $drift . " s");
     if (abs($drift) > 10) {
         $out->println("Warning: big clock drift -maybe a network filesystem");
     }
 }
 /**
  * Returns the stream with an additional linebreak.
  *
  * @return the resulting stream, or -1
  *         if the end of the resulting stream has been reached
  *
  * @throws IOException if the underlying stream throws an IOException
  *                        during reading
  */
 function read($len = null)
 {
     if ($this->processed === true) {
         return -1;
         // EOF
     }
     // Read
     $php = null;
     while (($buffer = $this->in->read($len)) !== -1) {
         $php .= $buffer;
     }
     if ($php === null) {
         // EOF?
         return -1;
     }
     if (empty($php)) {
         $this->log("File is empty!", Project::MSG_WARN);
         return '';
         // return empty string
     }
     // write buffer to a temporary file, since php_strip_whitespace() needs a filename
     $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
     file_put_contents($file->getAbsolutePath(), $php);
     $output = $php;
     $output = preg_replace("/\\/\\*@REMOVE@\\*\\/(.*?)\\/\\*@REMOVE@\\*\\//ims", "", $output);
     $output = preg_replace("/;@REMOVE@;(.*?);@REMOVE@;/ims", "", $output);
     $output = trim(str_replace(array('<!--@BUILD_ACTIVE@', '@BUILD_ACTIVE@-->', '/*@BUILD_ACTIVE@*/', '<?php /*@BUILD_ACTIVE@', '@BUILD_ACTIVE@*/ ?>', '/*@BUILD_ACTIVE@', '@BUILD_ACTIVE@*/'), "", $output));
     unlink($file->getAbsolutePath());
     $this->processed = true;
     return $output;
 }
 /**
  * Returns the stream with an additional linebreak.
  *
  * @return the resulting stream, or -1
  *         if the end of the resulting stream has been reached
  *
  * @throws IOException if the underlying stream throws an IOException
  *                        during reading
  */
 function read($len = null)
 {
     if ($this->processed === true) {
         return -1;
         // EOF
     }
     // Read
     $php = null;
     while (($buffer = $this->in->read($len)) !== -1) {
         $php .= $buffer;
     }
     if ($php === null) {
         // EOF?
         return -1;
     }
     if (empty($php)) {
         $this->log("File is empty!", Project::MSG_WARN);
         return '';
         // return empty string
     }
     // write buffer to a temporary file, since php_strip_whitespace() needs a filename
     $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
     file_put_contents($file->getAbsolutePath(), $php);
     $output = $php;
     $output = preg_replace(array("/^(( | \\* |-- |; |; \\* ).(Author|Date|Revision|LastChangedDate|LastChangedBy|URL).*)(\n|\r\n)/m", "/<\\?php\\s*\\?>/ims"), "", $output);
     unlink($file->getAbsolutePath());
     $this->processed = true;
     return $output;
 }