/** * Create application. * @param string $appPath Path to app-directory containing at least an * 'app.json' configuration file. * @param string $userPath Path to user-directory. * @param string $entryScript Name of entry script, e.g. 'index.php'. */ public function __construct($appPath, $userPath, $entryScript = 'index.php') { parent::__construct(); $this->logger = ErrorHandler::getInstance()->getLogger(); $appPath = Utilities::convertPath($appPath); $userPath = Utilities::convertPath($userPath); $manifestFile = $appPath . '/app.json'; if (file_exists($manifestFile)) { $manifest = Json::decodeFile($manifestFile); $manifest = array_merge($this->defaultManifest, $manifest); } else { $this->logger->error('Invalid application. "app.json" not found. Configuring default application.'); $this->noManifest = true; $manifest = $this->defaultManifest; } $this->manifest = $manifest; $this->m = new ModuleLoader(); $this->paths = new Paths(Paths::convertPath(getcwd()), $userPath); $this->paths->app = $appPath; $this->paths->user = $userPath; // $this->basePath = dirname($_SERVER['SCRIPT_NAME']); $this->entryScript = $entryScript; // Temporary work-around for weird SCRIPT_NAME. // When url contains a trailing dot such as // /app/index.php/admin./something // SCRIPT_NAME returns /app/index.php/admin./something instead of expected // /app/index.php $script = explode('/', $_SERVER['SCRIPT_NAME']); while (count($script) > 0) { if ($script[count($script) - 1] == $entryScript) { break; } array_pop($script); } $this->basePath = dirname(implode('/', $script)); // END work-around $this->name = $manifest['name']; $this->version = $manifest['version']; $this->namespace = $manifest['namespace']; Autoloader::getInstance()->addPath($this->namespace, $this->p('app')); $this->paths->Jivoo = \Jivoo\PATH; $this->paths->Core = \Jivoo\PATH . '/Core'; $file = new PhpStore($this->p('user/config.php')); $this->config = new Document(); $this->config['user'] = new Config($file); }