PHP Macro Preprocessor
phrep is a command-line macro preprocessor for PHP code.
- It handles C-style processing directives like
#define
,#include
,#if
,#ifdef
,#elif
,#else
,#endif
,#undef
,#pragma
,#stderr
,#srcout
. - Applies constants and standard macro substitutions only within code sections.
- Also allows more complex MACRO@() transformations per PHP inline callbacks.
- Is somewhat compatible with cpp / preprocess / phpp,
can read C header
.h
files. - Otherwise leaves comments and code structure intact.
It's intended as static configuration tool...
- Can be used within trivial makefiles, or slim packaging scripts.
- Useful for simple code templating or one-off generation tasks.
- And reduces runtime softcoding, as it allows code-embedded feature branches.
Usage
Preprocessing a source script is as simple as:
phrep -i config.src -o config.php -D PKG_USE_SQLITE=1
Where source files might look (well, in complex cases) like this:
<?php
#if __PHP_VERSION__ >= 5.4 && defined(PKG_USE_SQLITE)
#pragma(dirs=./includes)
#include <sqlite.ph>
#else
include("./lib/basic_db.php");
#ifdef PKG_DB_EXTENSION
$db->option = PKG_DB_EXTENSION;
#endif
#endif
Most preprocessor constants are just meant for conditional sectioning. But
they can also be substituted in PHP code blocks. Just like macros such as
HTML@(<a link="$var">…)
or even PARAMETERIZE@(select :$x FROM y WHERE z=$z)
.
Status
- Experimental / development
- Command line -flags don't completely map all #pragma directives yet.
- #if expressions are mostly usable already.
- No composer-plugin yet defined.
- A man page exists.
Download
- Use the zip or tar for literal sources.
- Get the combined phrep script.
- Or install phrep per phrep-0.3.0.deb / phrep-0.3.0.rpm directly.
- Updates are announced via http://freshcode.club/projects/macro.php