コード例 #1
0
 /**
  * Request cleanup work.
  * Default implementation will save the user object to session if possible.
  * The method is invoked at the end of {@link run} and {@link transfer}.
  * Derived classes can override this method to provide customized cleanup work.
  * Parent implementation should be invoked.
  */
 protected function endRequest()
 {
     if (!is_null($this->session) && $this->session->isStarted() && !is_null($this->user)) {
         $this->session->set($this->id . ':' . self::SESSION_USER, pradoSerializeObject($this->user));
     }
     foreach ($this->modules as $module) {
         $module->onUnload(new TEventParameter());
     }
 }
コード例 #2
0
/**
 * Returns the application singleton.
 *
 * In the first invocation of the method, it will construct an application instance
 * by either loading from a previously serialized instance from $cacheFile
 * or creating a new one based on the specification file $specFile.
 *
 * In the following invocations, the parameters can be omitted and the singleton is returned.
 *
 * @param string path of the application specification file (either absolute or relative to current requesting script)
 * @param string path of the cache file that stores serialized TApplication instance
 * @param string the application class name, TApplication by default.
 * @return TApplication the application singleton
 */
function pradoGetApplication($specFile = '', $cacheFile = '', $className = 'TApplication')
{
    static $application = null;
    if (!strlen($specFile)) {
        return $application;
    }
    if (strlen($cacheFile) && is_file($cacheFile)) {
        $application = pradoUnserializeObject(file_get_contents($cacheFile));
    } else {
        if (strlen($specFile)) {
            $application = new $className($specFile);
            if (!$application instanceof TApplication) {
                throw new TApplicationInheritanceException($className);
            }
            // serialize the application instance and save it to cache
            if (strlen($cacheFile) && ($fp = fopen($cacheFile, "wb"))) {
                fputs($fp, pradoSerializeObject($application));
                fclose($fp);
            }
        }
    }
    using('System');
    using('System.Web.UI');
    using('System.Exception');
    return $application;
}