]> git.andy128k.dev Git - ipf-template.git/commitdiff
unify exceptions
authorAndrey Kutejko <andy128k@gmail.com>
Tue, 30 Jul 2013 21:36:24 +0000 (00:36 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Tue, 30 Jul 2013 21:36:24 +0000 (00:36 +0300)
ipf/exception.php
ipf/exception/template.php [deleted file]
ipf/template/compiler.php
ipf/template/environment.php
ipf/template/environment/filesystem.php

index ef36fc77d7ef9489c8551b2ef4d9211b938594ba..2aa9755c04f6149683b4f20c6bf3ca47b038c323 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-class IPF_Exception extends Exception
+class IPF_Template_Exception extends Exception
 {
 }
 
diff --git a/ipf/exception/template.php b/ipf/exception/template.php
deleted file mode 100644 (file)
index a642149..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-class IPF_Exception_Template extends IPF_Exception{}
index f28cca5c50f0b3e3ff94304eec3f8363d1f34445..003e1c2f1241654999c0568a33f62eb3858d73a7 100644 (file)
@@ -61,7 +61,7 @@ class IPF_Template_Compiler
                                         array($this, '_callback'),
                                         $tplcontent);
         if (count($this->_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).'<?php ';
             } else {
-                trigger_error(__('End tag of a block missing: literal'), E_USER_ERROR);
+                trigger_error('End tag of a block missing: literal', E_USER_ERROR);
             }
             break;
         case '/literal':
-            trigger_error(__('Start tag of a block missing: literal'), E_USER_ERROR);
+            trigger_error('Start tag of a block missing: literal', E_USER_ERROR);
             break;
         case 'block':
             if (isset($this->_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;
                 }
index 8141715579ea4c3045c30c5f8768db57f74cb8d6..eb7834fa773622419855a1d62445c5948d05de5a 100644 (file)
@@ -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.');
     }
 }
 
index 8eb8d6581c87b80a3f450f32f30be29877f08a64..2d4f4b81548227f30c500cc4e1ac4e7b5f9440b2 100644 (file)
@@ -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;
     }