示例#1
0
 /**
  * Construct a new modX instance.
  *
  * @param string $configPath An absolute filesystem path to look for the config file.
  * @param array $options Options that can be passed to the instance.
  * @return modX A new modX instance.
  */
 public function __construct($configPath = '', array $options = array())
 {
     global $database_type, $database_server, $dbase, $database_user, $database_password, $database_connection_charset, $table_prefix;
     modX::protect();
     if (empty($configPath)) {
         $configPath = MODX_CORE_PATH . 'config/';
     }
     if (@(include $configPath . MODX_CONFIG_KEY . '.inc.php')) {
         $cachePath = MODX_CORE_PATH . 'cache/';
         if (MODX_CONFIG_KEY !== 'config') {
             $cachePath .= MODX_CONFIG_KEY . '/';
         }
         $options = array_merge(array(xPDO::OPT_CACHE_PATH => $cachePath, xPDO::OPT_TABLE_PREFIX => $table_prefix, xPDO::OPT_HYDRATE_FIELDS => true, xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, xPDO::OPT_LOADER_CLASSES => array('modAccessibleObject'), xPDO::OPT_VALIDATOR_CLASS => 'validation.modValidator', xPDO::OPT_VALIDATE_ON_SAVE => true, 'cache_system_settings' => true), $options);
         parent::__construct($database_type . ':host=' . $database_server . ';dbname=' . trim($dbase, '`') . ';charset=' . $database_connection_charset, $database_user, $database_password, $options, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_PERSISTENT => false, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
         $this->setPackage('modx', MODX_CORE_PATH . 'model/', $table_prefix);
         $this->setLogTarget($this->getOption('log_target', null, 'FILE'));
         if (!empty($site_id)) {
             $this->site_id = $site_id;
         }
     } else {
         $this->sendError($this->getOption('error_type', null, 'unavailable'), $options);
     }
 }
示例#2
0
 /**
  * Construct a new modX instance.
  *
  * @param string $configPath An absolute filesystem path to look for the config file.
  * @param array $options Options that can be passed to the instance.
  * @return modX A new modX instance.
  */
 public function __construct($configPath = '', array $options = array())
 {
     global $database_dsn, $database_user, $database_password, $config_options, $table_prefix, $site_id, $uuid;
     modX::protect();
     if (empty($configPath)) {
         $configPath = MODX_CORE_PATH . 'config/';
     }
     if (@(include $configPath . MODX_CONFIG_KEY . '.inc.php')) {
         $cachePath = MODX_CORE_PATH . 'cache/';
         if (MODX_CONFIG_KEY !== 'config') {
             $cachePath .= MODX_CONFIG_KEY . '/';
         }
         $options = array_merge(array(xPDO::OPT_CACHE_KEY => 'default', xPDO::OPT_CACHE_HANDLER => 'xPDOFileCache', xPDO::OPT_CACHE_PATH => $cachePath, xPDO::OPT_TABLE_PREFIX => $table_prefix, xPDO::OPT_HYDRATE_FIELDS => true, xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, xPDO::OPT_LOADER_CLASSES => array('modAccessibleObject'), xPDO::OPT_VALIDATOR_CLASS => 'validation.modValidator', xPDO::OPT_VALIDATE_ON_SAVE => true, 'cache_system_settings' => true, 'cache_system_settings_key' => 'system_settings'), $config_options, $options);
         parent::__construct($database_dsn, $database_user, $database_password, $options, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_PERSISTENT => false));
         $this->setPackage('modx', MODX_CORE_PATH . 'model/', $table_prefix);
         $this->setLogTarget($this->getOption('log_target', null, 'FILE'));
         if (!empty($site_id)) {
             $this->site_id = $site_id;
         }
         if (!empty($uuid)) {
             $this->uuid = $uuid;
         }
     } else {
         $this->sendError($this->getOption('error_type', null, 'unavailable'), $options);
     }
 }
