S
S
SpiRi72010-12-17 14:47:56
PHP
SpiRi7, 2010-12-17 14:47:56

Phing and source code pre-processing

Interested in the issue of preprocessing the source code of the project using phing.
What does it mean
There is a source code of the form:

 protected function _doImportant() {
#ifdef DEBUG
  $this->log("doing important stuff now");
#endif
  foreach ($this->import as $moreimportant) {
#ifdef DEBUG
   $this->log("as I said, important or $moreimportant");
#endif
  }
#ifdef DEBUG
  $this->log("finished doing ach so important thing");
#endif
 }


After preprocessing, if the DEBUG directive is present/enabled

 protected function _doImportant() {
  $this->log("doing important stuff now");
  foreach ($this->import as $moreimportant) {
   $this->log("as I said, important or $moreimportant");
  }
  $this->log("finished doing ach so important thing");
 }


If not:
 protected function _doImportant() {
    foreach ($this->import as $moreimportant) {
  
    }
 }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Imenem, 2011-01-07
@Imenem

Try using Replace Regexp for this. The task allows you to implement search/replace using regular expressions. Or switch to Ant, there is a preprocessing class for it.

A
Aecktann, 2011-01-06
@Aecktann

1) What is your question? Habr is not Google :)
2) Isn't it easier to use something like this instead of preprocessing:

const DEBUG = TRUE;
protected function _doImportant() {
  if (self::DEBUG) {
    $this->log("doing important stuff now");
  }
  foreach ($this->import as $moreimportant) {
    if (self::DEBUG) {
      $this->log("as I said, important or $moreimportant");
    }
  }
  if (self::DEBUG) {
    $this->log("finished doing ach so important thing");
  }
}

Const DEBUG is in the same class because you are using $this->log().
Although I use Log::debug($message) for this, which, if Log::DEBUG == 0, does not output anything. Trying to save on this is evil, like any premature optimization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question