diff options
author | Christian Schneider | 2007-10-02 13:11:40 +0000 |
---|---|---|
committer | Christian Schneider | 2007-10-02 13:11:40 +0000 |
commit | caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1 (patch) | |
tree | 6e5ecb261a3b72a0a288bc80be35cbb6f4e70e3d | |
parent | d3bc458e433859e5ae4b517240839db698a28f09 (diff) | |
download | itools-caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1.tar.gz itools-caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1.tar.bz2 itools-caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1.zip |
Added function it::createconfig()
-rw-r--r-- | it.class | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -23,6 +23,45 @@ class it { + +/** + * Create config class with static members initialized (e.g. $home). + * NOTE: PHP5 ONLY + * @param $p Static members to be generated in newly created class + * service: Class name of created class (default: from caller path) + * home: Home directory of application (default: from caller path) + * site: Domain name of application (default: from caller path) + * db: Database of application (default: from caller path) + */ +function createconfig($p = array()) +{ + $stack = debug_backtrace(); + $filename = $stack[0]['file']; + preg_match('!/www/((\w+)[^/]+)!', $filename, $parts); + + $p += array( + 'home' => $parts[0], + 'site' => $parts[1], + 'db' => strtr($parts[1], ".-", "__"), + 'service' => $parts[2], + ); + + if ($file = @fopen($p['service'] . "_tools.class", "r", true)) + { + $extends = "extends {$p['service']}_tools "; + fclose($file); + } + + $code = array("class {$p['service']} $extends{"); + + foreach ($p as $name => $value) + $code[] = "static \$$name = " . var_export($value, true) . ";"; + + $code[] = "}"; + eval(join("\n", $code)); +} + + /** * Clone an object and return copy, works for all PHP versions */ |