This method is used for the instruction parameter parsing. The first parameter defines the instruction name (used only, if an error occured and the compiler needs to tell, where it is). $args is an argument array got from the template tree. $config is a reference to the array that defined the number and type of parameters we need. After the method execution, the parsed values overwrite the configuration in this array. The format of this array is:
$params = array( 'param_1' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID), // ... 'param_n' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL), // ... );
The index defines the parameter name and the value is the parameter configuration. Their elements mean:
Note that __UNKNOWN__ is a reserved parameter name. It specifies the type of undefined parameters (see below). If the XML-style parameters are provided, they are returned in an assotiative array (param name => value). In the OPT-style, the array has the numeric indices.
$style allows to force the parameter style we want to use. By default each instruction accepts both XML-style and position-based syntax. To force XML-style, set the value to OPT_STYLE_XML and to force the second variant, to OPT_STYLE_OPT.
Let's take a look at some examples:
Example 3.13. parametrize()
$params = array( 'file' => array(OPT_PARAM_REQUIRED, OPT_PARAM_EXPRESSION), 'default' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL), 'assign' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_ID, NULL), '__UNKNOWN__' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL) ); $variables = $this -> compiler -> parametrize('include', $block -> getAttributes(), $params);
This is a part of real include instruction implemented in OPT. We see three "system" parameters: required file and optional default and assign. The two first parameters are parsed as expressions. We also allow to insert some additional parameters (__UNKNOWN__), which are returned to the $variables array. System parameter values are in the $params array. They are used by the instruction in this way:
Example 3.14. Using the parameters
foreach($variables as $name => $variable) { $code .= ' $this -> vars[\''.$name.'\'] = '.$variable.'; '; } // An optional parameter check if($params['default'] != NULL) { $code .= ' if(!$this -> doInclude('.$params['file'].')){ $this -> doInclude('.$params['default'].'); } '; } else { $code .= '$this -> doInclude('.$params['file'].');'; }