示例#3
0
 /**
  * Load the modX configuration when creating an instance of modX.
  *
  * @param string $configPath An absolute path location to search for the modX config file.
  * @param array $data Data provided to initialize the instance with, overriding config file entries.
  * @param null $driverOptions Driver options for the primary connection.
  * @return array The merged config data ready for use by the modX::__construct() method.
  */
 protected function loadConfig($configPath = '', $data = array(), $driverOptions = null)
 {
     if (!is_array($data)) {
         $data = array();
     }
     modX::protect();
     if (!defined('MODX_CONFIG_KEY')) {
         define('MODX_CONFIG_KEY', 'config');
     }
     if (empty($configPath)) {
         $configPath = MODX_CORE_PATH . 'config/';
     }
     global $database_dsn, $database_user, $database_password, $config_options, $driver_options, $table_prefix, $site_id, $uuid;
     if (file_exists($configPath . MODX_CONFIG_KEY . '.inc.php') && (include $configPath . MODX_CONFIG_KEY . '.inc.php')) {
         $cachePath = MODX_CORE_PATH . 'cache/';
         if (MODX_CONFIG_KEY !== 'config') {
             $cachePath .= MODX_CONFIG_KEY . '/';
         }
         if (!is_array($config_options)) {
             $config_options = array();
         }
         if (!is_array($driver_options)) {
             $driver_options = array();
         }
         $data = array_merge(array(xPDO::OPT_CACHE_KEY => 'default', xPDO::OPT_CACHE_HANDLER => 'xPDOFileCache', xPDO::OPT_CACHE_PATH => $cachePath, xPDO::OPT_TABLE_PREFIX => $table_prefix, xPDO::OPT_HYDRATE_FIELDS => true, xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, xPDO::OPT_VALIDATOR_CLASS => 'validation.modValidator', xPDO::OPT_VALIDATE_ON_SAVE => true, 'cache_system_settings' => true, 'cache_system_settings_key' => 'system_settings'), $config_options, $data);
         $primaryConnection = array('dsn' => $database_dsn, 'username' => $database_user, 'password' => $database_password, 'options' => array(xPDO::OPT_CONN_MUTABLE => isset($data[xPDO::OPT_CONN_MUTABLE]) ? (bool) $data[xPDO::OPT_CONN_MUTABLE] : true), 'driverOptions' => $driver_options);
         if (!array_key_exists(xPDO::OPT_CONNECTIONS, $data) || !is_array($data[xPDO::OPT_CONNECTIONS])) {
             $data[xPDO::OPT_CONNECTIONS] = array();
         }
         array_unshift($data[xPDO::OPT_CONNECTIONS], $primaryConnection);
         if (!empty($site_id)) {
             $this->site_id = $site_id;
         }
         if (!empty($uuid)) {
             $this->uuid = $uuid;
         }
     } else {
         throw new xPDOException("Could not load MODX config file.");
     }
     return $data;
 }
示例#4
0
 /**
  * Construct a new modX instance.
  *
  * @param string $configPath An absolute filesystem path to look for the config file.
  * @param array $options Options that can be passed to the instance.
  * @return modX A new modX instance.
  */
 public function __construct($configPath = '', array $options = array())
 {
     global $database_dsn, $database_user, $database_password, $config_options, $table_prefix, $site_id, $uuid;
     modX::protect();
     if (!defined('MODX_CONFIG_KEY')) {
         define('MODX_CONFIG_KEY', 'config');
     }
     if (empty($configPath)) {
         $configPath = MODX_CORE_PATH . 'config/';
     }
     if (@(include $configPath . MODX_CONFIG_KEY . '.inc.php')) {
         $cachePath = MODX_CORE_PATH . 'cache/';
         if (MODX_CONFIG_KEY !== 'config') {
             $cachePath .= MODX_CONFIG_KEY . '/';
         }
         $options = array_merge(array(xPDO::OPT_CACHE_KEY => 'default', xPDO::OPT_CACHE_HANDLER => 'xPDOFileCache', xPDO::OPT_CACHE_PATH => $cachePath, xPDO::OPT_TABLE_PREFIX => $table_prefix, xPDO::OPT_HYDRATE_FIELDS => true, xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, xPDO::OPT_VALIDATOR_CLASS => 'validation.modValidator', xPDO::OPT_VALIDATE_ON_SAVE => true, 'cache_system_settings' => true, 'cache_system_settings_key' => 'system_settings'), $config_options, $options);
         parent::__construct($database_dsn, $database_user, $database_password, $options, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_PERSISTENT => false));
         $this->setLogLevel($this->getOption('log_level', null, xPDO::LOG_LEVEL_ERROR));
         $this->setLogTarget($this->getOption('log_target', null, 'FILE'));
         $debug = $this->getOption('debug');
         switch ($debug) {
             case null:
             case '':
                 break;
             case true:
             case 1:
             case '1':
                 $this->setDebug(true);
                 break;
             case false:
             case 0:
             case '0':
                 $this->setDebug(false);
                 break;
             default:
                 if ((int) $debug > 1) {
                     $this->setDebug($debug);
                 }
                 break;
         }
         $this->setPackage('modx', MODX_CORE_PATH . 'model/', $table_prefix);
         if (!empty($site_id)) {
             $this->site_id = $site_id;
         }
         if (!empty($uuid)) {
             $this->uuid = $uuid;
         }
     } else {
         $this->sendError($this->getOption('error_type', null, 'unavailable'), $options);
     }
 }