Permalink
Browse files

Removing last remaining exceptions for #162

  • Loading branch information...
1 parent 4536283 commit b7be8966d658cc62b23f8b62f833372503691024 @zyxist zyxist committed Oct 31, 2010
@@ -279,7 +279,10 @@ public function _prepareTemplateVar($name)
} // end _prepareTemplateVar();
/**
- * Compiles a language variable.
+ * Compiles a language variable. If the language variable call is not
+ * supported, an exception is thrown.
+ *
+ * @throws Opt_Compiler_Exception
* @param string $group The group name
* @param string $id The message ID name
* @param int $weight The token weight
@@ -289,7 +292,7 @@ public function _compileLanguageVar($group, $id, $weight)
{
if($this->_tpl->getTranslationInterface() == null)
{
- throw new Opt_NotSupported_Exception('language variable call', 'no translation interface installed');
+ throw new Opt_Compiler_Exception('The language variable call is not supported: no translation interface installed');
}
$array = new SplFixedArray(4);
@@ -560,7 +563,7 @@ public function _compileVariable(array $variable, $type, $weight, $context = 0,
if($context > 0 && !$format->property($hook))
{
- throw new Opt_OperationNotSupported_Exception($path, $this->_dfCalls[$context]);
+ throw new Opt_Compiler_Exception('Unsupported operation for '.$path.': '.$this->_dfCalls[$context]);
}
$code .= $format->get($hook);
}
@@ -985,8 +988,10 @@ public function _buildObjectFieldDynamic(SplFixedArray $variable, $current)
} // end _buildObjectFieldDynamic();
/**
- * Processes the object access operator from a static class.
+ * Processes the object access operator from a static class. An exception
+ * is thrown, if the direct object access is disabled.
*
+ * @throws Opt_Compiler_Exception
* @param string $className The static class name
* @param string $current The class field name
* @return SplFixedArray
@@ -995,12 +1000,12 @@ public function _buildObjectFieldStatic($className, $current)
{
if(!$this->_tpl->allowObjects)
{
- throw new Opt_NotSupported_Exception('direct object access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct object access: disabled by the configuration');
}
if(($compiled = $this->_compiler->isClass($token)) !== null)
{
- throw new Opt_ItemNotAllowed_Exception('Class', $className);
+ throw new Opt_Compiler_Exception('The class \''.$className.'\' is not allowed to be used in templates.');
}
$variable = new SplFixedArray(4);
$variable[0] = $compiled.'::$'.(string)$current;
@@ -1021,7 +1026,7 @@ public function _buildObjectFieldNext(SplFixedArray $variable, $current)
{
if(!$this->_tpl->allowObjects)
{
- throw new Opt_NotSupported_Exception('direct object access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct object access: disabled by the configuration');
}
$variable[0] .= '->'.(string)$current;
@@ -1041,7 +1046,7 @@ public function _buildMethodDynamic(SplFixedArray $variable, $current)
{
if(!$this->_tpl->allowObjects)
{
- throw new Opt_NotSupported_Exception('direct object access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct object access: disabled by the configuration');
}
$variable = $this->_compileVariable($variable[0], $variable[1], 0);
@@ -1078,12 +1083,12 @@ public function _buildMethodStatic($className, $current)
{
if(!$this->_tpl->allowObjects)
{
- throw new Opt_NotSupported_Exception('direct class access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct class access: disabled by the configuration');
}
if(($compiled = $this->_compiler->isClass($className)) === null)
{
- throw new Opt_ItemNotAllowed_Exception('Class', $className);
+ throw new Opt_Compiler_Exception('The class \''.$className.'\' is not allowed to be used in templates.');
}
$variable = new SplFixedArray(4);
$variable[0] = $compiled.'::'.(string)$current[0].'(';
@@ -1120,7 +1125,7 @@ public function _buildMethodNext(SplFixedArray $variable, $current)
{
if(!$this->_tpl->allowObjects)
{
- throw new Opt_NotSupported_Exception('direct object access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct object access: disabled by the configuration');
}
$variable[0] .= '->'.(string)$current[0].'(';
@@ -1156,7 +1161,7 @@ public function _buildArrayDynamic(SplFixedArray $variable, SplFixedArray $curre
{
if(!$this->_tpl->allowArrays)
{
- throw new Opt_NotSupported_Exception('direct array access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct array access: disabled by the configuration');
}
$variable = $this->_compileVariable($variable[0], $variable[1], 0);
@@ -1180,7 +1185,7 @@ public function _buildArrayNext(SplFixedArray $variable, SplFixedArray $current)
{
if(!$this->_tpl->allowArrays)
{
- throw new Opt_NotSupported_Exception('direct array access', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported direct array access: disabled by the configuration');
}
$variable[0] .= '['.(string)$current[0].']';
@@ -1201,7 +1206,7 @@ public function _objective($action, $what, $weight)
{
if(!$this->_tpl->allowObjects || !$this->_tpl->allowObjectCreation)
{
- throw new Opt_NotSupported_Exception('object creation', 'disabled by the configuration');
+ throw new Opt_Compiler_Exception('Unsupported object creation: disabled by the configuration');
}
switch($action)
{
@@ -1214,7 +1219,7 @@ public function _objective($action, $what, $weight)
case 'new':
if(($compiled = $this->_compiler->isClass($what[0])) === null)
{
- throw new Opt_ItemNotAllowed_Exception('Class', $what[0]);
+ throw new Opt_Compiler_Exception('The class \''.$what[0].'\' is not allowed to be used in templates.');
}
$answer = new SplFixedArray(4);
$answer[0] = 'new '.$compiled;
@@ -208,16 +208,6 @@ public function dispose()
}
else
{
- /*
- * DO NOT REMOVE THE LINE BELOW UNLESS YOU WANT A SEGMENTATION FAULT!
- *
- * This piece of code activates the issue known as PHP Bug #40479 open
- * since 2007 related to the corrupted zend_mm_heap. I do not know, why
- * throwing an exception in this place causes this after a while (the
- * segfault occurs, when this exception is captured in the compile() method
- * to clean the compiler state).
- */
- // die('Opt_APIHookNotDefined_Exception: Invalid hook name: '.$hookName.' in '.get_class($this));
throw new Opt_Format_Exception('Invalid hook name: '.$hookName.' in '.get_class($this));
}
}
@@ -67,7 +67,7 @@ protected function _build($hookName)
// of "section" namespace.
if(!is_object($this->_decorated))
{
- throw new Opt_FormatNotDecorated_Exception('StaticGenerator');
+ throw new Opt_Format_Exception('The StaticGenerator format must be decorated.');
}
return ' $_sect'.$section['name'].'_vals = array(); if('.$ds.' instanceof Opt_Generator_Interface){ $_sect'.$section['name'].'_vals = '.$ds.'->generate(\''.$section['name'].'\'); } ';
View
@@ -782,24 +782,4 @@ static public function buildAttributes($attributes, $ignoreList = array(), $prep
}
return rtrim($prepend);
} // end buildAttributes();
-
- /**
- * Performs a safe template procedure call. Before that, it checks for
- * the existence of a procedure and if it does not exist, it throws
- * an exception.
- *
- * @throws Opt_ObjectNotExists_Exception
- * @param Opt_View $view The current view instance.
- * @param string $name The procedure name
- * @param array $arguments The list of procedure argument values
- */
- static public function call(Opt_InternalContext $ctx, $name, array $arguments)
- {
- if(function_exists('__optFunc_'.$name))
- {
- $arguments[0] = $ctx;
- return call_user_func_array('__optFunc_'.$name, $arguments);
- }
- throw new Opt_ObjectNotExists_Exception('template procedure', $name);
- } // end call();
} // end Opt_Function;
@@ -630,7 +630,6 @@ public function processSystemVar($opt)
if(strlen(trim($value)) == 0)
{
throw new Opt_Instruction_Exception('The attribute "'.$attr->getXmlName().'" in '.$item->getXmlName().' is empty.');
- throw new Opt_AttributeEmpty_Exception($attr->getXmlName(), $item->getXmlName());
}
// if(preg_match('/^([a-zA-Z0-9\_]{2,})\:([^\:].*)$/', $value, $found))
// {
@@ -182,7 +182,7 @@ public function processNode(Opt_Xml_Node $node)
{
if($value == 'required')
{
- $code .= 'if(!isset($args['.$i.'])){ throw new Opt_SnippetArgumentNotDefined_Exception(\''.$name.'\', \''.$params['snippet'].'\'); } '.PHP_EOL;
+ $code .= 'if(!isset($args['.$i.'])){ throw new Opt_Runtime_Exception(\'Snippet argument not defined: '.$name.' in '.$params['snippet'].'\'); } '.PHP_EOL;
}
else
{
@@ -150,7 +150,7 @@ protected function _processItem(Opt_Xml_Node $node)
{
if(is_null($node->get('priv:section')))
{
- throw new Opt_InstructionInvalidLocation_Exception('opt:item', 'opt:grid');
+ throw new Opt_Instruction_Exception('opt:item should be located in opt:grid.');
}
// We're at home. For this particular node we have to activate the section.
@@ -180,7 +180,7 @@ protected function _processEmptyitem(Opt_Xml_Node $node)
{
if(is_null($node->get('priv:section')))
{
- throw new Opt_InstructionInvalidLocation_Exception('opt:item', 'opt:grid');
+ throw new Opt_Instruction_Exception('opt:item should be located in opt:grid.');
}
$section = $node->get('priv:section');
$node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, ' if($_'.$section['name'].'_remain > 0 && !'.$node->get('priv:valid').') { for($_'.$section['name'].'_k = 0; $_'.$section['name'].'_k < $_'.$section['name'].'_remain; $_'.$section['name'].'_k++) { ');
@@ -176,7 +176,7 @@ protected function _postprocessSelector(Opt_Xml_Node $node)
* Processes the opt:selectorelse element.
* @internal
* @param Opt_Xml_Element $node
- * @throws Opt_InstructionInvalidParent_Exception
+ * @throws Opt_Instruction_Exception
*/
protected function _processElse(Opt_Xml_Element $node)
{
@@ -194,9 +194,10 @@ protected function _processElse(Opt_Xml_Element $node)
}
else
{
- throw new Opt_InstructionInvalidParent_Exception($node->getXmlName(), 'opt:section');
+ // Perhaps unreachable, unless some bug in the code occurs.
+ throw new Opt_Instruction_Exception('Invalid parent of \'opt:else\' node: '.$node->getXmlName());
}
- } // end _processSelectorelse();
+ } // end _processElse();
/**
* Processes the attribute version of opt:selector
@@ -210,12 +210,7 @@ public function _processSnippet(Opt_Xml_Element $node)
$this->_snippets[$params['name']][] = $node;
}
$node->unmount();
- /*
- if($node->getParent()->removeChild($node) == 0)
- {
- throw new Opl_Debug_Exception();
- }
- */
+
// Remember the template state of escaping for this snippet.
// This is necessary to make per-template escaping work with
// the inheritance.
@@ -364,7 +359,7 @@ public function useSnippet(Opt_Xml_Node $node, $snippetName, array $arguments, $
if($it == $snippetName)
{
$this->_current->push($snippetName);
- $err = new Opt_SnippetRecursion_Exception($snippetName);
+ $err = new Opt_Compiler_Recursion_Exception('Infinite snippet recursion detected in \''.$snippetName.'\' snippet.');
throw $err->setData($this->_current);
}
}
@@ -513,15 +508,15 @@ public function postuseSnippet(Opt_Xml_Node $node)
/**
* Returns the list of arguments of the specified snippet.
*
- * @throws Opt_SnippetNotFound_Exception
+ * @throws Opt_Instrcution_Exception
* @param string $snippetName The snippet name.
* @return array
*/
public function getArguments($snippetName)
{
if(!isset($this->_arguments[$snippetName]))
{
- throw new Opt_SnippetNotFound_Exception($snippetName);
+ throw new Opt_Instrcution_Exception('The requested snippet \''.$snippetName.'\' is not defined.');
}
return $this->_arguments[$snippetName];
} // end getArguments();
@@ -156,13 +156,13 @@ public function postprocessNode(Opt_Xml_Node $node)
* @internal
* @param Opt_Xml_Node $node XML node.
* @param Opt_Xml_Attribute $attr XML attribute.
- * @throws Opt_AttributeInvalidNamespace_Exception
+ * @throws Opt_Instruction_Exception
*/
public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr)
{
if($this->_compiler->isNamespace($node->getNamespace()))
{
- throw new Opt_AttributeInvalidNamespace_Exception($node->getXmlName());
+ throw new Opt_Instruction_Exception('The attribute \''.$node->getXmlName().'\' uses the invalid namespace.');
}
if($attr->getValue() == 'yes')
{
View
@@ -107,6 +107,11 @@ public function __toString()
/**
* Validates the inserted text.
+ *
+ * Throws an exception, if the validated text contains special <> XML
+ * symbols.
+ *
+ * @throws Opt_Xml_Exception
* @param String $text The text to validate
* @return Boolean
*/
@@ -119,7 +124,7 @@ protected function _validate(&$text)
}
if(strcspn($text, '<>') != strlen($text))
{
- throw new Opt_XmlInvalidCharacter_Exception(htmlspecialchars($text));
+ throw new Opt_Xml_Exception('Invalid symbols in the character data: '.htmlspecialchars($text));
}
return true;
} // end _validate();
View
@@ -759,7 +759,7 @@ protected function _linkAttributes(Opt_Compiler_Class $compiler)
$code .= ($attribute->bufferSize(Opt_Xml_Buffer::ATTRIBUTE_BEGIN) == 0 ? ' ' : '').$attribute->buildCode(Opt_Xml_Buffer::ATTRIBUTE_BEGIN, ' ', Opt_Xml_Buffer::ATTRIBUTE_NAME);
break;
default:
- throw new Opt_CompilerCodeBufferConflict_Exception(1, 'ATTRIBUTE_NAME', $this->getXmlName());
+ throw new Opt_Xml_Exception('Compiler code buffer conflict: the buffer \'ATTRIBUTE_NAME\' in '.$this->getXmlName().' can contain at most one code block.');
}
if($attribute->bufferSize(Opt_Xml_Buffer::ATTRIBUTE_VALUE) == 0)
@@ -290,6 +290,7 @@ public function moveChildren(Opt_Xml_Scannable $node)
* Replaces the child with the new node. The reference node can be
* identified either by the number or by the object.
*
+ * @throws Opt_Xml_Exception
* @param Opt_Xml_Node $newnode The new node.
* @param integer|Opt_Xml_Node $refnode The old node.
* @return boolean
@@ -322,7 +323,7 @@ public function replaceChild(Opt_Xml_Node $newnode, $refnode)
// Now, do the replacement.
if($refnode->_parent !== $this)
{
- throw new Opt_APIInvalidBorders_Exception;
+ throw new Opt_Xml_Exception('Cannot perform replaceChild(): invalid referenced node.');
}
if($this->_iterator === $refnode)
@@ -921,9 +922,9 @@ public function key()
/**
* Checks whether the node can be added to this collection. If the specified
* node cannot be inserted into a collection, the method is supposed to
- * return 'Opt_APIInvalidNodeType_Exception'
+ * throw 'Opt_Xml_Exception'
*
- * @throws Opt_APIInvalidNodeType_Exception
+ * @throws Opt_Xml_Exception
* @param Opt_Xml_Node $node The node to test
*/
protected function _testNode(Opt_Xml_Node $node)

0 comments on commit b7be896

Please sign in to comment.