summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorChristian Schneider2007-10-02 13:11:40 +0000
committerChristian Schneider2007-10-02 13:11:40 +0000
commitcaacf25cfe3e5e6c233a7f7cbc7accb9600a24b1 (patch)
tree6e5ecb261a3b72a0a288bc80be35cbb6f4e70e3d /it.class
parentd3bc458e433859e5ae4b517240839db698a28f09 (diff)
downloaditools-caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1.tar.gz
itools-caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1.tar.bz2
itools-caacf25cfe3e5e6c233a7f7cbc7accb9600a24b1.zip
Added function it::createconfig()
Diffstat (limited to 'it.class')
-rw-r--r--it.class39
1 files changed, 39 insertions, 0 deletions
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
*/