From caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 2 Oct 2007 13:11:40 +0000 Subject: Added function it::createconfig() --- it.class | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'it.class') diff --git a/it.class b/it.class index 952da9e..9b5056e 100644 --- a/it.class +++ b/it.class @@ -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 */ -- cgit v1.2.3