protected function getCache()
 {
     if (!$this->_cache) {
         $this->_cache = Prado::getApplication()->getCache();
     }
     return $this->_cache;
 }
示例#2
0
 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);
 }
示例#3
0
 /**
  * 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;
 }
 /**
  * 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');
     }
 }
示例#5
0
 /**
  * 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;
     }
 }
示例#6
0
 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;
 }
 /**
  * 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;
 }
示例#8
0
 /**
  * @param string external configuration file in namespace format. The file
  * must be suffixed with '.xml'.
  * @throws TInvalidDataValueException if the file is invalid.
  */
 public function setConfigFile($value)
 {
     if (($this->_configFile = Prado::getPathOfNamespace($value, Prado::getApplication()->getConfigurationFileExt())) === null) {
         throw new TConfigurationException('soapservice_configfile_invalid', $value);
     }
 }
示例#9
0
 /**
  * Apply behavior of {@link SecureConnection} property by conditionaly prefixing
  * URL with {@link THttpRequest::getBaseUrl()}
  *
  * @param string $url
  * @return string
  * @since 3.2
  */
 protected function applySecureConnectionPrefix($url)
 {
     static $request;
     if ($request === null) {
         $request = Prado::getApplication()->getRequest();
     }
     static $isSecureConnection;
     if ($isSecureConnection === null) {
         $isSecureConnection = $request->getIsSecureConnection();
     }
     switch ($this->getSecureConnection()) {
         case TUrlMappingPatternSecureConnection::EnableIfNotSecure:
             if ($isSecureConnection) {
                 return $url;
             }
             return $request->getBaseUrl(true) . $url;
             break;
         case TUrlMappingPatternSecureConnection::DisableIfSecure:
             if (!$isSecureConnection) {
                 return $url;
             }
             return $request->getBaseUrl(false) . $url;
             break;
         case TUrlMappingPatternSecureConnection::Enable:
             return $request->getBaseUrl(true) . $url;
             break;
         case TUrlMappingPatternSecureConnection::Disable:
             return $request->getBaseUrl(false) . $url;
             break;
         case TUrlMappingPatternSecureConnection::Automatic:
         default:
             return $url;
             break;
     }
 }
示例#10
0
 /**
  * Applies a page configuration.
  * @param TPageConfiguration the configuration
  */
 protected function applyConfiguration($config)
 {
     // initial page properties (to be set when page runs)
     $this->_properties = array_merge($this->_properties, $config->getProperties());
     $this->getApplication()->getAuthorizationRules()->mergeWith($config->getRules());
     $pagePath = $this->getRequestedPagePath();
     // external configurations
     foreach ($config->getExternalConfigurations() as $filePath => $params) {
         list($configPagePath, $condition) = $params;
         if ($condition !== true) {
             $condition = $this->evaluateExpression($condition);
         }
         if ($condition) {
             if (($path = Prado::getPathOfNamespace($filePath, Prado::getApplication()->getConfigurationFileExt())) === null || !is_file($path)) {
                 throw new TConfigurationException('pageservice_includefile_invalid', $filePath);
             }
             $c = new TPageConfiguration($pagePath);
             $c->loadFromFile($path, $configPagePath);
             $this->applyConfiguration($c);
         }
     }
 }
示例#11
0
 /**
  * @return ICache Application cache instance.
  */
 protected function getCache()
 {
     return Prado::getApplication()->getCache();
 }
示例#12
0
 /**
  * Encodes a PHP variable into javascript string.
  * This method invokes json_encode to perform the encoding.
  * @param mixed variable to be encoded
  * @return string encoded string
  */
 public static function jsonEncode($value, $options = 0)
 {
     if (($g = Prado::getApplication()->getGlobalization(false)) !== null && strtoupper($enc = $g->getCharset()) != 'UTF-8') {
         self::convertToUtf8($value, $enc);
     }
     $s = @json_encode($value, $options);
     self::checkJsonError();
     return $s;
 }
 /**
  * Performs the actual dependency checking.
  * This method returns true if the specified global state is changed.
  * @return boolean whether the dependency is changed or not.
  */
 public function getHasChanged()
 {
     return $this->_stateValue !== Prado::getApplication()->getGlobalState($this->_stateName);
 }
示例#14
0
 protected function popParamsByToken($token)
 {
     if ($cache = Prado::getApplication()->getCache()) {
         $v = $cache->get($token);
         assert($v != '');
         $cache->delete($token);
         // remove it from cache so it can't be used again and won't take up space either
         $params = unserialize($v);
     } else {
         if ($mgr = Prado::getApplication()->getSecurityManager()) {
             $v = $mgr->decrypt(base64_decode(urldecode($token)));
             $params = unserialize($v);
         } else {
             throw new Exception('TActiveFileUpload needs either an application level cache or a security manager to work securely');
         }
     }
     assert($params instanceof TActiveFileUploadCallbackParams);
     return $params;
 }
示例#15
0
 /**
  * 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;
 }
示例#16
0
 /**
  * Loads a specific config file.
  * @param string config file name
  * @param string the page path that the config file is associated with. The page path doesn't include the page name.
  */
 public function loadFromFile($fname, $configPagePath)
 {
     Prado::trace("Loading page configuration file {$fname}", 'System.Web.Services.TPageService');
     if (empty($fname) || !is_file($fname)) {
         return;
     }
     if (Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
         $fcontent = (include $fname);
         $this->loadFromPhp($fcontent, dirname($fname), $configPagePath);
     } else {
         $dom = new TXmlDocument();
         if ($dom->loadFromFile($fname)) {
             $this->loadFromXml($dom, dirname($fname), $configPagePath);
         } else {
             throw new TConfigurationException('pageserviceconf_file_invalid', $fname);
         }
     }
 }
 /**
  * @return ICache the cache module being used for data storage
  */
 public function getCache()
 {
     if ($this->_cache === null) {
         if ($this->_cacheModuleID !== '') {
             $cache = Prado::getApplication()->getModule($this->_cacheModuleID);
         } else {
             $cache = Prado::getApplication()->getCache();
         }
         if ($cache === null || !$cache instanceof ICache) {
             if ($this->_cacheModuleID !== '') {
                 throw new TConfigurationException('cachepagestatepersister_cachemoduleid_invalid', $this->_cacheModuleID);
             } else {
                 throw new TConfigurationException('cachepagestatepersister_cache_required');
             }
         }
         $this->_cache = $cache;
     }
     return $this->_cache;
 }