/** * Runtime initializations based on the application specification. * Derived classes can override this method to provide additional initializations. */ protected function init() { foreach ($this->preload as $namespace) { using($namespace); } $locatorClass = $this->handlers['locator']; $parserClass = $this->handlers['parser']; $cacheClass = $this->handlers['cache']; $errorClass = $this->handlers['error']; $requestClass = $this->handlers['request']; $sessionClass = $this->handlers['session']; $vsmClass = $this->handlers['vsmanager']; $globalizationClass = $this->handlers['globalization']; $serviceManagerClass = $this->handlers['services']; $this->resourceLocator = new $locatorClass($this->specification->locator); $this->resourceParser = new $parserClass($this->specification->parser); $this->cacheManager = new $cacheClass($this->specification->cache); $this->errorHandler = new $errorClass($this->specification->error); $this->request = new $requestClass($this->specification->request); $this->session = new $sessionClass($this->specification->session); $this->vsm = new $vsmClass($this->specification->vsmanager); $this->services = new $serviceManagerClass($this->specification->services); $this->session->start(); $userClass = $this->handlers['user']; if (!empty($userClass)) { if ($this->session->has($this->id . ':' . self::SESSION_USER)) { $this->user = pradoUnserializeObject($this->session->get($this->id . ':' . self::SESSION_USER)); } if (!$this->user instanceof IUser) { $this->user = new $userClass($this->specification->user); } if (!$this->user instanceof IUser) { throw new Exception('User class must implement IUser interface.'); } } // load the theme if one was declared in the app.spec file if (is_file($this->getThemeFile())) { $this->theme = $this->getResourceParser()->parseTheme(file_get_contents($this->getThemeFile())); } //globalization should be last, it may require Request, Session, Resource and User if ($this->specification->globalization->length) { $this->globalization = new $globalizationClass($this->specification->globalization); } }
/** * 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; }