Ejemplo n.º 1
0
 /**
  * Load configuration from all files.
  *
  * @param string $stage Configuration stage.
  *
  * @throws Exception
  * @return Config
  */
 protected static function _getConfiguration($stage)
 {
     $config = new Config([], $stage);
     $configDirectory = ROOT_PATH . self::CONFIG_PATH . $stage;
     $configFiles = glob($configDirectory . '/*.php');
     foreach ($configFiles as $file) {
         $data = (include_once $file);
         $config->offsetSet(basename($file, ".php"), $data);
     }
     $config->offsetSet('events', []);
     $config->offsetSet('modules', explode(',', self::CONFIG_MODULES_WILL_LOAD));
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     /**
      * Create default DI.
      */
     $di = new DI\FactoryDefault();
     /**
      * Get config.
      */
     $this->_config = Config::factory();
     if (!$this->_config->installed) {
         define('CHECK_REQUIREMENTS', true);
         require_once PUBLIC_PATH . '/requirements.php';
     }
     /**
      * Setup Registry.
      */
     $registry = new Registry();
     $registry->modules = array_merge([self::SYSTEM_DEFAULT_MODULE, 'user'], $this->_config->modules->toArray());
     $registry->widgets = $this->_config->widgets->toArray();
     $registry->directories = (object) ['engine' => ROOT_PATH . '/app/engine/', 'modules' => ROOT_PATH . '/app/modules/', 'plugins' => ROOT_PATH . '/app/plugins/', 'widgets' => ROOT_PATH . '/app/widgets/', 'libraries' => ROOT_PATH . '/app/libraries/'];
     $di->set('registry', $registry);
     // Store config in the DI container.
     $di->setShared('config', $this->_config);
     parent::__construct($di);
 }
Ejemplo n.º 3
0
 /**
  * Get html for config.
  *
  * @return string
  */
 private function _getHtmlConfig()
 {
     $html = '';
     $configData = $this->_config->toArray();
     uasort($configData['application'], function ($a, $b) {
         if (is_array($a) && !is_array($b)) {
             return 1;
         }
         return 0;
     });
     foreach ($configData as $key => $data) {
         if (!is_array($data) || empty($data) || $key == 'database') {
             continue;
         }
         $html .= $this->_viewRenderTitle(ucfirst($key));
         $html .= $this->_renderConfigSection($data);
         $html .= '<br/>';
     }
     return $html;
 }
Ejemplo n.º 4
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     /**
      * Create default DI.
      */
     $di = new DI\FactoryDefault();
     /**
      * Get config.
      */
     $this->_config = Config::factory();
     /**
      * Adding modules to registry to load.
      * Module namespace - directory will be load from here.
      */
     $registry = new PhRegistry();
     $registry->modules = array_merge([self::SYSTEM_DEFAULT_MODULE], $this->_config->modules->toArray());
     $registry->directories = (object) ['engine' => ROOT_PATH . '/app/engine/', 'modules' => ROOT_PATH . '/app/modules/'];
     $di->set('registry', $registry);
     /**
      * Store config in the DI container.
      */
     $di->setShared('config', $this->_config);
     parent::__construct($di);
 }
Ejemplo n.º 5
0
 /**
  * Load configuration from all files.
  *
  * @param string $stage Configuration stage.
  *
  * @throws Exception
  * @return Config
  */
 protected static function _getConfiguration($stage)
 {
     $config = new Config(null, $stage);
     $configDirectory = ROOT_PATH . self::CONFIG_PATH . $stage;
     $configFiles = glob($configDirectory . '/*.php');
     // create config files from .dist
     if (!$configFiles) {
         foreach (glob($configDirectory . '/*.dist') as $file) {
             $configFile = substr($file, 0, -5);
             copy($file, $configFile);
             $configFiles[] = $configFile;
         }
     }
     foreach ($configFiles as $file) {
         $data = (include_once $file);
         $config->offsetSet(basename($file, ".php"), $data);
     }
     $appPath = ROOT_PATH . self::CONFIG_METADATA_APP;
     if (!file_exists($appPath)) {
         $config->offsetSet('installed', false);
         $config->offsetSet('events', array());
         $config->offsetSet('modules', array());
         $config->offsetSet('widgets', array());
         return $config;
     }
     $data = (include_once $appPath);
     $config->merge(new Config($data));
     return $config;
 }
Ejemplo n.º 6
0
 /**
  * Check package dependencies.
  *
  * @param Config $manifest Package manifest.
  *
  * @throws PackageException
  * @return void
  */
 private function _checkDependencies($manifest)
 {
     // Check dependencies.
     if (!$manifest->get('dependencies')) {
         return;
     }
     $filter = new PhalconFilter();
     $missingDependencies = [];
     $wrongVersionDependencies = [];
     $dependencies = $manifest->get('dependencies');
     foreach ($dependencies as $dependency) {
         if (!isset($this->_packagesVersions[$dependency['type']][$dependency['name']])) {
             $missingDependencies[] = $dependency;
             continue;
         }
         $installedVersion = $filter->sanitize($this->_packagesVersions[$dependency['type']][$dependency['name']], 'int');
         $packageDependecyVersion = $filter->sanitize($dependency['version'], 'int');
         if ($installedVersion < $packageDependecyVersion) {
             $wrongVersionDependencies[] = $dependency;
         }
     }
     if (!empty($missingDependencies)) {
         $msg = 'This package requires the presence of the following modules:<br/>';
         foreach ($missingDependencies as $dependency) {
             $msg .= sprintf('- %s "%s" (v.%s)<br/>', $dependency['type'], $dependency['name'], $dependency['version']);
         }
         throw new PackageException($msg);
     }
     if (!empty($wrongVersionDependencies)) {
         $msg = 'To install this package you need update:<br/>';
         foreach ($wrongVersionDependencies as $dependency) {
             $msg .= sprintf('- %s "%s" up to: v.%s. Current version: v.%s <br/>', $dependency['type'], $dependency['name'], $dependency['version'], $this->_packagesVersions[$dependency['type']][$dependency['name']]);
         }
         throw new PackageException($msg);
     }
 }