Index: branches/RC/core/kernel/nparser/ntags.php
===================================================================
diff -u -N -r8968 -r10604
--- branches/RC/core/kernel/nparser/ntags.php (.../ntags.php) (revision 8968)
+++ branches/RC/core/kernel/nparser/ntags.php (.../ntags.php) (revision 10604)
@@ -10,6 +10,13 @@
var $Parser = null;
var $Tag = null;
+ /**
+ * Contains parameter names, that should be given to tag in any case
+ *
+ * @var Array
+ */
+ var $_requiredParams = Array ();
+
function _BlockTag($tag)
{
parent::kBase();
@@ -18,10 +25,36 @@
function Open($tag)
{
+ if (!$this->_checkRequiredParams($tag)) {
+ return false;
+ }
+ return '';
}
/**
+ * Checks, that all required attributes for tag are passed
+ *
+ * @param Array $tag
+ * @return bool
+ */
+ function _checkRequiredParams($tag)
+ {
+ $missing_params = array_diff($this->_requiredParams, array_keys($tag['NP']));
+ if (!$missing_params) {
+ return true;
+ }
+
+ $error_msg = 'Tag ' . $this->Parser->TagInfo($tag, true) . ' called without required ' . implode(', ', $missing_params) . ' attribute';
+ if (count($missing_params) > 1) {
+ $error_msg .= '(-s)';
+ }
+
+ $this->Application->handleError(E_USER_ERROR, $error_msg, $tag['file'], $tag['line']);
+ return false;
+ }
+
+ /**
* All tags inside block tag are passed through to this method
* Any returned result is appened to current level's buffer
* This can be used to implement special handling of such tags as
@@ -46,6 +79,7 @@
}
class _Tag_Comment extends _BlockTag {
+
function PassThrough(&$tag)
{
$tag['processed'] = true;
@@ -59,9 +93,16 @@
class _Tag_DefineElement extends _BlockTag {
+ function _Tag_DefineElement($tag)
+ {
+ parent::_BlockTag($tag);
+
+ $this->_requiredParams = Array ('name');
+ }
+
function Open($tag)
{
- $o = '';
+ $o = parent::Open($tag);
$f_name = $tag['NP']['name'].'_'.abs(crc32($tag['file'])).'_'.$tag['line'];
@@ -97,8 +138,20 @@
}
class _Tag_Capture extends _Tag_DefineElement {
+
+ function _Tag_Capture($tag)
+ {
+ parent::_Tag_DefineElement($tag);
+
+ $this->_requiredParams = Array ('to_var');
+ }
+
function Open($tag)
{
+ if (!$this->_checkRequiredParams($tag)) {
+ return false;
+ }
+
$tag['NP']['name'] = '__capture_'.$tag['NP']['to_var'];
$o = '';
@@ -112,8 +165,21 @@
var $Single = true;
var $OriginalTag;
+ function _Tag_RenderElement($tag)
+ {
+ parent::_Tag_DefineElement($tag);
+
+ if (!$tag['is_closing']) {
+ $this->_requiredParams = Array ('design');
+ }
+ }
+
function Open($tag)
{
+ if (!$this->_checkRequiredParams($tag)) {
+ return false;
+ }
+
$o = '';
if ($tag['is_closing']) {
if (isset($tag['NP']['design'])) {
@@ -150,9 +216,18 @@
}
class _Tag_Param extends _BlockTag {
+
+ function _Tag_Param($tag)
+ {
+ parent::_BlockTag($tag);
+
+ $this->_requiredParams = Array ('name');
+ }
+
function Open($tag)
{
- $o = '';
+ $o = parent::Open($tag);
+
$code[] = "if (isset(\$_parser->Captures['{$tag['NP']['name']}'])) {";
$code[] = "\${$tag['NP']['name']} = \$_parser->ParseBlock(array('name' => '__capture_{$tag['NP']['name']}'));";
$code[] = "\$params['{$tag['NP']['name']}'] = \${$tag['NP']['name']};";
@@ -164,6 +239,7 @@
}
class _Tag_Include extends _BlockTag {
+
function Open($tag)
{
$o = '';
@@ -182,16 +258,18 @@
*/
var $_Inversed = false;
+ function _Tag_If($tag)
+ {
+ parent::_BlockTag($tag);
+
+ $this->_requiredParams = Array ('check');
+ }
+
function Open($tag)
{
- $o = '';
+ $o = parent::Open($tag);
$to_pass = $this->Parser->CompileParamsArray($tag['NP']);
- if (!isset($tag['NP']['check'])) {
- $this->Application->handleError(E_USER_ERROR, 'Tag '.$this->Parser->TagInfo($tag, true).' called without required check attribute', $tag['file'], $tag['line']);
- return false;
- }
-
$code[] = "\$_splited = \$_parser->SplitTag(array('tag'=>\"{$tag['NP']['check']}\", 'file'=>'{$tag['file']}', 'line'=>{$tag['line']}));";
$code[] = 'if ($_splited[\'prefix\'] == \'__auto__\') {$_splited[\'prefix\'] = $PrefixSpecial;}';
$code[] = '$_p_ =& $_parser->GetProcessor($_splited[\'prefix\']);';
@@ -213,8 +291,7 @@
$tag['processed'] = true;
}
if ($tag['name'] == 'elseif') {
- if (!isset($tag['NP']['check'])) {
- $this->Application->handleError(E_USER_ERROR, 'Tag '.$this->Parser->TagInfo($tag, true).' called without required check attribute', $tag['file'], $tag['line']);
+ if (!$this->_checkRequiredParams($tag)) {
return '';
}
@@ -248,13 +325,14 @@
function _Tag_IfNot($tag)
{
- parent::_BlockTag($tag);
+ parent::_Tag_If($tag);
$this->_Inversed = true;
}
}
class _Tag_DefaultParam extends _BlockTag {
+
function Open($tag)
{
$o = '';