From d81328dc00c38130ea825d70ea0fcb41c3694ed0 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Wed, 31 Jul 2013 00:36:24 +0300 Subject: [PATCH] unify exceptions --- ipf/exception.php | 2 +- ipf/exception/template.php | 3 --- ipf/template/compiler.php | 32 ++++++++++++------------- ipf/template/environment.php | 4 ++-- ipf/template/environment/filesystem.php | 6 ++--- 5 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 ipf/exception/template.php diff --git a/ipf/exception.php b/ipf/exception.php index ef36fc7..2aa9755 100644 --- a/ipf/exception.php +++ b/ipf/exception.php @@ -1,6 +1,6 @@ _blockStack)) { - trigger_error(sprintf(__('End tag of a block missing: %s'), end($this->_blockStack)), E_USER_ERROR); + trigger_error(sprintf('End tag of a block missing: %s', end($this->_blockStack)), E_USER_ERROR); } return $result; } @@ -100,7 +100,7 @@ class IPF_Template_Compiler } if ($count != 0) - throw new IPF_Exception(sprintf(__('Blocks are not nested properly.'))); + throw new IPF_Template_Exception('Blocks are not nested properly.'); return $result; } @@ -147,7 +147,7 @@ class IPF_Template_Compiler { list(,$tag, $firstcar) = $matches; if (!preg_match('/^\$|[\'"]|[a-zA-Z\/]$/', $firstcar)) { - trigger_error(sprintf(__('Invalid tag syntax: %s'), $tag), E_USER_ERROR); + trigger_error(sprintf('Invalid tag syntax: %s', $tag), E_USER_ERROR); return ''; } if (in_array($firstcar, array('$', '\'', '"'))) { @@ -160,7 +160,7 @@ class IPF_Template_Compiler } } else { if (!preg_match('/^(\/?[a-zA-Z0-9_]+)(?:(?:\s+(.*))|(?:\((.*)\)))?$/', $tag, $m)) { - trigger_error(sprintf(__('Invalid function syntax: %s'), $tag), E_USER_ERROR); + trigger_error(sprintf('Invalid function syntax: %s', $tag), E_USER_ERROR); return ''; } if (count($m) == 4){ @@ -183,12 +183,12 @@ class IPF_Template_Compiler $res = $this->_parseFinal(array_shift($tok), self::$allowedInVar); foreach ($tok as $modifier) { if (!preg_match('/^(\w+)(?:\:(.*))?$/', $modifier, $m)) { - trigger_error(sprintf(__('Invalid modifier syntax: (%s) %s'), $expr, $modifier), E_USER_ERROR); + trigger_error(sprintf('Invalid modifier syntax: (%s) %s', $expr, $modifier), E_USER_ERROR); return ''; } if ($this->environment->hasModifier($m[1])) { - trigger_error(sprintf(__('Unknown modifier: (%s) %s'), $expr, $m[1]), E_USER_ERROR); + trigger_error(sprintf('Unknown modifier: (%s) %s', $expr, $m[1]), E_USER_ERROR); return ''; } @@ -212,13 +212,13 @@ class IPF_Template_Compiler break; case 'else': if (end($this->_blockStack) != 'if') { - trigger_error(sprintf(__('End tag of a block missing: %s'), end($this->_blockStack)), E_USER_ERROR); + trigger_error(sprintf('End tag of a block missing: %s', end($this->_blockStack)), E_USER_ERROR); } $res = 'else: '; break; case 'elseif': if (end($this->_blockStack) != 'if') { - trigger_error(sprintf(__('End tag of a block missing: %s'), end($this->_blockStack)), E_USER_ERROR); + trigger_error(sprintf('End tag of a block missing: %s', end($this->_blockStack)), E_USER_ERROR); } $res = 'elseif('.$this->_parseFinal($args, self::$allowedInExpr).'):'; break; @@ -251,7 +251,7 @@ class IPF_Template_Compiler break; case '/foreach': if(end($this->_blockStack) != 'foreach'){ - trigger_error(sprintf(__('End tag of a block missing: %s'), end($this->_blockStack)), E_USER_ERROR); + trigger_error(sprintf('End tag of a block missing: %s', end($this->_blockStack)), E_USER_ERROR); } array_pop($this->_blockStack); $res = @@ -265,7 +265,7 @@ class IPF_Template_Compiler case '/while': $short = substr($name,1); if(end($this->_blockStack) != $short){ - trigger_error(sprintf(__('End tag of a block missing: %s'), end($this->_blockStack)), E_USER_ERROR); + trigger_error(sprintf('End tag of a block missing: %s', end($this->_blockStack)), E_USER_ERROR); } array_pop($this->_blockStack); $res = 'end'.$short.'; '; @@ -277,11 +277,11 @@ class IPF_Template_Compiler if (count($this->_literals)) { $res = '?>'.array_shift($this->_literals).'_extendBlocks[$args])) @@ -310,7 +310,7 @@ class IPF_Template_Compiler case '/blocktrans': $short = substr($name,1); if(end($this->_blockStack) != $short){ - trigger_error(sprintf(__('End tag of a block missing: %s'), end($this->_blockStack)), E_USER_ERROR); + trigger_error(sprintf('End tag of a block missing: %s', end($this->_blockStack)), E_USER_ERROR); } $res = ''; if ($this->_transPlural) { @@ -364,7 +364,7 @@ class IPF_Template_Compiler // Here we start the template tag calls at the template tag // {tag ...} is not a block, so it must be a function. if (!$this->environment->isTagAllowed($name)) { - trigger_error(sprintf(__('The function tag "%s" is not allowed.'), $name), E_USER_ERROR); + trigger_error(sprintf('The function tag "%s" is not allowed.', $name), E_USER_ERROR); } // $argfct is a string that can be copy/pasted in the PHP code // but we need the array of args. @@ -398,11 +398,11 @@ class IPF_Template_Compiler } elseif (in_array($type, $allowed)) { $result[] = $tok; } else { - throw new IPF_Exception_Template(sprintf(__('Invalid syntax: (%s) %s.'), $string, $str)); + throw new IPF_Template_Exception(sprintf('Invalid syntax: (%s) %s.', $string, $str)); } } else { if (in_array($tok, $exceptchar)) { - trigger_error(sprintf(__('Invalid character: (%s) %s.'), $string, $tok), E_USER_ERROR); + trigger_error(sprintf('Invalid character: (%s) %s.', $string, $tok), E_USER_ERROR); } else { $result[] = $tok; } diff --git a/ipf/template/environment.php b/ipf/template/environment.php index 8141715..eb7834f 100644 --- a/ipf/template/environment.php +++ b/ipf/template/environment.php @@ -19,7 +19,7 @@ abstract class IPF_Template_Environment if (isset($this->tags[$name])) return $this->tags[$name]; else - throw new IPF_Exception_Template('Tag '.$name.' is not defined.'); + throw new IPF_Template_Exception('Tag '.$name.' is not defined.'); } // Dictionary of modifiers (modifier name => function) @@ -55,7 +55,7 @@ abstract class IPF_Template_Environment if (isset($this->modifiers[$name])) return $this->modifiers[$name]; else - throw new IPF_Exception_Template('Modifier '.$name.' is not defined.'); + throw new IPF_Template_Exception('Modifier '.$name.' is not defined.'); } } diff --git a/ipf/template/environment/filesystem.php b/ipf/template/environment/filesystem.php index 8eb8d65..2d4f4b8 100644 --- a/ipf/template/environment/filesystem.php +++ b/ipf/template/environment/filesystem.php @@ -10,14 +10,14 @@ class IPF_Template_Environment_FileSystem extends IPF_Template_Environment { // FIXME: Very small security check, could be better. if (strpos($filename, '..') !== false) { - throw new IPF_Exception(sprintf(__('Template file contains invalid characters: %s'), $filename)); + throw new IPF_Template_Exception(sprintf('Template file contains invalid characters: %s', $filename)); } foreach ($this->folders as $folder) { if (file_exists($folder.'/'.$filename)) { return file_get_contents($folder.'/'.$filename); } } - throw new IPF_Exception(sprintf(__('Template file not found: %s'), $filename)); + throw new IPF_Template_Exception(sprintf('Template file not found: %s', $filename)); } public function getCompiledTemplateName($template) @@ -43,7 +43,7 @@ class IPF_Template_Environment_FileSystem extends IPF_Template_Environment @chmod($filename, 0777); return true; } else { - throw new IPF_Exception_Template(sprintf(__('Cannot write the compiled template: %s'), $filename)); + throw new IPF_Template_Exception(sprintf('Cannot write the compiled template: %s', $filename)); } return false; } -- 2.49.0