From ee3bc29f39819cf6cabcc593162982e95c6e08dd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 24 Dec 2011 01:44:13 +0200 Subject: Improve the Parser library --- system/libraries/Parser.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'system/libraries/Parser.php') diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 0e6ab63d8..39aa61e45 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -1,13 +1,13 @@ -load->view($template, $data, TRUE); + $this->CI =& get_instance(); + $template = $this->CI->load->view($template, $data, TRUE); return $this->_parse($template, $data, $return); } @@ -76,7 +77,7 @@ class CI_Parser { * @param bool * @return string */ - function parse_string($template, $data, $return = FALSE) + public function parse_string($template, $data, $return = FALSE) { return $this->_parse($template, $data, $return); } @@ -89,13 +90,13 @@ class CI_Parser { * Parses pseudo-variables contained in the specified template, * replacing them with the data in the second param * - * @access public + * @access private * @param string * @param array * @param bool * @return string */ - function _parse($template, $data, $return = FALSE) + private function _parse($template, $data, $return = FALSE) { if ($template == '') { @@ -116,8 +117,7 @@ class CI_Parser { if ($return == FALSE) { - $CI =& get_instance(); - $CI->output->append_output($template); + $this->CI->output->append_output($template); } return $template; @@ -133,7 +133,7 @@ class CI_Parser { * @param string * @return void */ - function set_delimiters($l = '{', $r = '}') + public function set_delimiters($l = '{', $r = '}') { $this->l_delim = $l; $this->r_delim = $r; @@ -150,9 +150,9 @@ class CI_Parser { * @param string * @return string */ - function _parse_single($key, $val, $string) + private function _parse_single($key, $val, $string) { - return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); + return str_replace($this->l_delim.$key.$this->r_delim, (string) $val, $string); } // -------------------------------------------------------------------- @@ -168,7 +168,7 @@ class CI_Parser { * @param string * @return string */ - function _parse_pair($variable, $data, $string) + private function _parse_pair($variable, $data, $string) { if (FALSE === ($match = $this->_match_pair($string, $variable))) { @@ -178,7 +178,7 @@ class CI_Parser { $str = ''; foreach ($data as $row) { - $temp = $match['1']; + $temp = $match[1]; foreach ($row as $key => $val) { if ( ! is_array($val)) @@ -194,7 +194,7 @@ class CI_Parser { $str .= $temp; } - return str_replace($match['0'], $str, $string); + return str_replace($match[0], $str, $string); } // -------------------------------------------------------------------- @@ -207,7 +207,7 @@ class CI_Parser { * @param string * @return mixed */ - function _match_pair($string, $variable) + private function _match_pair($string, $variable) { if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match)) { -- cgit v1.2.3-24-g4f1b