/** * Creates the new translation object. * * @param Opc_Translate_Adapter $adapter The default translation adapter. */ public function __construct(Opc_Translate_Adapter $adapter) { if (!Opl_Registry::exists('opc')) { throw new Opc_ClassInstanceNotExists_Exception(); } $this->_opc = Opl_Registry::get('opc'); $this->_defaultLanguage = $this->_opc->defaultLanugage; $this->_defaultAdapter = $adapter; }
/** * The informator that prints the basic OPT configuration to the error * output. * * @param Opc_Exception $exception The exception */ protected function _printBasicConfiguration($exception) { if (!Opl_Registry::exists('opc')) { return false; } $opc = Opl_Registry::get('opc'); echo '<p class="directive">Caching directory: <span>' . htmlspecialchars($opc->cacheDir) . "</span></p>\r\n"; echo '<p class="directive">Caching expiry time: <span>' . htmlspecialchars($opc->expiryTime) . "</span></p>\r\n"; }
/** * Returns the main OPL library class that threw the exception. * * @return Opl_Class The main class of the exception library. */ public function getLibrary() { $name = explode('_', get_class_name($this)); $name = strtolower($name[0]); if (Opl_Registry::exists($name)) { return Opl_Registry::get($name); } return null; }
/** * Processes the opt:form XML node. * * @param Opt_Xml_Node $node The recognized node. */ public function _processForm(Opt_Xml_Node $node) { $this->_nesting++; $params = array('name' => array(0 => self::OPTIONAL, self::EXPRESSION, null), 'from' => array(0 => self::OPTIONAL, self::EXPRESSION, null), '__UNKNOWN__' => array(0 => self::OPTIONAL, self::STRING)); $extra = $this->_extractAttributes($node, $params); if (!isset($params['name']) && !isset($params['from']) || isset($params['name']) && isset($params['from'])) { throw new Opf_Exception('Attributes "name" or "from" are not defined.'); } $attr = 'array(\'method\' => $_form->getMethod(), \'action\' => $_form->getAction(), \'class\' => Opf_Design::getClass(\'form\', $_form->isValid()), '; foreach ($extra as $name => $value) { $attr .= ' \'' . $name . '\' => ' . $value . ','; } $attr .= ')'; $opf = Opl_Registry::get('opf'); $node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, 'if(($_formy = Opf_Form::topOfStack()) === null) { if(Opf_Class::hasForm(' . $params['name'] . ')) { $_formx = Opf_Class::getForm(' . $params['name'] . '); $_form = $_formx->fluent(); Opf_Form::pushToStack($_form); echo \'<form \'.Opt_Function::buildAttributes(' . $attr . ').\'>\'; } } else { $_formx = ' . (isset($params['from']) ? $params['from'] : '$_formy->getItemDisplay(' . $params['name'] . ')') . '; $_form = $_formx->fluent(); if(!$_form instanceof Opf_Form) { throw new Opf_Exception(\'Invalid form object type(\'.get_class($_formx).\'), should be Opf_Form\'); } Opf_Form::pushToStack($_form); } if(isset($_form)) { foreach($_formx->getInternals() as $n => $v){ echo \'<input type="hidden" name="' . $opf->formInternalId . '[\'.$n.\']" value="\'.htmlspecialchars($v).\'" />\'; } self::$_vars[\'form\'] = $_form; '); $node->addBefore(Opt_Xml_Buffer::TAG_AFTER, ' Opf_Form::popFromStack($_form); if((self::$_vars[\'form\'] = $_form = Opf_Form::topOfStack()) === null) { echo \'</form>\'; } }'); self::_setProcessedForm($params['name']); $this->_compiler->setConversion('##component', '$_form->_widgetFactory(\'%CLASS%\', \'%TAG%\', %ATTRIBUTES%)'); $node->set('postprocess', true); $this->_process($node); }
/** * Creates the adapter and applies the options. * * @param array $options The adapter options. */ public function __construct(array $options = array()) { if (!Opl_Registry::exists('opc')) { throw new Opc_ClassInstanceNotExists_Exception(); } $this->_opc = Opl_Registry::get('opc'); if (isset($options['directory'])) { $this->setDirectory($options['directory']); } if (isset($options['fileExistsCheck'])) { $this->_fileExistsCheck = (bool) $options['fileExistsCheck']; } }
/** * Sets the compiler instance. * * @param Opt_Compiler_Class $compiler The compiler object */ public function setCompiler(Opt_Compiler_Class $compiler) { $this->_compiler = $compiler; $this->_tpl = Opl_Registry::get('opt'); if ($this->_tpl->unicodeNames) { // Register unicode name regular expressions $this->_rOpeningChar = '(\\p{Lu}|\\p{Ll}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Nl}|\\_|\\:)'; $this->_rNameChar = '(\\p{Lu}|\\p{Ll}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Nl}|\\p{Mc}|\\p{Me}|\\p{Mn}|\\p{Lm}|\\p{Nd}|\\_|\\:|\\.|\\-)'; $this->_rModifiers = 'msiu'; } // Register the rest of the expressions $this->_rNameExpression = '/(' . $this->_rOpeningChar . '?' . $this->_rNameChar . '*)/' . $this->_rModifiers; $this->_rXmlTagExpression = '/(\\<((\\/)?(' . $this->_rOpeningChar . '?' . $this->_rNameChar . '*)( [^\\<\\>]*)?(\\/)?)\\>)/' . $this->_rModifiers; $this->_rTagExpandExpression = '/^(\\/)?(' . $this->_rOpeningChar . '?' . $this->_rNameChar . '*)( [^\\<\\>]*)?(\\/)?$/' . $this->_rModifiers; $this->_rQuirksTagExpression = '/(\\<((\\/)?((' . implode('|', $this->_tpl->_getList('_namespaces')) . ')\\:' . $this->_rNameChar . '*)( [^\\<\\>]+)?(\\/)?)\\>)/' . $this->_rModifiers; }
/** * TODO: To be documented. * * @param <type> $name * @return <type> */ public function display(Exception $exception) { $debug = false; if (Opl_Registry::getValue('opl_extended_errors')) { $debug = true; } $out = Opl_Registry::get('stdout'); // Match the port to the exception. foreach ($this->_ports as $port) { if ($port->match($exception)) { $libraryName = $port->getName(); if ($debug === true) { $context = $port->getContext($exception); } break; } } if (!isset($libraryName)) { return false; } $out->writeLine('= ' . $libraryName . ' ='); $out->writeLine('MESSAGE: ' . $exception->getMessage()); $out->writeLine('CODE: ' . get_class($exception)); if ($debug) { $out->writeLine('FILE: ' . $exception->getFile() . ' [LINE ' . $exception->getLine() . ']'); } else { $out->writeLine('Debug mode is disabled. No additional information provided.'); } if ($debug) { foreach ($context as $name => $params) { $informer = $this->getInformer($name); if ($informer !== null) { $informer->display($exception, $params); } else { $out->writeLine('Unknown informer: ' . $name); } } } return true; }
/** * Sets the compiler instance in the expression parser. * * @param Opt_Compiler_Class $compiler The compiler object */ public function setCompiler(Opt_Compiler_Class $compiler) { $this->_compiler = $compiler; $this->_manager = $compiler->getCdfManager(); $this->_tpl = Opl_Registry::get('opt'); $this->_tf = $this->_tpl->getTranslationInterface(); }
/** * Formats the input number to look nice in the text. If the extra arguments * are not present, they are taken from OPT configuration. * * @param Number $number The input number * @param Integer $d1 The number of decimals * @param String $d2 The decimal separator * @param String $d3 The thousand separator * @return String */ public static function number($number, $d1 = null, $d2 = null, $d3 = null) { if (self::isContainer($number)) { return self::processContainer(array('Opt_Function', 'number'), array($number, $d1, $d2, $d3)); } $opt = Opl_Registry::get('opt'); $d1 = $d1 === null ? $opt->numberDecimals : $d1; $d2 = $d2 === null ? $opt->numberDecPoint : $d2; $d3 = $d3 === null ? $opt->numberThousandSep : $d3; return number_format($number, $d1, $d2, $d3); }
/** * The interface method of Opt_Caching_Interface. Finalizes * the caching of the view. * * @param Opt_View $view The cached view. */ public function templateCacheStop(Opt_View $view) { $header = array('timestamp' => time(), 'expire' => $this->getExpiryTime(), 'dynamic' => $view->hasDynamicContent() ? 'true' : 'false'); $header = '<' . '?php /* ' . serialize($header) . '*/ ?>' . "\n"; $tpl = Opl_Registry::get('opt'); $tpl->setBufferState('cache', false); if ($view->hasDynamicContent()) { $buffer = $view->getOutputBuffers(); $dyn = file_get_contents($tpl->compileDir . $view->_convert($view->getTemplate()) . '.dyn'); if ($dyn !== false) { $dynamic = unserialize($dyn); unset($dyn); } else { throw new Opc_View_Cache_InvalidDynamicContent_Exception($view->getTemplate()); return false; } $content = ''; for ($i = 0, $endI = count($buffer); $i < $endI; $i++) { $content .= $buffer[$i]; $content .= $dynamic[$i]; } if (file_put_contents($this->getDirectory() . $this->_getFilename($view), $header . $content . ob_get_flush()) === false) { throw new Opc_View_Cache_CannotSaveFile_Exception($this->getDirectory()); return false; } } else { if (file_put_contents($this->getDirectory() . $this->_getFileName($view), $header . ob_get_contents()) === false) { throw new Opc_View_Cache_CannotSaveFile_Exception($this->getDirectory()); return false; } } }
/** * The constructor that creates the new HTTP output object. */ public function __construct() { $this->_tpl = Opl_Registry::get('opt'); }
/** * The informator that prints the basic OPT configuration to the error * output. * * @internal * @param Opt_Exception $exception Exception */ protected function _printBasicConfiguration($exception) { $compileMode = array(Opt_Class::CM_DEFAULT => 'Default', Opt_Class::CM_REBUILD => 'Rebuild', Opt_Class::CM_PERFORMANCE => 'Performance'); $tpl = Opl_Registry::get('opt'); echo " \t\t\t<p class=\"directive\">Source directories:</p>\r\n"; echo " \t\t\t<ol>\r\n"; foreach ($tpl->sourceDir as $name => $path) { echo ' <li><code>' . $name . '</code>: <span>' . $path . "</span></li>\r\n"; } echo " \t\t\t</ol>\r\n"; echo ' <p class="directive">Compilation directory: <span>' . $tpl->compileDir . "</span></p>\r\n"; echo ' <p class="directive">Compilation mode: <span' . ($tpl->compileMode == Opt_Class::CM_REBUILD ? ' class="bad"' : '') . '>' . $compileMode[$tpl->compileMode] . "</span></p>\r\n"; }
/** * Displays the help. */ public function showHelp() { $stdout = Opl_Registry::get('stdout'); $stdout->writeLine('Help'); foreach (self::$_actions as $action) { $stdout->writeLine($action->getName() . ' - ' . $action->getDescription()); } }
/** * @covers Opl_Registry::set * @covers Opl_Registry::get */ public function testSettingValue() { Opl_Registry::set('foo', 'bar'); $this->assertEquals(Opl_Registry::get('foo'), 'bar'); }
/** * Links the element attributes into a valid XML code and returns * the output code. * * @internal * @param Opt_Xml_Element $subitem The XML element. * @return String */ protected function _linkAttributes() { // Links the attributes into the PHP code if ($this->hasAttributes() || $this->bufferSize(Opt_Xml_Buffer::TAG_BEGINNING_ATTRIBUTES) > 0 || $this->bufferSize(Opt_Xml_Buffer::TAG_ENDING_ATTRIBUTES) > 0) { $code = $this->buildCode(Opt_Xml_Buffer::TAG_ATTRIBUTES_BEFORE, Opt_Xml_Buffer::TAG_BEGINNING_ATTRIBUTES); $attrList = $this->getAttributes(); // Link attributes into a string foreach ($attrList as $attribute) { $s = $attribute->bufferSize(Opt_Xml_Buffer::ATTRIBUTE_NAME); switch ($s) { case 0: $code .= $attribute->buildCode(Opt_Xml_Buffer::ATTRIBUTE_BEGIN) . ' ' . $attribute->getXmlName(); break; case 1: $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()); } if ($attribute->bufferSize(Opt_Xml_Buffer::ATTRIBUTE_VALUE) == 0) { // Static value $tpl = Opl_Registry::get('opt'); if (!($tpl->htmlAttributes && $attribute->getValue() == $attribute->getName())) { $code .= '="' . htmlspecialchars($attribute->getValue()) . '"'; } } else { $code .= '="' . $attribute->buildCode(Opt_Xml_Buffer::ATTRIBUTE_VALUE) . '"'; } $code .= $attribute->buildCode(Opt_Xml_Buffer::ATTRIBUTE_END); } return $code . $this->buildCode(Opt_Xml_Buffer::TAG_ENDING_ATTRIBUTES, Opt_Xml_Buffer::TAG_ATTRIBUTES_AFTER); } return ''; }
/** * Executes the form sequence. */ public function execute() { $opf = Opl_Registry::get('opf'); $this->invokeEvent('preInit'); $this->onInit(); $this->invokeEvent('postInit'); // Validate the input data. $data = $this->_retrieveData(); // Decide, if the form has been sent to us. if ($_SERVER['REQUEST_METHOD'] == $this->_method && isset($data[$opf->formInternalId])) { // Get the internal data and remove them from the "official" scope. $internals = $data[$opf->formInternalId]; unset($data[$opf->formInternalId]); // The names must match. if (isset($internals['name']) && $internals['name'] == $this->_name) { $this->_step = 0; if (isset($internals['step'])) { $this->_step = (int) $internals['step']; } $tracker = $this->getTracker(); $tracker->setSequence($this); $current = 0; while ($current < $this->_step) { // Get the current form and advance the placeholder pointer. $form = $this->getNextSubform(); // Attempt to ensure that the tracked data are still valid. $formData = $tracker->retrieve($internals, $current); $current++; $state = $form->_validate($formData); if (!$state) { $this->_step = $current; $this->_state = $form->_state = self::ERROR; $form->populate($data); $form->_onRender($this->_view); $this->_onRender($this->_view); $this->invokeEvent('preRender'); $form->invokeEvent('preRender'); $form->onRender(); $form->invokeEvent('postRender'); $this->invokeEvent('postRender'); return $this->_state; } } $form = $this->getNextSubform(); // Now, the currently displayed form. $state = $form->_validate($data); if (!$state) { $this->_state = $form->_state = self::ERROR; $form->populate($data); $form->_onRender($this->_view); $form->invokeEvent('preRender'); $form->onRender(); $form->invokeEvent('postRender'); return $this->_state; } else { $tracker->track($data, $current); $form->_state = self::ACCEPTED; } // Decide, what to do next: display another form or return $this->_step++; if (($form = $this->getNextSubform()) === false) { $this->_state = self::ACCEPTED; $this->invokeEvent('preAccept'); $this->onAccept(); $this->invokeEvent('postAccept'); return $this->_state; } else { $this->_state = $form->_state = self::RENDER; $form->_onRender($this->_view); $this->_onRender($this->_view); $form->invokeEvent('preRender'); $form->onRender(); $form->invokeEvent('postRender'); return $this->_state; } } } $form = $this->getNextSubform(); $this->_state = $form->_state = self::RENDER; $form->_onRender($this->_view); $this->_onRender($this->_view); $form->invokeEvent('preRender'); $form->onRender(); $form->invokeEvent('postRender'); return $this->_state; }
/** * Generates a help from the available options. * * @param Opl_Console_Stream $stdout The output stream used for rendering. */ public function printHelp() { $stdout = Opl_Registry::get('stdout'); $stdout->writeLine('Help'); foreach ($this->_availableOpts as $option) { $stdout->writeLine('-' . $option->getShortFlag() . ($option->getArgument() !== null ? ' ...' : '') . '/--' . $option->getLongFlag() . ($option->getArgument() !== null ? '=...' : '') . ' - ' . $option->getHelp()); } }
/** * Creates a new view object. The optional argument, $template * may specify the template to be associated with this view. * Please note that if you do not specify the template here, * you have to do this manually later using Opt_View::setTemplate() * method. * * @param string $template The template file. */ public function __construct($template = '') { $this->_tpl = Opl_Registry::get('opt'); $this->_template = (string) $template; $this->_parser = $this->_tpl->parser; $this->_cache = $this->_tpl->getCache(); }
/** * Validates the field against the registered validators. * @param mixed $data The data to validate. */ protected function _validate(&$data, Opf_Item $errorClass = null) { $opf = Opl_Registry::get('opf'); $tf = $opf->getTranslationInterface(); // The complex items may overwrite this setting to redirect the error // messages somewhere else. if ($errorClass === null) { $errorClass = $this; } foreach ($this->_validators as $validator) { if (!$validator->validate($errorClass, $data)) { $this->_valid = false; if ($tf === null) { $errorClass->addErrorMessage(vsprintf($validator->getError(), $validator->getErrorData())); } else { $tf->assign($opf->translationGroup, $validator->getError(), $validator->getErrorData()); $errorClass->addErrorMessage($tf->_($opf->translationGroup, $validator->getError())); } return false; } } $errorClass->_valid = true; return true; }
/** * Executes the form. The result is the overall result of the * form processing process. * * @return boolean */ public function execute() { $this->_executed = true; $opf = Opl_Registry::get('opf'); $this->invokeEvent('preInit'); $this->onInit(); $this->invokeEvent('postInit'); // Validate the input data. $data = $this->_retrieveData(); // Decide, if the form has been sent to us. if ($_SERVER['REQUEST_METHOD'] == $this->_method && isset($data[$opf->formInternalId])) { // Get the internal data and remove them from the "official" scope. $internals = $data[$opf->formInternalId]; unset($data[$opf->formInternalId]); // The names must match. if (isset($internals['name']) && $internals['name'] == $this->_name) { // The form has been sent! $state = $this->_validate($data); if (!$state) { $this->_state = self::ERROR; return $this->_state; } $this->_data = $data; $this->_state = self::ACCEPTED; $this->invokeEvent('preAccept'); $this->onAccept(); $this->invokeEvent('postAccept'); $this->clear(); return $this->_state; } } $this->_state = self::RENDER; return $this->_state; }
function modifyVariable($item, $value) { $data = Opl_Registry::get('data'); $data[$item] = $value; Opl_Registry::register('data', $data); }
/** * Creates new paginator. * * @param integer $all The amout of all items * @param integer $limit Items per page * @return void */ public function __construct($all = null, $limit = null) { if (!Opl_Registry::exists('opc')) { throw new Opc_ClassInstanceNotExists_Exception(); } $opc = Opl_Registry::get('opc'); if (is_null($limit)) { $limit = $opc->itemsPerPage; } if (!is_null($opc->paginatorDecorator)) { $this->set('decorator', $opc->paginatorDecorator); } if (is_array($opc->paginatorDecoratorOptions)) { $this->decorator->loadConfig($opc->paginatorDecoratorOptions); } $this->set('all', $all); $this->set('limit', $limit); }
/** * Creates a new instruction processor for the specified compiler. * * @param Opt_Compiler_Class $compiler The compiler object. */ public function __construct(Opt_Compiler_Class $compiler) { $this->_compiler = $compiler; $this->_tpl = Opl_Registry::get('opt'); $this->configure(); }
/** * This function is executed by the compiler during the third compilation stage, * linking. */ public function preLink(Opt_Compiler_Class $compiler) { if ($this->get('cdata')) { $compiler->appendOutput($this->buildCode(Opt_Xml_Buffer::TAG_BEFORE) . '<![CDATA[' . $this . ']]>' . $this->buildCode(Opt_Xml_Buffer::TAG_AFTER)); return; } $compiler->appendOutput($this->buildCode(Opt_Xml_Buffer::TAG_BEFORE)); $tpl = Opl_Registry::get('opt'); // We strip the white spaces at the linking level. if ($tpl->stripWhitespaces) { // The CDATA composed of white characters only is reduced to a single space. if (ctype_space((string) $this)) { // TODO: Wtf is this? Compare with OPT 2.0 code... /*if($wasElement) { $output .= ' '; }*/ } else { // In the opposite case reduce all the groups of the white characters // to single spaces in the text. if ($this->get('noEntitize') === true) { $compiler->appendOutput(preg_replace('/\\s\\s+/', ' ', (string) $this)); } else { $compiler->appendOutput($compiler->parseSpecialChars(preg_replace('/(\\s){1,}/', ' ', (string) $this))); } } } else { $compiler->appendOutput($this->get('noEntitize') ? (string) $this : $compiler->parseSpecialChars($this)); } $compiler->appendOutput($this->buildCode(Opt_Xml_Buffer::TAG_AFTER)); // $this->_closeComments($item, $output); }