示例#1
0
 /**
  * Get information about a database driver.
  *
  * The returned information array is of the format:
  * <code>
  * array(
  *   'driver' => ..., // Driver name (string)
  *   'name' => ..., // Formal name, e.g. 'MySQL' instead of 'MySql' (string)
  *   'requiredOptions' => array(...), // List of required options (string[])
  *   'optionalOptions' => array(...), // List of optional options (string[])
  *   'isAvailable' => ..., // Whether or not driver is available (bool)
  *   'missingExtensions => array(...) // List of missing extensions (string[])
  * )
  * </code>
  * @param string $driver Driver name
  * @return array Driver information as an associative array.
  * @throws InvalidDriverException If driver is missing or invalid.
  */
 public function checkDriver($driver)
 {
     if (!file_exists($this->p('Jivoo/Databases/Drivers/' . $driver . '/' . $driver . 'Database.php'))) {
         throw new InvalidDriverException(tr('Driver class not found: %1', $driver));
     }
     if (!file_exists($this->p('Jivoo/Databases/Drivers/' . $driver . '/driver.json'))) {
         throw new InvalidDriverException(tr('Driver manifest not found: %1', $driver));
     }
     try {
         $info = Json::decodeFile($this->p('Jivoo/Databases/Drivers/' . $driver . '/driver.json'));
     } catch (JsonException $e) {
         throw new InvalidDriverException(tr('Invalid driver manifest: %1 (%2)', $driver, $e->getMessage()), 0, $e);
     }
     if (!isset($info['required'])) {
         $info['required'] = array();
     }
     if (!isset($info['optional'])) {
         $info['optional'] = array();
     }
     if (!isset($info['phpExtensions'])) {
         $info['phpExtensions'] = array();
     }
     $missing = array();
     foreach ($info['phpExtensions'] as $dependency) {
         if (!extension_loaded($dependency)) {
             $missing[] = $dependency;
         }
     }
     return array('driver' => $driver, 'name' => $info['name'], 'requiredOptions' => $info['required'], 'optionalOptions' => $info['optional'], 'isAvailable' => count($missing) < 1, 'missingExtensions' => $missing);
 }
示例#2
0
文件: Themes.php 项目: jivoo/jivoo
 /**
  * Get information about a theme.
  * @param string $theme Theme name.
  * @return ThemeInfo|null Theme information or null if theme not found or
  * invalid. Will produce a warning if the JSON file is invalid.
  */
 public function getInfo($theme)
 {
     if (!isset($this->info[$theme])) {
         $dir = $this->p('themes', $theme);
         $library = null;
         if (!file_exists($dir . '/theme.json')) {
             foreach ($this->libraries as $key) {
                 $dir = $this->p($key, 'themes/' . $theme);
                 if (file_exists($dir . '/theme.json')) {
                     $library = $key;
                 }
             }
             if (!isset($library)) {
                 return null;
             }
         }
         $info = Json::decodeFile($dir . '/theme.json');
         if (!$info) {
             $this->logger->warning(tr('The theme "%1" has an invalid json file.', $theme));
             return null;
         }
         $this->info[$theme] = new ThemeInfo($theme, $info, array(), $library);
     }
     return $this->info[$theme];
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function read($name, $path)
 {
     $file = $path . '/' . $this->getFileName();
     if (!file_exists($file)) {
         return null;
     }
     try {
         $manifest = Json::decodeFile($file);
     } catch (JsonException $e) {
         return null;
     }
     if (!isset($manifest['name'])) {
         $manifest['name'] = $name;
     }
     return $this->getPackage($manifest, $path);
 }
示例#4
0
文件: App.php 项目: jivoo/jivoo
 /**
  * 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);
 }
示例#5
0
 /**
  * Get extension information.
  * @param string $extension Extension name.
  * @param string $kind Extension kind.
  * @return ExtensionInfo|null Extension information or null if not found or
  * invalid.
  */
 public function getInfo($extension, $kind = 'extensions')
 {
     if (!isset($this->info[$extension])) {
         $dir = $this->p($kind, $extension);
         $manifest = $this->kinds[$kind]['manifest'] . '.json';
         $library = null;
         if (!file_exists($dir . '/' . $manifest)) {
             foreach ($this->libraries as $key) {
                 $dir = $this->p($key, $kind . '/' . $extension);
                 if (file_exists($dir . '/' . $manifest)) {
                     $library = $key;
                 }
             }
             if (!isset($library)) {
                 return null;
             }
         }
         try {
             $info = Json::decodeFile($dir . '/' . $manifest);
         } catch (JsonException $e) {
             $this->logger->error(tr('Error decoding JSON: %1', $dir . '/' . $manifest));
             return null;
         }
         $this->info[$extension] = new ExtensionInfo($extension, $info, $library, $this->isEnabled($extension));
     }
     return $this->info[$extension];
 }