add @todo note
[phpt.git] / src / PHPT / Section / INI.php
blob78e654a64cb6d949f8938f5dc51bb77513101e9b
1 <?php
3 class PHPT_Section_INI extends PHPT_Section_ModifiableAbstract implements PHPT_Section_RunnableBefore
5 private $_default_values = array(
6 'output_handler' => '',
7 'open_basedir' => '',
8 'safe_mode' => '0',
9 'disable_functions' => '',
10 'output_buffering' => 'Off',
11 'display_errors' => '1',
12 'log_errors' => '0',
13 'html_errors' => '0',
14 'track_errors' => '1',
15 'report_memleaks' => '0',
16 'report_zend_debug' => '0',
17 'docref_root' => '',
18 'docref_ext' => '.html',
19 'error_prepend_string' => '',
20 'error_append_string' => '',
21 'auto_prepend_file' => '',
22 'auto_append_file' => '',
23 'magic_quotes_runtime' => '0',
24 'xdebug.default_enable' => '0',
25 'allow_url_fopen' => '1',
28 public $data = array();
29 private $_raw_data = null;
30 private $_case = null;
32 public function __construct($data = '')
34 parent::__construct($data);
35 $this->_raw_data = $data;
38 public function run(PHPT_Case $case)
40 parent::run($case);
41 $this->_case = $case;
42 if (!empty($this->_raw_data)) {
43 $this->data = $this->_loadFromFileAndParseIni($this->_raw_data);
44 } elseif (file_exists($this->_getPhpIni($case))) {
45 $this->data = $this->_loadFromFileAndParseIni($this->_getPhpIni($case));
48 if (isset(PHPT_Registry::getInstance()->opts['ini'])) {
49 $this->data = array_merge(
50 $this->_parseIni(PHPT_Registry::getInstance()->opts['ini'], ','),
51 $this->data
55 $this->data = array_merge($this->data, $this->_default_values);
58 public function getPriority()
60 return 0;
63 private function _loadFromFileAndParseIni($data, $separator = PHP_EOL)
65 if (is_file($data)) {
66 $data = file_get_contents($data);
67 } else {
68 $php = new PHPT_Util_Code($data);
69 if ($php->isValid()) {
70 $data = $php->runAsFile($this->_case->filename . '.ini');
71 if (is_file($data)) {
72 $data = file_get_contents($data);
76 return $this->_parseIni($data, $separator);
79 private function _parseIni($raw_data, $separator = PHP_EOL)
81 $return = array();
82 $lines = explode($separator, $raw_data);
83 foreach ($lines as $line) {
84 $pair = explode('=', $line, 2);
85 $return[trim($pair[0])] = trim($pair[1]);
87 return $return;
90 private function _getPhpIni(PHPT_Case $case) {
91 return dirname($case->filename) . '/php.ini';
94 public function __toString()
96 $string = '';
97 foreach ($this->data as $key => $value) {
98 if (!empty($string)) {
99 $string .= " ";
101 $string .= "-d \"{$key}={$value}\"";
103 return $string;