Exemple #1
0
 /**
  * Logs exception and return false to mark operation has failed.
  * @param string $message A message to write into log
  * @return false
  */
 protected function throwException($message = '')
 {
     if ($this->_log === null) {
         $this->_log = new LogWriter($this->_logPath);
     }
     if (mysqli_connect_errno()) {
         $message = '(' . mysqli_connect_errno() . ') ' . mysqli_connect_error() . ': ' . $message;
     } elseif (mysqli_errno($this->_conn)) {
         $message = '(' . mysqli_errno($this->_conn) . ') ' . mysqli_error($this->_conn) . ': ' . $message;
     }
     if ($message) {
         $this->_log->log($message);
     }
     return false;
 }
Exemple #2
0
 /**
  * Logs exception and return false to mark operation has failed.
  * @param string $message A message to write into log
  * @param Exception $exc The exception occurs while executing the function
  * @param array $params An array of parameters passed to the 'mail' function (to, subject, message, header)
  * @return false
  */
 protected function throwException($message = '', $exc = null, $params = array())
 {
     if ($this->_log === null) {
         $this->_log = new LogWriter(realpath(dirname(__FILE__) . '/../logs') . DIRECTORY_SEPARATOR . 'mail.log');
     }
     if ($exc) {
         $message = '(' . $exc->getCode() . ') ' . $exc->getMessage() . ': ' . $message;
     }
     foreach ($params as $pName => $pValue) {
         $message .= PHP_EOL . $pName . ': ' . $pValue;
     }
     if ($message) {
         $this->_log->log($message);
     }
     return false;
 }
Exemple #3
0
 /**
  * Append the file(s).
  *
  * {@inheritdoc}
  */
 public function main()
 {
     $this->validate();
     try {
         if ($this->to !== null) {
             // create a file writer to append to "to" file.
             $writer = new FileWriter($this->to, $this->append);
         } else {
             $writer = new LogWriter($this);
         }
         if ($this->text !== null) {
             // simply append the text
             if ($this->to instanceof PhingFile) {
                 $this->log("Appending string to " . $this->to->getPath());
             }
             $text = $this->text;
             if ($this->filtering) {
                 $fr = $this->getFilteredReader(new StringReader($text));
                 $text = $fr->read();
             }
             $text = $this->appendHeader($text);
             $text = $this->appendFooter($text);
             $writer->write($text);
         } else {
             // append explicitly-specified file
             if ($this->file !== null) {
                 try {
                     $this->appendFile($writer, $this->file);
                 } catch (Exception $ioe) {
                     $this->log("Unable to append contents of file " . $this->file->getAbsolutePath() . ": " . $ioe->getMessage(), Project::MSG_WARN);
                 }
             }
             // append any files in filesets
             foreach ($this->filesets as $fs) {
                 try {
                     if ($fs instanceof Path) {
                         $files = $fs->listPaths();
                         $this->appendFiles($writer, $files);
                     } elseif ($fs instanceof FileSet) {
                         $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
                         $this->appendFiles($writer, $files, $fs->getDir($this->project));
                     }
                 } catch (BuildException $be) {
                     if (strpos($be->getMessage(), 'is the same as the output file') === false) {
                         $this->log($be->getMessage(), Project::MSG_WARN);
                     } else {
                         throw new BuildException($be->getMessage());
                     }
                 } catch (IOException $ioe) {
                     throw new BuildException($ioe);
                 }
             }
             /** @var FileList $list */
             foreach ($this->fileList as $list) {
                 $dir = $list->getDir($this->project);
                 $files = $list->getFiles($this->project);
                 foreach ($files as $file) {
                     $this->appendFile($writer, new PhingFile($dir, $file));
                 }
             }
         }
     } catch (Exception $e) {
         throw new BuildException($e);
     }
     $writer->close();
 }