summaryrefslogtreecommitdiffstats
path: root/system/libraries/Parser.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Parser.php')
-rw-r--r--system/libraries/Parser.php93
1 files changed, 43 insertions, 50 deletions
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index 321248277..b64c78254 100644
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Parser Class
*
@@ -38,18 +36,33 @@
*/
class CI_Parser {
+ /**
+ * Left delimeter character for psuedo vars
+ *
+ * @var string
+ */
public $l_delim = '{';
+
+ /**
+ * Right delimeter character for psuedo vars
+ *
+ * @var string
+ */
public $r_delim = '}';
- public $object;
- private $CI;
/**
- * Parse a template
+ * Reference to CodeIgniter instance
+ *
+ * @var object
+ */
+ protected $CI;
+
+ /**
+ * Parse a template
*
* Parses pseudo-variables contained in the specified template view,
* replacing them with the data in the second param
*
- * @access public
* @param string
* @param array
* @param bool
@@ -66,12 +79,11 @@ class CI_Parser {
// --------------------------------------------------------------------
/**
- * Parse a String
+ * Parse a String
*
* Parses pseudo-variables contained in the specified string,
* replacing them with the data in the second param
*
- * @access public
* @param string
* @param array
* @param bool
@@ -85,37 +97,31 @@ class CI_Parser {
// --------------------------------------------------------------------
/**
- * Parse a template
+ * Parse a template
*
* Parses pseudo-variables contained in the specified template,
* replacing them with the data in the second param
*
- * @access private
* @param string
* @param array
* @param bool
* @return string
*/
- private function _parse($template, $data, $return = FALSE)
+ protected function _parse($template, $data, $return = FALSE)
{
- if ($template == '')
+ if ($template === '')
{
return FALSE;
}
foreach ($data as $key => $val)
{
- if (is_array($val))
- {
- $template = $this->_parse_pair($key, $val, $template);
- }
- else
- {
- $template = $this->_parse_single($key, (string)$val, $template);
- }
+ $template = is_array($val)
+ ? $this->_parse_pair($key, $val, $template)
+ : $template = $this->_parse_single($key, (string) $val, $template);
}
- if ($return == FALSE)
+ if ($return === FALSE)
{
$this->CI->output->append_output($template);
}
@@ -126,9 +132,8 @@ class CI_Parser {
// --------------------------------------------------------------------
/**
- * Set the left/right variable delimiters
+ * Set the left/right variable delimiters
*
- * @access public
* @param string
* @param string
* @return void
@@ -142,15 +147,14 @@ class CI_Parser {
// --------------------------------------------------------------------
/**
- * Parse a single key/value
+ * Parse a single key/value
*
- * @access private
* @param string
* @param string
* @param string
* @return string
*/
- private function _parse_single($key, $val, $string)
+ protected function _parse_single($key, $val, $string)
{
return str_replace($this->l_delim.$key.$this->r_delim, (string) $val, $string);
}
@@ -158,17 +162,16 @@ class CI_Parser {
// --------------------------------------------------------------------
/**
- * Parse a tag pair
+ * Parse a tag pair
*
- * Parses tag pairs: {some_tag} string... {/some_tag}
+ * Parses tag pairs: {some_tag} string... {/some_tag}
*
- * @access private
* @param string
* @param array
* @param string
* @return string
*/
- private function _parse_pair($variable, $data, $string)
+ protected function _parse_pair($variable, $data, $string)
{
if (FALSE === ($match = $this->_match_pair($string, $variable)))
{
@@ -181,14 +184,9 @@ class CI_Parser {
$temp = $match[1];
foreach ($row as $key => $val)
{
- if ( ! is_array($val))
- {
- $temp = $this->_parse_single($key, $val, $temp);
- }
- else
- {
- $temp = $this->_parse_pair($key, $val, $temp);
- }
+ $temp = is_array($val)
+ ? $this->_parse_pair($key, $val, $temp)
+ : $this->_parse_single($key, $val, $temp);
}
$str .= $temp;
@@ -200,25 +198,20 @@ class CI_Parser {
// --------------------------------------------------------------------
/**
- * Matches a variable pair
+ * Matches a variable pair
*
- * @access private
* @param string
* @param string
* @return mixed
*/
- private function _match_pair($string, $variable)
+ protected 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))
- {
- return FALSE;
- }
-
- return $match;
+ return 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)
+ ? $match : FALSE;
}
}
-// END Parser Class
/* End of file Parser.php */
-/* Location: ./system/libraries/Parser.php */
+/* Location: ./system/libraries/Parser.php */ \ No newline at end of file