/** * Creates a new instance of the template compiler. The compiler can * be created, using the settings from the main OPT class or another * compiler. * * @param Opt_Class|Opt_Compiler_Class $tpl The initial object. */ public function __construct($tpl) { if ($tpl instanceof Opt_Class) { $this->_tpl = $tpl; $this->_namespaces = $tpl->_getList('_namespaces'); $this->_classes = $tpl->_getList('_classes'); $this->_functions = $tpl->_getList('_functions'); $this->_components = $tpl->_getList('_components'); $this->_blocks = $tpl->_getList('_blocks'); $this->_phpFunctions = $tpl->_getList('_phpFunctions'); $this->_formats = $tpl->_getList('_formats'); $this->_tf = $tpl->_getList('_tf'); $this->_entities = $tpl->_getList('_entities'); $this->_exprEngines = $tpl->_getList('_exprEngines'); $this->_modifiers = $tpl->_getList('_modifiers'); $this->_charset = strtoupper($tpl->charset); // Create the processors and call their configuration method in the constructors. $instructions = $tpl->_getList('_instructions'); foreach ($instructions as $instructionClass) { $obj = new $instructionClass($this, $tpl); $this->_processors[$obj->getName()] = $obj; // Add the tags and attributes registered by this processor. foreach ($obj->getInstructions() as $item) { $this->_instructions[$item] = $obj; } foreach ($obj->getAttributes() as $item) { $this->_attributes[$item] = $obj; } } } elseif ($tpl instanceof Opt_Compiler_Class) { // Simply import the data structures from that compiler. $this->_tpl = $tpl->_tpl; $this->_namespaces = $tpl->_namespaces; $this->_classes = $tpl->_classes; $this->_functions = $tpl->_functions; $this->_components = $tpl->_components; $this->_blocks = $tpl->_blocks; $this->_inheritance = $tpl->_inheritance; $this->_formatInfo = $tpl->_formatInfo; $this->_formats = $tpl->_formats; $this->_tf = $tpl->_tf; $this->_processor = $tpl->_processors; $this->_instructions = $tpl->_instructions; $this->_attributes = $tpl->_attributes; $this->_charset = $tpl->_charset; $this->_entities = $tpl->_entities; $this->_exprEngines = $tpl->_exprEngines; $this->_modifiers = $tpl->_modifiers; $tpl = $this->_tpl; } // We've just thrown the performance away by loading the compiler, so this won't make things worse // but the user may be happy :). However, don't show this message, if we are in the performance mode. if (!is_writable($tpl->compileDir) && $tpl->_compileMode != Opt_Class::CM_PERFORMANCE) { throw new Opt_FilesystemAccess_Exception('compilation', 'writeable'); } // If the debug console is active, preload the XML tree classes. // Without it, the debug console would show crazy things about the memory usage. if ($this->_tpl->debugConsole && !class_exists('Opt_Xml_Root')) { Opl_Loader::load('Opt_Xml_Root'); Opl_Loader::load('Opt_Xml_Text'); Opl_Loader::load('Opt_Xml_Cdata'); Opl_Loader::load('Opt_Xml_Element'); Opl_Loader::load('Opt_Xml_Attribute'); Opl_Loader::load('Opt_Xml_Expression'); Opl_Loader::load('Opt_Xml_Prolog'); Opl_Loader::load('Opt_Xml_Dtd'); Opl_Loader::load('Opt_Format_Array'); } $this->_contextStack = new SplStack(); }