protected function getCache() { if (!$this->_cache) { $this->_cache = Prado::getApplication()->getCache(); } return $this->_cache; }
/** * Creates a new instance of a particular class (for PHP primative types, * their corresponding default value for given type is used). * @param string PHP type name * @return mixed default type value, if no type is specified null is returned. * @throws TSqlMapException if class name is not found. */ public function createInstanceOf($type = '') { if (strlen($type) > 0) { switch (strtolower($type)) { case 'string': return ''; case 'array': return array(); case 'float': case 'double': case 'decimal': return 0.0; case 'integer': case 'int': return 0; case 'bool': case 'boolean': return false; } if (class_exists('Prado', false)) { return Prado::createComponent($type); } else { if (class_exists($type, false)) { //NO auto loading return new $type(); } else { throw new TSqlMapException('sqlmap_unable_to_find_class', $type); } } } }
protected function initializeHeaderCell($cell, $columnIndex) { $text = $this->getHeaderText(); if (($classPath = $this->getHeaderRenderer()) !== '') { $control = Prado::createComponent($classPath); if ($control instanceof \Prado\IDataRenderer) { if ($control instanceof IItemDataRenderer) { $item = $cell->getParent(); $control->setItemIndex($item->getItemIndex()); $control->setItemType($item->getItemType()); } $control->setData($text); } $cell->getControls()->add($control); } else { if ($this->getAllowSorting()) { $sortExpression = $this->getSortExpression(); if (($url = $this->getHeaderImageUrl()) !== '') { $button = new TActiveImageButton(); $button->setImageUrl($url); $button->setCommandName(TDataGrid::CMD_SORT); $button->setCommandParameter($sortExpression); if ($text !== '') { $button->setAlternateText($text); $button->setToolTip($text); } $button->setCausesValidation(false); $cell->getControls()->add($button); } else { if ($text !== '') { $button = new TActiveLinkButton(); $button->setText($text); $button->setCommandName(TDataGrid::CMD_SORT); $button->setCommandParameter($sortExpression); $button->setCausesValidation(false); $cell->getControls()->add($button); } else { $cell->setText(' '); } } } else { if (($url = $this->getHeaderImageUrl()) !== '') { $image = new TActiveImage(); $image->setImageUrl($url); if ($text !== '') { $image->setAlternateText($text); $image->setToolTip($text); } $cell->getControls()->add($image); } else { if ($text !== '') { $cell->setText($text); } else { $cell->setText(' '); } } } } }
private function _startThemeManager() { $themeManager = new TThemeManager(); $themeManager->BasePath = "System.Wsat.themes"; $url = Prado::getApplication()->getAssetManager()->publishFilePath(Prado::getPathOfNamespace('System.Wsat')); $themeManager->BaseUrl = "{$url}/themes"; $themeManager->init(null); $this->setThemeManager($themeManager); }
/** * Create an instance of an object give by the attribute named 'class' in the * node and set the properties on the object given by attribute names and values. * @param SimpleXmlNode property node * @return Object new instance of class with class name given by 'class' attribute value. */ protected function createObjectFromNode($node) { if (isset($node['class'])) { $obj = Prado::createComponent((string) $node['class']); $this->setObjectPropFromNode($obj, $node, array('class')); return $obj; } throw new TSqlMapConfigurationException('sqlmap_node_class_undef', $node, $this->getConfigFile()); }
public function testSetTransformPathAsNamespace() { if (Prado::getPathOfAlias('UnitTest') === null) { Prado::setPathOfAlias('UnitTest', dirname(__FILE__) . '/data'); } $expected = $this->transformPath; $transform = new TXmlTransform(); $transform->setTransformPath('UnitTest.hello'); $this->assertEquals($expected, $transform->getTransformPath()); }
/** * @return string path to the error message file */ protected function getErrorMessageFile() { $lang = Prado::getPreferredLanguage(); $dir = dirname(__FILE__); $msgFile = $dir . '/messages-' . $lang . '.txt'; if (!is_file($msgFile)) { $msgFile = $dir . '/messages.txt'; } return $msgFile; }
/** * Renders body content. * This method overrides the parent implementation by replacing * the body content with the processed text content. * @param THtmlWriter writer */ public function renderContents($writer) { if (($text = $this->getText()) === '' && $this->getHasControls()) { $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter()); parent::renderContents($htmlWriter); $text = $htmlWriter->flush(); } if ($text !== '') { $writer->write($this->processText($text)); } }
public function setOpFile($op_file_namespace) { $op_file = Prado::getPathOfNamespace($op_file_namespace); if (empty($op_file)) { throw new Exception("You need to fix your output folder namespace."); } if (!is_dir($op_file)) { mkdir($op_file, 0777, true); } $this->_opFile = $op_file; }
/** * getControl * * Compatibility method to get a control from its clientside id * @return TControl control, or null if not found */ public function getControl($id) { $control = null; $service = Prado::getApplication()->getService(); if ($service instanceof TPageService) { // Find the control // Warning, this will not work if you have a '_' in your control Id ! $controlId = str_replace(TControl::CLIENT_ID_SEPARATOR, TControl::ID_SEPARATOR, $id); $control = $service->getRequestedPage()->findControl($controlId); } return $control; }
/** * Sets the location of image file of the THyperLink. * @param string the image file location */ public function setImageUrl($value) { if (parent::getImageUrl() === $value) { return; } parent::setImageUrl($value); if ($this->getActiveControl()->canUpdateClientSide() && $value !== '') { $textWriter = new TTextWriter(); $renderer = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $textWriter); $this->createImage($value)->renderControl($renderer); $this->getPage()->getCallbackClient()->update($this, $textWriter->flush()); } }
/** * Creates the DB connection. * @param string the module ID for TDataSourceConfig * @return TDbConnection the created DB connection * @throws TConfigurationException if module ID is invalid or empty */ protected function createDbConnection($connectionID) { if ($connectionID !== '') { $conn = Prado::getApplication()->getModule($connectionID); if ($conn instanceof TDataSourceConfig) { return $conn->getDbConnection(); } else { throw new TConfigurationException('messagesource_connectionid_invalid', $connectionID); } } else { throw new TConfigurationException('messagesource_connectionid_required'); } }
/** * Save untranslated messages to the catalogue. */ public static function saveMessages() { static $onceonly = true; if ($onceonly) { foreach (self::$formatters as $catalogue => $formatter) { $app = Prado::getApplication()->getGlobalization(); $config = $app->getTranslationConfiguration(); if (isset($config['autosave'])) { $formatter->getSource()->setCulture($app->getCulture()); $formatter->getSource()->save($catalogue); } } $onceonly = false; } }
protected function getMysqlSqlMapManager() { static $conn; static $sqlMapManager; if (Prado::getApplication() === null) { Prado::setApplication(new TApplication(dirname(__FILE__) . '/app')); } if ($conn === null) { $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest', 'prado_unitest'); } $conn->setActive(true); if ($sqlMapManager === null) { $sqlMapManager = new TSqlMapManager($conn); $sqlMapManager->configureXml(dirname(__FILE__) . '/DynamicParameterTestMap.xml'); } return $sqlMapManager; }
/** * @param Exception exception details. * @return array exception stack trace details. */ private function getExceptionStackTrace($exception) { $data['code'] = $exception->getCode() > 0 ? $exception->getCode() : 500; $data['file'] = $exception->getFile(); $data['line'] = $exception->getLine(); $data['trace'] = $exception->getTrace(); if ($exception instanceof TPhpErrorException) { // if PHP exception, we want to show the 2nd stack level context // because the 1st stack level is of little use (it's in error handler) if (isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) { $data['file'] = $trace[0]['file']; $data['line'] = $trace[0]['line']; } } $data['type'] = get_class($exception); $data['message'] = $exception->getMessage(); $data['version'] = $_SERVER['SERVER_SOFTWARE'] . ' ' . Prado::getVersion(); $data['time'] = @strftime('%Y-%m-%d %H:%M', time()); return $data; }
/** * Loads the template from the specified file. * @return ITemplate template parsed from the specified file, null if the file doesn't exist. */ public function getTemplateByFileName($fileName) { if (($fileName = $this->getLocalizedTemplate($fileName)) !== null) { Prado::trace("Loading template {$fileName}", '\\Prado\\Web\\UI\\TTemplateManager'); if (($cache = $this->getApplication()->getCache()) === null) { return new TTemplate(file_get_contents($fileName), dirname($fileName), $fileName); } else { $array = $cache->get(self::TEMPLATE_CACHE_PREFIX . $fileName); if (is_array($array)) { list($template, $timestamps) = $array; if ($this->getApplication()->getMode() === TApplicationMode::Performance) { return $template; } $cacheValid = true; foreach ($timestamps as $tplFile => $timestamp) { if (!is_file($tplFile) || filemtime($tplFile) > $timestamp) { $cacheValid = false; break; } } if ($cacheValid) { return $template; } } $template = new TTemplate(file_get_contents($fileName), dirname($fileName), $fileName); $includedFiles = $template->getIncludedFiles(); $timestamps = array(); $timestamps[$fileName] = filemtime($fileName); foreach ($includedFiles as $includedFile) { $timestamps[$includedFile] = filemtime($includedFile); } $cache->set(self::TEMPLATE_CACHE_PREFIX . $fileName, array($template, $timestamps)); return $template; } } else { return null; } }
/** * Runs the service. * This method is invoked by application automatically. */ public function run() { $id = $this->getRequest()->getServiceParameter(); if (isset($this->_feeds[$id])) { $feedConfig = $this->_feeds[$id]; $properties = array(); $feed = null; if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { if (isset($feedConfig['class'])) { $feed = Prado::createComponent($feedConfig['class']); if ($service instanceof IFeedContentProvider) { $properties = isset($feedConfig['properties']) ? $feedConfig['properties'] : array(); } else { throw new TConfigurationException('jsonservice_response_type_invalid', $id); } } else { throw new TConfigurationException('jsonservice_class_required', $id); } } else { $properties = $feedConfig->getAttributes(); if (($class = $properties->remove('class')) !== null) { $feed = Prado::createComponent($class); if (!$feed instanceof IFeedContentProvider) { throw new TConfigurationException('feedservice_feedtype_invalid', $id); } } else { throw new TConfigurationException('feedservice_class_required', $id); } } // init feed properties foreach ($properties as $name => $value) { $feed->setSubproperty($name, $value); } $feed->init($feedConfig); $content = $feed->getFeedContent(); //$this->getResponse()->setContentType('application/rss+xml'); $this->getResponse()->setContentType($feed->getContentType()); $this->getResponse()->write($content); } else { throw new THttpException(404, 'feedservice_feed_unknown', $id); } }
/** * Returns the URLs of all stylesheet files referenced on the page * @return array List of all stylesheet urls used in the page */ public function getStyleSheetUrls() { $stylesheets = array_values(array_map(function ($e) { return is_array($e) ? $e[0] : $e; }, $this->_styleSheetFiles)); foreach (Prado::getApplication()->getAssetManager()->getPublished() as $path => $url) { if (substr($url, strlen($url) - 4) == '.css') { $stylesheets[] = $url; } } $stylesheets = array_unique($stylesheets); return $stylesheets; }
/** * Starts a transaction. * @return TDbTransaction the transaction initiated * @throws TDbException if the connection is not active */ public function beginTransaction() { if ($this->getActive()) { $this->_pdo->beginTransaction(); return $this->_transaction = Prado::createComponent($this->getTransactionClass(), $this); } else { throw new TDbException('dbconnection_connection_inactive'); } }
/** * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}. * @param TParameterProperty parameter property * @param TSqlMapTypeHandlerRegistry type handler registry * @return TSqlMapTypeHandler type handler. */ protected function createTypeHandler($property, $registry) { $type = $property->getTypeHandler() ? $property->getTypeHandler() : $property->getType(); $handler = $registry->getTypeHandler($type); if ($handler === null && $property->getTypeHandler()) { $handler = Prado::createComponent($type); } return $handler; }
/** * @param string the base path for all themes. It must be in the format of a namespace. * @throws TInvalidDataValueException if the base path is not a proper namespace. */ public function setBasePath($value) { if ($this->_initialized) { throw new TInvalidOperationException('thememanager_basepath_unchangeable'); } else { $this->_basePath = Prado::getPathOfNamespace($value); if ($this->_basePath === null || !is_dir($this->_basePath)) { throw new TInvalidDataValueException('thememanager_basepath_invalid', $value); } } }
/** * @return IPageStatePersister page state persister */ public function getStatePersister() { if ($this->_statePersister === null) { $this->_statePersister = Prado::createComponent($this->_statePersisterClass); if (!$this->_statePersister instanceof IPageStatePersister) { throw new TInvalidDataTypeException('page_statepersister_invalid'); } $this->_statePersister->setPage($this); } return $this->_statePersister; }
/** * Renders the output cache control. * This method overrides the parent implementation by capturing the output * from its child controls and saving it into cache, if output cache is needed. * @param THtmlWriter */ public function render($writer) { if ($this->_dataCached) { $writer->write($this->_contents); } else { if ($this->_cacheAvailable) { $textwriter = new TTextWriter(); $multiwriter = new TOutputCacheTextWriterMulti(array($writer->getWriter(), $textwriter)); $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $multiwriter); $stack = $this->getPage()->getCachingStack(); $stack->push($this); parent::render($htmlWriter); $stack->pop(); $content = $textwriter->flush(); $data = array($content, $this->_state, $this->_actions, time()); $this->_cache->set($this->getCacheKey(), $data, $this->getDuration(), $this->getCacheDependency()); } else { parent::render($writer); } } }
/** * Renders the callback response by adding additional callback data and * javascript actions in the header and page state if required. * @param THtmlWriter html content writer. */ protected function renderResponse($writer) { Prado::trace("ActivePage renderResponse()", 'Prado\\Web\\UI\\ActiveControls\\TActivePageAdapter'); //renders all the defered render() calls. foreach ($this->_controlsToRender as $rid => $forRender) { $forRender[0]->render($forRender[1]); } $response = $this->getResponse(); //send response data in header if ($response->getHasAdapter()) { $responseData = $response->getAdapter()->getResponseData(); if ($responseData !== null) { $data = TJavaScript::jsonEncode($responseData); $this->appendContentPart($response, self::CALLBACK_DATA_HEADER, $data); } } //sends page state in header if (($handler = $this->getCallbackEventTarget()) !== null) { if ($handler->getActiveControl()->getClientSide()->getEnablePageStateUpdate()) { $pagestate = $this->getPage()->getClientState(); $this->appendContentPart($response, self::CALLBACK_PAGESTATE_HEADER, $pagestate); } } //safari must receive at least 1 byte of data. $writer->write(" "); //output the end javascript if ($this->getPage()->getClientScript()->hasEndScripts()) { $writer = $response->createHtmlWriter(); $this->getPage()->getClientScript()->renderEndScriptsCallback($writer); $this->getPage()->getCallbackClient()->evaluateScript($writer); } //output the actions $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute(); $actions = TJavaScript::jsonEncode($executeJavascript); $this->appendContentPart($response, self::CALLBACK_ACTION_HEADER, $actions); $cs = $this->Page->getClientScript(); // collect all stylesheet file references $stylesheets = $cs->getStyleSheetUrls(); if (count($stylesheets) > 0) { $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets)); } // collect all stylesheet snippets references $stylesheets = $cs->getStyleSheetCodes(); if (count($stylesheets) > 0) { $this->appendContentPart($response, self::CALLBACK_STYLESHEET_HEADER, TJavaScript::jsonEncode($stylesheets)); } // collect all script file references $scripts = $cs->getScriptUrls(); if (count($scripts) > 0) { $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts)); } // collect all hidden field references $fields = $cs->getHiddenFields(); if (count($fields) > 0) { $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields)); } }
/** * Runs the service. * If the service parameter ends with '.wsdl', it will serve a WSDL file for * the specified soap server. * Otherwise, it will handle the soap request using the specified server. */ public function run() { Prado::trace("Running SOAP service", 'Prado\\Web\\Services\\TSoapService'); $server = $this->createServer(); $this->getResponse()->setContentType('text/xml'); $this->getResponse()->setCharset($server->getEncoding()); if ($this->getIsWsdlRequest()) { // server WSDL file Prado::trace("Generating WSDL", 'Prado\\Web\\Services\\TSoapService'); $this->getResponse()->clear(); $this->getResponse()->write($server->getWsdl()); } else { // provide SOAP service Prado::trace("Handling SOAP request", 'Prado\\Web\\Services\\TSoapService'); $server->run(); } }
/** * Runs the service. * This method is invoked by application automatically. */ public function run() { $id = $this->getRequest()->getServiceParameter(); if (isset($this->_services[$id])) { $serviceConfig = $this->_services[$id]; if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { if (isset($serviceConfig['class'])) { $service = Prado::createComponent($serviceConfig['class']); if ($service instanceof TJsonResponse) { $properties = isset($serviceConfig['properties']) ? $serviceConfig['properties'] : array(); $this->createJsonResponse($service, $properties, $serviceConfig); } else { throw new TConfigurationException('jsonservice_response_type_invalid', $id); } } else { throw new TConfigurationException('jsonservice_class_required', $id); } } else { $properties = $serviceConfig->getAttributes(); if (($class = $properties->remove('class')) !== null) { $service = Prado::createComponent($class); if ($service instanceof TJsonResponse) { $this->createJsonResponse($service, $properties, $serviceConfig); } else { throw new TConfigurationException('jsonservice_response_type_invalid', $id); } } else { throw new TConfigurationException('jsonservice_class_required', $id); } } } else { throw new THttpException(404, 'jsonservice_provider_unknown', $id); } }
/** * Copies a file to a directory. * Copying is done only when the destination file does not exist * or has an older file modification time. * @param string source file path * @param string destination directory (if not exists, it will be created) */ protected function copyFile($src, $dst) { if (!is_dir($dst)) { @mkdir($dst); @chmod($dst, PRADO_CHMOD); } $dstFile = $dst . DIRECTORY_SEPARATOR . basename($src); if (@filemtime($dstFile) < @filemtime($src)) { Prado::trace("Publishing file {$src} to {$dstFile}", 'Prado\\Web\\TAssetManager'); @copy($src, $dstFile); } }
/** * renders the translated string. */ public function render($writer) { $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter()); $subs = array(); foreach ($this->getParameters() as $key => $value) { $subs['{' . $key . '}'] = $value; } foreach ($this->getControls() as $control) { if ($control instanceof TTranslateParameter) { $subs['{' . $control->getKey() . '}'] = $control->getParameter(); } elseif ($control instanceof TControl) { $control->render($htmlWriter); } elseif (is_string($control)) { $htmlWriter->write($control); } } $text = $this->getText(); if (strlen($text) == 0) { $text = $htmlWriter->flush(); } if ($this->getTrim()) { $text = trim($text); } $writer->write($this->translateText($text, $subs)); }
/** * @param string the parameter file path. It must be in namespace format * and the file extension is '.xml'. * @throws TInvalidOperationException if the module is initialized * @throws TConfigurationException if the file is invalid */ public function setParameterFile($value) { if ($this->_initialized) { throw new TInvalidOperationException('parametermodule_parameterfile_unchangeable'); } else { if (($this->_paramFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null || !is_file($this->_paramFile)) { throw new TConfigurationException('parametermodule_parameterfile_invalid', $value); } } }
/** * Performs the actual dependency checking. * This method returns true if the currently running application is not in performance mode. * @return boolean whether the dependency is changed or not. */ public function getHasChanged() { return Prado::getApplication()->getMode() !== TApplicationMode::Performance; }