Esempio n. 1
0
 /**
  * Get Path
  *
  * @return string
  *
  * @since 1.0.0
  */
 public function getBasePath()
 {
     if (empty($this->base_path)) {
         $reflection_class = new ReflectionClass($this);
         $file_path = explode(DIRECTORY_SEPARATOR, dirname($reflection_class->getFileName()));
         $base_path = array_filter(array_slice($file_path, 0, array_search($this->getComponentName(), $file_path) + 1));
         $base_path_prefix = '';
         if (dirname($reflection_class->getFileName())[0] == DIRECTORY_SEPARATOR) {
             $base_path_prefix = DIRECTORY_SEPARATOR;
         }
         $this->base_path = $base_path_prefix . implode(DIRECTORY_SEPARATOR, $base_path);
         unset($reflection_class);
     }
     return $this->base_path;
 }
Esempio n. 2
0
 /**
  * Initialize Application
  */
 public function initialize()
 {
     //check pdo support
     $drivers = \PDO::getAvailableDrivers();
     if (empty($drivers)) {
         throw new \PDOException("PDO does not support any driver.");
     }
     if (empty($this->base_path)) {
         $reflection = new ReflectionClass(get_class($this));
         $this->base_path = dirname($reflection->getFileName());
     }
     // register autoload for Library if path exists
     $library_namespace = ucfirst(strtolower(basename($this->base_path))) . '\\Library';
     $library_path = $this->base_path . DIRECTORY_SEPARATOR . 'library';
     if (file_exists($library_path)) {
         $this->Cyan->Autoload->registerNamespace($library_namespace, $library_path);
     }
     $this->setContainer('factory_plugin', new FactoryPlugin());
     $app_config = $this->getConfig();
     if ($this->canInitializeResource('database')) {
         $database_environment = isset($app_config['database_environment']) ? $app_config['database_environment'] : 'local';
         $database_environment_identifier = sprintf('config:application.%s.database.%s', $this->getName(), $database_environment);
         $database_config = $this->Cyan->Finder->getIdentifier($database_environment_identifier, [], []);
         if (empty($database_config)) {
             $database_config = $this->Cyan->Finder->getIdentifier(sprintf('config:database.default.%s', $database_environment), [], []);
         }
         if (!empty($database_config)) {
             $this->Database->setConfig($database_config->toArray())->connect();
         } else {
             throw new ApplicationException(sprintf('Database Environment "%s" not found in path %s', $database_environment, $this->Cyan->Finder->getPath($database_environment_identifier)));
         }
     }
     Extension::addIncludePath($this->Cyan->Finder->getPath('vendor:cms.extension.type'));
     // load plugins
     $this->loadPlugins();
     // assign applications plugins to this class
     $this->getContainer('factory_plugin')->assign('application', $this);
     // add path prefix if set
     if (!empty($this->route_path)) {
         $this->Router->setRoutePathPrefix($this->route_path);
     }
     // load component structure
     $this->loadComponents($this->Cyan->Finder->getResource('components'));
     parent::initialize();
 }