Use callback rather than preg e modifier
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 9 Jul 2010 22:02:43 +0000 (16:02 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 12 Jul 2010 04:24:21 +0000 (22:24 -0600)
framework/Text_Filter/lib/Horde/Text/Filter/Environment.php

index 385c667..b856ddc 100644 (file)
@@ -23,10 +23,31 @@ class Horde_Text_Filter_Environment extends Horde_Text_Filter_Base
      */
     public function getPatterns()
     {
-        $regexp = array('/^#.*$\n/m' => '',
-                        '/^([^#]*)#.*$/m' => '$1',
-                        '/%([A-Za-z_]+)%/e' => 'getenv("$1")');
-        return array('regexp' => $regexp);
+        $regexp = array(
+            '/^#.*$\n/m' => '',
+            '/^([^#]*)#.*$/m' => '$1'
+        );
+
+        $regexp_callback = array(
+            '/%([A-Za-z_]+)%/e' => array($this, 'regexCallback')
+        );
+
+        return array(
+            'regexp' => $regexp,
+            'regexp_callback' => $regexp_callback
+        );
+    }
+
+    /**
+     * Preg callback.
+     *
+     * @param array $matches  preg_replace_callback() matches.
+     *
+     * @return string  The replacement string.
+     */
+    public function regexCallback($matches)
+    {
+        return getenv($matches[1]);
     }
 
 }