In my
project I needed to build different versions of the sources. And so that different pieces of code would be placed in different assemblies. If-else did not suit me here, because it was necessary that the code either entered or did not enter the assembly exactly.
Decision
So I decided to use # ifdef / # endif directives. To implement them, I created a small C # program that processes these directives. In the program you need to specify the source file or folder, and the folder where you want to place the finished result. Only php files are processed for directives, the rest are simply copied.
Work program
The program has a global array defined, which is created from the third field ("Defines (comma separated)"). This array can be supplemented with the "#define TEXT" directive in php code.
The program can handle the following directives: "#ifdef TEXT", "#ifndef TEXT". The first includes the code if the directive is defined, the second includes if not defined. These directives must have closing "#endif".
The same program can handle "#else" and nesting of these directives.
Conclusion
Since in php the “#” symbol defines a comment, the code can be executed without cutting out these directives.
However, if you use "#ifdef - #else - #endif" with code that performs various actions with the same data, you need to comment out one of these actions in order to execute it without cutting out directives like this:
')
<?php
#ifdef COPY
$chat_page = new View('copy');
$chat_page->SetVars(array('copyright' => $this->Copyright()));
$this->html = $chat_page->Get();
$this->Display();
/*#else
$this->html = View('no_copy')::Call();
$this->Display();
*/#endif
?>
Download the program here:
phpifdef.googlecode.com/files/Php%20Ifdef%20Collector.exeProgram sources here:
code.google.com/p/phpifdef