/** * Launch the compilation of a template * * Store the result (a php content) into a cache file given by the selector. * @param jSelectorTpl $selector the template selector * @return boolean true if ok */ public function compile($selector) { $this->_sourceFile = $selector->getPath(); $cachefile = $selector->getCompiledFilePath(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $this->_modifier = array_merge($this->_modifier, $selector->userModifiers); $this->_userFunctions = $selector->userFunctions; jContext::push($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $result = $this->compileContent(file_get_contents($this->_sourceFile)); $header = "<?php \n"; foreach ($this->_pluginPath as $path => $ok) { $header .= ' require_once(\'' . $path . "');\n"; } $header .= 'function template_meta_' . md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')) . '($t){'; $header .= "\n" . $this->_metaBody . "\n}\n"; $header .= 'function template_' . md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')) . '($t){' . "\n?>"; $result = $header . $result . "<?php \n}\n?>"; jFile::write($cachefile, $result); jContext::pop(); return true; }
public function compile($selector) { $this->_sourceFile = $selector->getPath(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $md5 = md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')); jContext::push($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $this->compileString(file_get_contents($this->_sourceFile), $selector->getCompiledFilePath(), $selector->userModifiers, $selector->userFunctions, $md5); jContext::pop(); return true; }
/** * instancy a zone object, and call one of its methods * @param string $name zone selector * @param string $method method name * @param array $params arguments for the method * @return mixed the result returned by the method */ private static function _callZone($name, $method, &$params) { $sel = new jSelectorZone($name); jContext::push($sel->module); $fileName = $sel->getPath(); require_once $fileName; $className = $sel->resource . 'Zone'; $zone = new $className($params); $toReturn = $zone->{$method}(); jContext::pop(); return $toReturn; }
/** * main method : launch the execution of the action. * * This method should be called in a entry point. * @param jRequest $request the request object */ public function process($request) { global $gJConfig; $this->request = $request; // let's log messages appeared during init foreach ($this->initErrorMessages as $msg) { jLog::log($msg, $msg->getCategory()); } $this->request->init(); jSession::start(); $this->moduleName = $request->getParam('module'); $this->actionName = $request->getParam('action'); if (empty($this->moduleName)) { $this->moduleName = $gJConfig->startModule; } if (empty($this->actionName)) { if ($this->moduleName == $gJConfig->startModule) { $this->actionName = $gJConfig->startAction; } else { $this->actionName = 'default:index'; } } jContext::push($this->moduleName); try { $this->action = new jSelectorActFast($this->request->type, $this->moduleName, $this->actionName); if ($gJConfig->modules[$this->moduleName . '.access'] < 2) { throw new jException('jelix~errors.module.untrusted', $this->moduleName); } $ctrl = $this->getController($this->action); } catch (jException $e) { if ($gJConfig->urlengine['notfoundAct'] == '') { throw $e; } try { $this->action = new jSelectorAct($gJConfig->urlengine['notfoundAct']); $ctrl = $this->getController($this->action); } catch (jException $e2) { throw $e; } } if (count($this->plugins)) { $pluginparams = array(); if (isset($ctrl->pluginParams['*'])) { $pluginparams = $ctrl->pluginParams['*']; } if (isset($ctrl->pluginParams[$this->action->method])) { $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]); } foreach ($this->plugins as $name => $obj) { $result = $this->plugins[$name]->beforeAction($pluginparams); if ($result) { $this->action = $result; jContext::pop(); jContext::push($result->module); $this->moduleName = $result->module; $this->actionName = $result->resource; $ctrl = $this->getController($this->action); break; } } } $this->response = $ctrl->{$this->action->method}(); if ($this->response == null) { throw new jException('jelix~errors.response.missing', $this->action->toString()); } foreach ($this->plugins as $name => $obj) { $this->plugins[$name]->beforeOutput(); } $this->response->output(); foreach ($this->plugins as $name => $obj) { $this->plugins[$name]->afterProcess(); } jContext::pop(); jSession::end(); }
function single() { $rep = $this->_prepareResponse(); $module = $this->param('mod'); $testname = $this->param('test'); if (isset($this->testsList[$module])) { $reporter = jClasses::create("junittests~jtextrespreporter"); jClasses::inc('junittests~junittestcase'); jClasses::inc('junittests~junittestcasedb'); $reporter->setResponse($rep); foreach ($this->testsList[$module] as $test) { if ($test[1] == $testname) { $group = new GroupTest('"' . $module . '" module , ' . $test[2]); $group->addTestFile($GLOBALS['gJConfig']->_modulesPathList[$module] . 'tests/' . $test[0]); jContext::push($module); $result = $group->run($reporter); if (!$result) { $rep->setExitCode(jResponseCmdline::EXIT_CODE_ERROR); } jContext::pop(); break; } } } else { $rep->addContent("\n" . 'no tests for "' . $module . '" module.' . "\n"); } return $this->_finishResponse($rep); }
protected function tearDown() { jContext::pop(); }
function single() { if (!isset($GLOBALS['gJConfig']->enableTests) || !$GLOBALS['gJConfig']->enableTests) { // security $rep = $this->getResponse('html', true); $rep->title = 'Error'; $rep->setHttpStatus('404', 'Not found'); $rep->addContent('<p>404 Not Found</p>'); return $rep; } $rep = $this->_prepareResponse(); $module = $this->param('mod'); $testname = $this->param('test'); if (isset($this->testsList[$module])) { $reporter = jClasses::create("junittests~jhtmlrespreporter"); jClasses::inc('junittests~junittestcase'); jClasses::inc('junittests~junittestcasedb'); $reporter->setResponse($rep); foreach ($this->testsList[$module] as $test) { if ($test[1] == $testname) { $group = new TestSuite('"' . $module . '" module , ' . $test[2]); $group->addFile($GLOBALS['gJConfig']->_modulesPathList[$module] . 'tests/' . $test[0]); jContext::push($module); $group->run($reporter); jContext::pop(); break; } } } else { $rep->body->assign('MAIN', '<p>no tests for "' . $module . '" module.</p>'); } return $this->_finishResponse($rep); }
function single() { $rep = $this->_prepareResponse(); $module = $this->param('mod'); $testname = $this->param('test'); $category = $this->category ? ' ' . $this->category : ''; if (isset($this->testsList[$module])) { $reporter = jClasses::create($this->responseType); jClasses::inc('junittests~junittestcase'); jClasses::inc('junittests~junittestcasedb'); $reporter->setResponse($rep); foreach ($this->testsList[$module] as $test) { if ($test[1] == $testname) { $group = new TestSuite('"' . $module . '" module , ' . $test[2]); $group->addFile(jApp::config()->_modulesPathList[$module] . 'tests/' . $test[0]); jContext::push($module); $result = $group->run($reporter); if (!$result) { $rep->setExitCode(jResponseCmdline::EXIT_CODE_ERROR); } jContext::pop(); break; } } } else { $this->output("\n" . 'no' . $category . ' tests for "' . $module . '" module.' . "\n"); } return $this->_finishResponse($rep); }