Esempio n. 1
0
 /**
  * Find and import a library.
  * @param string $name Library name.
  */
 public function import($name)
 {
     if (isset($this->imported[$name])) {
         return;
     }
     $manifest = null;
     foreach ($this->paths as $path => $reader) {
         $path = $path . '/' . $name;
         if (is_dir($path)) {
             $manifest = $reader->read($name, $path);
             if (isset($manifest)) {
                 break;
             }
         }
     }
     if (!isset($manifest)) {
         throw new ImportException(tr('Could not import library: %1', $name));
     }
     $manifest->load(Autoloader::getInstance());
     $this->imported[$name] = true;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function load(Autoloader $autoloader)
 {
     if (!isset($this->manifest['autoload']) or !is_array($this->manifest['autoload'])) {
         return;
     }
     if (isset($this->manifest['autoload']['psr-4'])) {
         assume(is_array($this->manifest['autoload']['psr-4']));
         foreach ($this->manifest['autoload']['psr-4'] as $namespace => $path) {
             if (is_array($path)) {
                 foreach ($path as $p) {
                     $autoloader->addPath($namespace, $this->path . '/' . trim($p, '/'));
                 }
             } else {
                 $autoloader->addPath($namespace, $this->path . '/' . trim($path, '/'));
             }
         }
     }
     if (isset($this->manifest['autoload']['psr-0'])) {
         assume(is_array($this->manifest['autoload']['psr-0']));
         foreach ($this->manifest['autoload']['psr-0'] as $namespace => $path) {
             if (is_array($path)) {
                 foreach ($path as $p) {
                     $autoloader->addPath($namespace, $this->path . '/' . trim($p, '/'), false, true);
                 }
             } else {
                 $autoloader->addPath($namespace, $this->path . '/' . trim($path, '/'), false, true);
             }
         }
     }
     if (isset($this->manifest['autoload']['classmap'])) {
         assume(false, 'classmap support not implemented');
     }
     if (isset($this->manifest['autoload']['files'])) {
         assume(is_array($this->manifest['autoload']['files']));
         foreach ($this->manifest['autoload']['files'] as $file) {
             require $this->path . '/' . $file;
         }
     }
 }
Esempio n. 3
0
File: App.php Progetto: 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);
 }
Esempio n. 4
0
 /**
  * Find migrations for a database.
  *
  * @param string $name
  *            Database name.
  * @return string[] List of migration class names.
  */
 public function getMigrations($name)
 {
     $migrationDir = $this->migrationDirs[$name];
     $migrations = array();
     if (is_dir($migrationDir)) {
         Autoloader::getInstance()->addPath('', $migrationDir);
         $files = scandir($migrationDir);
         if ($files !== false) {
             foreach ($files as $file) {
                 $split = explode('.', $file);
                 if (isset($split[1]) and $split[1] == 'php') {
                     $migrations[] = $split[0];
                 }
             }
         }
     }
     sort($migrations);
     return $migrations;
 }
Esempio n. 5
0
 /**
  * Import a single extension.
  * @param string $extension Extension name.
  */
 public function import($extension)
 {
     if (isset($this->imported[$extension])) {
         if (!$this->imported[$extension]) {
             throw new InvalidExtensionException(tr('Extension not found or invalid: "%1"', $extension));
         }
         return;
     }
     $this->imported[$extension] = false;
     $extensionInfo = $this->getInfo($extension);
     if (!isset($extensionInfo)) {
         throw new InvalidExtensionException(tr('Extension not found or invalid: "%1"', $extension));
     }
     if (isset($extensionInfo->namespace)) {
         Autoloader::getInstance()->addPath($extensionInfo->namespace, $extensionInfo->p($this->app, ''));
     } else {
         Autoloader::getInstance()->addPath('', $extensionInfo->p($this->app, ''));
     }
     $extensionInfo->imported = true;
     if (is_dir($extensionInfo->p($this->app, 'languages'))) {
         I18n::loadFrom($extensionInfo->p($this->app, 'languages'));
     }
     foreach ($extensionInfo->loadAfter as $dependency) {
         $this->import($dependency);
         $this->getInfo($dependency)->requiredBy($extension);
     }
     foreach ($this->featureHandlers as $tuple) {
         list($feature, $handler) = $tuple;
         if (isset($extensionInfo->{$feature})) {
             call_user_func($handler, $extensionInfo);
         }
     }
     $this->imported[$extension] = true;
 }