1: <?php
2: /**
3: * Replaces occurences of %VAR% with VAR, if VAR exists in the webserver's
4: * environment. Ignores all text after a '#' character (shell-style
5: * comments).
6: *
7: * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
8: *
9: * See the enclosed file COPYING for license information (LGPL). If you
10: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
11: *
12: * @author Jan Schneider <jan@horde.org>
13: * @category Horde
14: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15: * @package Text_Filter
16: */
17: class Horde_Text_Filter_Environment extends Horde_Text_Filter_Base
18: {
19: /**
20: * Returns a hash with replace patterns.
21: *
22: * @return array Patterns hash.
23: */
24: public function getPatterns()
25: {
26: $regexp = array(
27: '/^#.*$\n/m' => '',
28: '/^([^#]*)#.*$/m' => '$1'
29: );
30:
31: $regexp_callback = array(
32: '/%([A-Za-z_]+)%/' => array($this, 'regexCallback')
33: );
34:
35: return array(
36: 'regexp' => $regexp,
37: 'regexp_callback' => $regexp_callback
38: );
39: }
40:
41: /**
42: * Preg callback.
43: *
44: * @param array $matches preg_replace_callback() matches.
45: *
46: * @return string The replacement string.
47: */
48: public function regexCallback($matches)
49: {
50: return getenv($matches[1]);
51: }
52:
53: }
54: