summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
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
*/