/** * 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(); $this->outputType = $selector->outputType; $this->trusted = $selector->trusted; $md5 = md5($selector->module . '_' . $selector->resource . '_' . $this->outputType . ($this->trusted ? '_t' : '')); jApp::pushCurrentModule($selector->module); if (!file_exists($this->_sourceFile)) { $this->doError0('errors.tpl.not.found'); } $header = "if (jApp::config()->compilation['checkCacheFiletime'] &&\n"; $header .= "filemtime('" . $this->_sourceFile . '\') > ' . filemtime($this->_sourceFile) . "){ return false;\n} else {\n"; $footer = "return true;}\n"; $this->compileString(file_get_contents($this->_sourceFile), $selector->getCompiledFilePath(), $selector->userModifiers, $selector->userFunctions, $md5, $header, $footer); jApp::popCurrentModule(); return true; }
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]); jApp::pushCurrentModule($module); $result = $group->run($reporter); if (!$result) { $rep->setExitCode(jResponseCmdline::EXIT_CODE_ERROR); } jApp::popCurrentModule(); break; } } } else { $this->output("\n" . 'no' . $category . ' tests for "' . $module . '" module.' . "\n"); } return $this->_finishResponse($rep); }
/** * main method : launch the execution of the action. * * This method should be called in a entry point. * * @param jRequest $request the request object. It is required if a descendant of jCoordinator did not called setRequest before */ public function process($request = null) { jLog::log("process: start"); try { if ($request) { $this->setRequest($request); } jSession::start(); $ctrl = $this->getController($this->action); } catch (jException $e) { $config = jApp::config(); if ($config->urlengine['notfoundAct'] == '') { throw $e; } if (!jSession::isStarted()) { jSession::start(); } try { jLog::log("Exception: get notfoundact ctrl (" . $config->urlengine['notfoundAct'] . ")"); $this->action = new jSelectorAct($config->urlengine['notfoundAct']); $ctrl = $this->getController($this->action); } catch (jException $e2) { throw $e; } } jApp::pushCurrentModule($this->moduleName); 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]); } jLog::dump($pluginparams, "process: plugin params"); foreach ($this->plugins as $name => $obj) { jLog::log("process: beforeAction on plugin {$name}"); $result = $this->plugins[$name]->beforeAction($pluginparams); if ($result) { $this->action = $result; jApp::popCurrentModule(); jApp::pushCurrentModule($result->module); jLog::log("process: beforeAction said to do internal redirect to " . $result->module . "~" . $result->resource); $this->moduleName = $result->module; $this->actionName = $result->resource; $ctrl = $this->getController($this->action); break; } } } jLog::log('process: call action'); $this->response = $ctrl->{$this->action->method}(); if ($this->response == null) { throw new jException('jelix~errors.response.missing', $this->action->toString()); } jLog::log('process: response: ' . get_class($this->response)); if (get_class($this->response) == 'jResponseRedirect') { jLog::log('process: redirection to ' . $this->response->action); } else { if (get_class($this->response) == 'jResponseRedirectUrl') { jLog::log('process: redirection to ' . $this->response->url); } } foreach ($this->plugins as $name => $obj) { jLog::log('process: beforeOutput on plugin ' . $name); $this->plugins[$name]->beforeOutput(); } jLog::log('process: call response output'); $this->response->output(); foreach ($this->plugins as $name => $obj) { jLog::log('process: afterProcess on plugin ' . $name); $this->plugins[$name]->afterProcess(); } jApp::popCurrentModule(); jSession::end(); jLog::log('process: end'); }
protected function setUp() { parent::setUp(); jApp::pushCurrentModule($this->module); }
protected function parseRecord($xml, $tools) { //add the record properties if (isset($xml->record)) { if (isset($xml->record[0]['extends'])) { jApp::pushCurrentModule($this->selector->module); $this->_userRecord = new jSelectorDaoRecord((string) $xml->record[0]['extends']); jApp::popCurrentModule(); } if (isset($xml->record[0]->property)) { // don't append directly new properties into _properties, // so we can see the differences between imported properties // and readed properties $properties = array(); foreach ($xml->record[0]->property as $prop) { $p = new jDaoProperty($prop->attributes(), $this, $tools); if (isset($properties[$p->name])) { throw new jDaoXmlException($this->selector, 'property.already.defined', $p->name); } if (!in_array($p->name, $this->_tables[$p->table]['fields'])) { // if this property does not redefined an imported property $this->_tables[$p->table]['fields'][] = $p->name; } $properties[$p->name] = $p; } $this->_properties = array_merge($this->_properties, $properties); } } // in the case when there is no defined property and no imported dao if (count($this->_properties) == 0) { throw new jDaoXmlException($this->selector, 'properties.missing'); } // check that properties are attached to a known table. It can be // wrong if the datasource has been redefined with other table names $countprop = 0; foreach ($this->_properties as $p) { if (!isset($this->_tables[$p->table])) { throw new jDaoXmlException($this->selector, 'property.imported.unknown.table', $p->name); } if ($p->ofPrimaryTable && !$p->isPK) { $countprop++; } } $this->hasOnlyPrimaryKeys = $countprop == 0; }
function single() { $conf = jApp::config(); if (!isset($conf->enableTests) || !$conf->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($conf->_modulesPathList[$module] . 'tests/' . $test[0]); jApp::pushCurrentModule($module); $group->run($reporter); jApp::popCurrentModule(); break; } } } else { $rep->body->assign('MAIN', '<p>no tests for "' . $module . '" module.</p>'); } return $this->_finishResponse($rep); }
/** * main method : launch the execution of the action. * * This method should be called in a entry point. * * @param jRequest $request the request object. It is required if a descendant of jCoordinator did not called setRequest before */ public function process($request = null) { try { if ($request) { $this->setRequest($request); } jSession::start(); $ctrl = $this->getController($this->action); } catch (jException $e) { $config = jApp::config(); if ($config->urlengine['notfoundAct'] == '') { throw $e; } if (!jSession::isStarted()) { jSession::start(); } try { $this->action = new jSelectorAct($config->urlengine['notfoundAct']); $ctrl = $this->getController($this->action); } catch (jException $e2) { throw $e; } } jApp::pushCurrentModule($this->moduleName); 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; jApp::popCurrentModule(); jApp::pushCurrentModule($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(); } jApp::popCurrentModule(); jSession::end(); }
public function run() { $this->loadAppConfig(); require_once JELIX_LIB_PATH . 'dao/jDaoParser.class.php'; $path = $this->getModulePath($this->_parameters['module']); $formdir = $path . 'forms/'; $this->createDir($formdir); $formfile = strtolower($this->_parameters['form']) . '.form.xml'; if ($this->getOption('-createlocales')) { $locale_content = ''; $locale_base = $this->_parameters['module'] . '~' . strtolower($this->_parameters['form']) . '.form.'; $locale_filename_fr = 'locales/fr_FR/'; $this->createDir($path . $locale_filename_fr); $locale_filename_fr .= strtolower($this->_parameters['form']) . '.UTF-8.properties'; $locale_filename_en = 'locales/en_US/'; $this->createDir($path . $locale_filename_en); $locale_filename_en .= strtolower($this->_parameters['form']) . '.UTF-8.properties'; $submit = "\n\n<submit ref=\"_submit\">\n\t<label locale='" . $locale_base . "ok' />\n</submit>"; } else { $submit = "\n\n<submit ref=\"_submit\">\n\t<label>ok</label>\n</submit>"; } $dao = $this->getParam('dao'); if ($dao === null) { if ($this->getOption('-createlocales')) { $locale_content = "form.ok=OK\n"; $this->createFile($path . $locale_filename_fr, 'locales.tpl', array('content' => $locale_content), "Locales file"); $this->createFile($path . $locale_filename_en, 'locales.tpl', array('content' => $locale_content), "Locales file"); } $this->createFile($formdir . $formfile, 'module/form.xml.tpl', array('content' => '<!-- add control declaration here -->' . $submit), "Form"); return; } jApp::config()->startModule = $this->_parameters['module']; jApp::pushCurrentModule($this->_parameters['module']); $tools = jDb::getConnection()->tools(); // we're going to parse the dao $selector = new jSelectorDao($dao, ''); $doc = new DOMDocument(); $daoPath = $selector->getPath(); if (!$doc->load($daoPath)) { throw new jException('jelix~daoxml.file.unknown', $daoPath); } if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') { throw new jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI)); } $parser = new jDaoParser($selector); $parser->parse(simplexml_import_dom($doc), $tools); // now we generate the form file $properties = $parser->GetProperties(); $table = $parser->GetPrimaryTable(); $content = ''; foreach ($properties as $name => $property) { if (!$property->ofPrimaryTable) { continue; } if ($property->isPK && $property->autoIncrement) { continue; } $attr = ''; if ($property->required) { $attr .= ' required="true"'; } if ($property->defaultValue !== null) { $attr .= ' defaultvalue="' . htmlspecialchars($property->defaultValue) . '"'; } if ($property->maxlength !== null) { $attr .= ' maxlength="' . $property->maxlength . '"'; } if ($property->minlength !== null) { $attr .= ' minlength="' . $property->minlength . '"'; } $datatype = ''; $tag = 'input'; switch ($property->unifiedType) { case 'integer': case 'numeric': $datatype = 'integer'; break; case 'datetime': $datatype = 'datetime'; break; case 'time': $datatype = 'time'; break; case 'date': $datatype = 'date'; break; case 'double': case 'float': $datatype = 'decimal'; break; case 'text': case 'blob': $tag = 'textarea'; break; case 'boolean': $tag = 'checkbox'; break; } if ($datatype != '') { $attr .= ' type="' . $datatype . '"'; } // use database comment to create form's label if ($property->comment != '' && $this->getOption('-usecomments')) { if ($this->getOption('-createlocales')) { // replace special chars by dot $locale_content .= 'form.' . $name . '=' . htmlspecialchars(utf8_decode($property->comment)) . "\n"; $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label locale='" . $locale_base . $name . "' />\n</{$tag}>"; } else { // encoding special chars $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>" . htmlspecialchars($property->comment) . "</label>\n</{$tag}>"; } } else { if ($this->getOption('-createlocales')) { $locale_content .= 'form.' . $name . '=' . ucwords(str_replace('_', ' ', $name)) . "\n"; $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label locale='" . $locale_base . $name . "' />\n</{$tag}>"; } else { $content .= "\n\n<{$tag} ref=\"{$name}\"{$attr}>\n\t<label>" . ucwords(str_replace('_', ' ', $name)) . "</label>\n</{$tag}>"; } } } if ($this->getOption('-createlocales')) { $locale_content .= "form.ok=OK\n"; $this->createFile($path . $locale_filename_fr, 'module/locales.tpl', array('content' => $locale_content), "Locales file"); $this->createFile($path . $locale_filename_en, 'module/locales.tpl', array('content' => $locale_content), "Locales file"); } $this->createFile($formdir . $formfile, 'module/form.xml.tpl', array('content' => $content . $submit), "Form file"); }
/** * 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); jApp::pushCurrentModule($sel->module); $fileName = $sel->getPath(); require_once $fileName; $className = $sel->resource . 'Zone'; $zone = new $className($params); $toReturn = $zone->{$method}(); jApp::popCurrentModule(); return $toReturn; }