예제 #1
0
 protected function initialize()
 {
     $this->config = ConfigManager::bind();
     // setting limit time
     set_time_limit($this->config['webbot']['time_limit']);
     $this->container = new Pimple();
     // initializing persistence
     $config = $this->config;
     if ($config['general']['persistence']['use_database']) {
         if (!isset($config['general']['persistence']['connections'])) {
             throw new ConfigurationAccessException(101);
         }
         if (!is_array($config['general']['persistence']['connections']) || count($config['general']['persistence']['connections']) < 1) {
             throw new ConfigurationAccessException(102);
         }
         $connections = $config['general']['persistence']['connections'];
         // initializing ActiveRecord
         ActiveRecord\Config::initialize(function ($cfg) use($connections, $config) {
             $cfg->set_model_directory($config->getBaseDir() . '/' . $config['general']['persistence']['models_dir']);
             $cfg->set_connections($connections);
             // assigning as default conection the first one
             $default_con_index = array_shift(array_keys($connections));
             $cfg->set_default_connection($default_con_index);
         });
     }
     $this->loadStartups();
 }
예제 #2
0
/**
 * Load classes of php-activerecord framework
 * 
 * @param string
 * @return void
 */

function activerecord_autoload($class_name)
{
	$path = ActiveRecord\Config::instance()->get_model_directory();
	$root = realpath(isset($path) ? $path : '.');

	if (($namespaces = ActiveRecord\get_namespaces($class_name)))
	{
		$class_name = array_pop($namespaces);
		$directories = array();

		foreach ($namespaces as $directory)
		{
		    $directories[] = $directory;
		}

		$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
	}

	$file = "$root/$class_name.php";

	if (file_exists($file))
	{
	    require $file;
	}
}
function activerecord_autoload($class_name)
{
    $path = ActiveRecord\Config::instance()->get_model_directory();
    $root = realpath(isset($path) ? $path : '.');
    if ($namespaces = ActiveRecord\get_namespaces($class_name)) {
        $class_name = array_pop($namespaces);
        $directories = array();
        foreach ($namespaces as $directory) {
            $directories[] = $directory;
        }
        $root .= DS . implode($directories, DS);
    }
    $file_name = "{$class_name}.php";
    $file = $root . DS . $file_name;
    if (file_exists($file)) {
        require $file;
    } else {
        $modules_path = APPPATH . 'modules';
        if (is_dir($modules_path)) {
            $modules = scandir(realpath($modules_path));
            foreach ($modules as $module) {
                $full_path = $modules_path . DS . $module . DS . 'models' . DS . $file_name;
                if ($module != '.' && $module != '..' && file_exists($full_path)) {
                    require $full_path;
                }
            }
        }
    }
}
예제 #4
0
 public function tear_down()
 {
     ActiveRecord\Config::instance()->set_date_class($this->original_date_class);
     if ($this->original_default_connection) {
         ActiveRecord\Config::instance()->set_default_connection($this->original_default_connection);
     }
 }
예제 #5
0
 /**
  * Abre la conexion teniendo en cuenta los parametros de application/config/config.php
  */
 private function openDatabaseConnection()
 {
     ActiveRecord\Config::initialize(function ($cfg) {
         $cfg->set_model_directory('application/models');
         $cfg->set_connections(array('development' => DB_TYPE . '://' . DB_USER . ':' . DB_PASS . '@' . DB_HOST . '/' . DB_NAME));
     });
 }
예제 #6
0
function configure()
{
    $cfg = ActiveRecord\Config::instance();
    $cfg->set_model_directory("models");
    $cfg->set_connections(array("development" => "mysql://*****:*****@localhost/hello_world?charset=utf8"));
    option("bas_url", "/");
}
예제 #7
0
 /**
  * Initalize the ORM
  * @return \Config_Framework_BaseController
  */
 protected function initORM()
 {
     ActiveRecord\Config::initialize(function ($cfg) {
         $cfg->set_model_directory($this->getClassDir());
         $cfg->set_connections(array('development' => 'mysql://*****:*****@127.0.0.1/mvc'));
     });
     return $this;
 }
예제 #8
0
 public function test_connect_with_port()
 {
     $config = ActiveRecord\Config::instance();
     $name = $config->get_default_connection();
     $url = parse_url($config->get_connection($name));
     if ($this->conn->protocol != 'sqlite') {
         ActiveRecord\Connection::instance("{$url['scheme']}://{$url['user']}:{$url['pass']}@{$url['host']}:{$this->conn->default_port()}{$url['path']}");
     }
 }
 function __construct() {
     
     $this->exhibitSettings();
     
     ActiveRecord\Config::initialize(function($cfg){
         $cfg->set_model_directory('model');
         $cfg->set_connections(array('development' => 'mysql://*****:*****@localhost/prokatvros'));
     });
 }
예제 #10
0
 public function set_up()
 {
     $this->column = new Column();
     try {
         $this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection());
     } catch (DatabaseException $e) {
         $this->mark_test_skipped('failed to connect using default connection. ' . $e->getMessage());
     }
 }
예제 #11
0
 public function set_up($connection_name = null)
 {
     if (!extension_loaded('memcache')) {
         $this->markTestSkipped('The memcache extension is not available');
         return;
     }
     parent::set_up($connection_name);
     ActiveRecord\Config::instance()->set_cache('memcache://localhost');
 }
예제 #12
0
 public function registerSupportLibraries()
 {
     include_once SUPPORT_DIRECTORY . '/parsedown/Parsedown.php';
     include_once SUPPORT_DIRECTORY . '/php-activerecord/ActiveRecord.php';
     ActiveRecord\Config::initialize(function ($cfg) {
         /** @var ActiveRecord\Config $cfg */
         $cfg->set_model_directory(APPLICATION_DIRECTORY . '/models/');
         $cfg->set_connections(array('development' => sprintf('mysql://%s:%s@%s/%s', $this->configuration->database->username, $this->configuration->database->password, $this->configuration->database->host, $this->configuration->database->databaseName)));
     });
 }
예제 #13
0
 private function setupActiveRecord()
 {
     require_once './libs/php-activerecord/ActiveRecord.php';
     $connectionString = sprintf('%s://%s:%s@%s/%s', $this->config->get('database.type'), $this->config->get('database.user'), $this->config->get('database.pass'), $this->config->get('database.host'), $this->config->get('database.name'));
     $cfg = ActiveRecord\Config::instance();
     $cfg->set_model_directory($this->config->get('database.models'));
     $cfg->set_connections(['development' => $connectionString]);
     $cfg->set_logging(true);
     $cfg->set_logger($this->profiler);
 }
예제 #14
0
 /**
  * @access public
  *      * 
  * @importante metodo @Core contem include as principais class dos sistema
  * 
  * @param array() $main
  * 
  * 
  */
 public static function begin($main)
 {
     define('DSN', $main['config']['db']['dsn']);
     ActiveRecord\Config::initialize(function ($cfg) {
         // $cfg->set_model_directory(MODEL);
         $cfg->set_connections(array('development' => DSN));
     });
     date_default_timezone_set($main['config']['timezone']);
     Controller::begin($main)->load();
 }
예제 #15
0
 public static function init($username, $password, $database, $host)
 {
     if (empty($username) || empty($database) || empty($host)) {
         throw new Exception("Please configure your database connection properly", 1);
     }
     $connections = array('development' => 'mysql://' . $username . ':' . $password . '@' . $host . '/' . $database);
     self::$conn = ActiveRecord\Config::instance();
     self::$conn->set_model_directory(AR::$model_directories);
     self::$conn->set_connections($connections);
 }
예제 #16
0
 function __construct()
 {
     // This closure is the winner in "because we can" category.
     ActiveRecord\Config::initialize(function ($cfg) {
         $conn = array('development' => Services::ARURL);
         $cfg->set_model_directory('models');
         $cfg->set_connections($conn);
         $cfg->set_default_connection('development');
     });
 }
 public function testConnectWithPort()
 {
     $config = ActiveRecord\Config::instance();
     $name = $config->getDefaultConnection();
     $url = parse_url($config->getConnection($name));
     $conn = $this->conn;
     $port = $conn::$DEFAULT_PORT;
     if ($this->conn->protocol != 'sqlite') {
         ActiveRecord\Connection::instance("{$url['scheme']}://{$url['user']}:{$url['pass']}@{$url['host']}:{$port}{$url['path']}");
     }
 }
예제 #18
0
 public function __construct()
 {
     // Set a path to the spark root that we can reference
     $spark_path = dirname(__DIR__) . '/';
     // Include the CodeIgniter database config file
     // Is the config file in the environment folder?
     if (!defined('ENVIRONMENT') or !file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/database.php')) {
         if (!file_exists($file_path = APPPATH . 'config/database.php')) {
             show_error('PHPActiveRecord: The configuration file database.php does not exist.');
         }
     }
     require $file_path;
     // Include the ActiveRecord bootstrapper
     require_once $spark_path . 'vendor/php-activerecord/ActiveRecord.php';
     // PHPActiveRecord allows multiple connections.
     $connections = array();
     if ($db && $active_group) {
         foreach ($db as $conn_name => $conn) {
             // Build the DSN string for each connection
             $connections[$conn_name] = $conn['dbdriver'] . '://' . $conn['username'] . ':' . $conn['password'] . '@' . $conn['hostname'] . '/' . $conn['database'] . '?charset=' . $conn['char_set'];
         }
         // Initialize PHPActiveRecord
         ActiveRecord\Config::initialize(function ($cfg) use($connections, $active_group) {
             $cfg->set_model_directories(APPPATH . 'models/core/', APPPATH . 'models/', APPPATH . 'models/delete/');
             // $cfg->set_model_directory(APPPATH.'models/');
             $cfg->set_connections($connections);
             // This connection is the default for all models
             $cfg->set_default_connection($active_group);
             // To enable logging and profiling, install the Log library
             // from pear, create phpar.log inside of your application/logs
             // directory, then uncomment the following block:
             if (is_writable(APPPATH . 'logs/query.log')) {
                 $log_file = APPPATH . 'logs/query.log';
                 include_once BASEPATH . 'log/log.php';
                 $logger = Log::singleton('file', $log_file, 'ident', array('mode' => 0664, 'timeFormat' => '%Y-%m-%d %H:%M:%S'));
                 $cfg->set_logging(true);
                 $cfg->set_logger($logger);
             }
             /*
             $log_file = $_SERVER['DOCUMENT_ROOT'].'/application/logs/phpar.log';
             
             if (file_exists($log_file) and is_writable($log_file)) {
                 include 'Log.php';
                 $logger = Log::singleton('file', $log_file ,'ident',array('mode' => 0664, 'timeFormat' =>  '%Y-%m-%d %H:%M:%S'));
                 $cfg->set_logging(true);
                 $cfg->set_logger($logger);
             } else {
                 log_message('warning', 'Cannot initialize logger. Log file does not exist or is not writeable');
             }
             */
         });
     }
 }
예제 #19
0
function connect_to_db()
{
    require_once dirname(__FILE__) . '/php-activerecord/ActiveRecord.php';
    $connections = array('development' => 'mysql://*****:*****@apochroma.ch/debitorenbuchhaltung?charset=utf8');
    #'production' => '');
    ActiveRecord\Config::initialize(function ($cfg) use($connections) {
        $cfg->set_model_directory(dirname(__FILE__) . '/models');
        $cfg->set_connections($connections);
        $cfg->set_default_connection('development');
        #$cfg->set_default_connection('production');
    });
}
예제 #20
0
 public function _initDatabase()
 {
     if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
         die('PHP ActiveRecord requires PHP 5.3 or higher');
     }
     ActiveRecord\Config::initialize(function ($cfg) {
         $mysqlConfig = $this->config->get("database.mysql");
         $cfg->set_model_directory(APP_PATH . '/app/models');
         $cfg->set_connections(array('production' => 'mysql://' . $mysqlConfig->user . ':' . $mysqlConfig->password . '@' . $mysqlConfig->host . '/' . $mysqlConfig->database, 'development' => 'mysql://' . $mysqlConfig->user . ':' . $mysqlConfig->password . '@' . $mysqlConfig->host . '/' . $mysqlConfig->database));
         $cfg->set_default_connection('production');
     });
 }
 public function __construct($name = null, array $data = array(), $dataName = '')
 {
     include __DIR__ . '/../setup/config.php';
     $pdo = new PDO("mysql:host={$db['host']};", $db['user'], $db['password']);
     $result = $pdo->exec("SET @@sql_mode = 'TRADITIONAL'");
     $sqlStr = file_get_contents(__DIR__ . '/../setup/mysql.sql');
     $result = $pdo->exec($sqlStr);
     $cfg = ActiveRecord\Config::instance();
     $cfg->set_model_directory(__DIR__ . '/../setup');
     $cfg->set_connections(array('development' => "mysql://{$db['user']}:{$db['password']}@{$db['host']}/{$db['database']}"));
     parent::__construct($name, $data, $dataName);
 }
예제 #22
0
	public static function loadActiveRecord() {
		$connections = array(
			'development' => 'mysql://'.MY_DB_USER.':'.MY_DB_PASS.'@'.MY_DB_SERVER.'/'.MY_DB_NAME
		);

		// initialize ActiveRecord
		ActiveRecord\Config::initialize(function($cfg) use ($connections)
		{
		    $cfg->set_model_directory(APP_PATH . '/models');
		    $cfg->set_connections($connections);
		});
	}
예제 #23
0
 public function __construct($initData)
 {
     $modelsPath = $initData['modelsPath'];
     $cfg = ActiveRecord\Config::instance();
     $cfg->set_model_directory($modelsPath);
     $username = AGSATTRACK_CONFIG::$database['user'];
     $password = AGSATTRACK_CONFIG::$database['pass'];
     $db = AGSATTRACK_CONFIG::$database['db'];
     $host = AGSATTRACK_CONFIG::$database['host'];
     $cfg->set_connections(array('development' => 'mysql://' . $username . ':' . $password . '@' . $host . '/' . $db));
     $this->basePath = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR;
     $this->viewPath = $this->basePath . 'application' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
 }
예제 #24
0
 public function test_connect_with_port()
 {
     $config = ActiveRecord\Config::instance();
     $name = $config->get_default_connection();
     $url = parse_url($config->get_connection($name));
     $conn = $this->conn;
     $port = $conn::$DEFAULT_PORT;
     $connection_string = "{$url['scheme']}://{$url['user']}";
     if (isset($url['pass'])) {
         $connection_string = "{$connection_string}:{$url['pass']}";
     }
     $connection_string = "{$connection_string}@{$url['host']}:{$port}{$url['path']}";
     if ($this->conn->protocol != 'sqlite') {
         ActiveRecord\Connection::instance($connection_string);
     }
 }
예제 #25
0
 public static function connect()
 {
     ActiveRecord\Config::initialize(function ($cfg) {
         $dbHost = Config::getValue_('dbHost');
         $dbUser = Config::getValue_('dbUser');
         $dbPass = Config::getValue_('dbPass');
         $dbName = Config::getValue_('dbName');
         $cfg->set_model_directory(MODEL);
         $cfg->set_connections(array('development' => 'mysql://' . $dbUser . ':' . $dbPass . '@' . $dbHost . '/' . $dbName));
         try {
             ConnectionManager::get_connection("development");
         } catch (Exception $e) {
             $response = Utils::getInternalServerErrorResponse(true);
             $response->send();
             die;
         }
     });
 }
예제 #26
0
파일: db.php 프로젝트: p-mob2015/idea19
function includeDB($path2home = "", $connectionString)
{
    /*
    Initialize a database
    PARAM:
    # path2home - relative path of home dir to referer file
    RESULT:
    # none
    */
    include_once $path2home . 'config/dir.php';
    require_once $path2home . _DIR_LIB_ARECORD . 'ActiveRecord.php';
    define('_TMP_DIR_MODEL_DYNAMIC', $path2home . _DIR_MODEL);
    define('_TMP_DB_CNCT_STRING', $connectionString);
    ActiveRecord\Config::initialize(function ($cfg) {
        $cfg->set_model_directory(_TMP_DIR_MODEL_DYNAMIC);
        $cfg->set_connections(array('development' => _TMP_DB_CNCT_STRING));
    });
}
예제 #27
0
 function __construct()
 {
     // Load database configuration from CodeIgniter
     include APPPATH . '/config/database.php';
     // Get connections from database.php
     $dsn = array();
     if ($db) {
         foreach ($db as $name => $db_values) {
             // Convert to dsn format
             $dsn[$name] = $db[$name]['dbdriver'] . '://' . $db[$name]['username'] . ':' . $db[$name]['password'] . '@' . $db[$name]['hostname'] . '/' . $db[$name]['database'];
         }
     }
     // Initialize ActiveRecord
     ActiveRecord\Config::initialize(function ($cfg) use($dsn, $active_group) {
         $cfg->set_model_directory(APPPATH . '/models');
         $cfg->set_connections($dsn);
         $cfg->set_default_connection($active_group);
     });
 }
예제 #28
0
 function __construct()
 {
     global $config;
     // Load database configuration from CodeIgniter
     include APPPATH . '/config/site_config.php';
     // Get connections from database.php
     $dsn = array();
     if ($config["db"]) {
         // Convert to dsn format
         $dsn["default"] = $config["db"]['dbdriver'] . '://' . $config["db"]['username'] . ':' . $config["db"]['password'] . '@' . $config["db"]['hostname'] . '/' . $config["db"]['database'];
     }
     $active_group = "default";
     // Initialize ActiveRecord
     ActiveRecord\Config::initialize(function ($cfg) use($dsn, $active_group) {
         $cfg->set_model_directory(APPPATH . '/models');
         $cfg->set_connections($dsn);
         $cfg->set_default_connection($active_group);
     });
 }
예제 #29
0
 /**
  * @access public
  *      * 
  * @importante metodo @Core contem include as principais class dos sistema
  * 
  * @param array() $main
  * 
  * 
  */
 public static function run($main)
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . Kanda_CORE);
     define('DSN', $main['db']['dsn']);
     define('THEME', $main['app']['view'][1][0]);
     define('MODEL', WWW_ROOT . $main['app']['model']);
     define('VIEW', $main['app']['view'][0]);
     define('CONTROLLER', $main['app']['controller']);
     if (isset($main['app']['diralias'])) {
         define('ALIAS', $main['app']['diralias']);
     } else {
         define('ALIAS', '');
     }
     ActiveRecord\Config::initialize(function ($cfg) {
         $cfg->set_model_directory(MODEL);
         $cfg->set_connections(array('development' => DSN));
     });
     date_default_timezone_set($main['app']['timezone']);
     $controller = new Controller();
     $controller->setController($main['app']['view'][1]);
 }
예제 #30
0
function activerecord_autoload($class_name)
{
    $paths = ActiveRecord\Config::instance()->get_model_directories();
    $namespace_directory = '';
    if ($namespaces = ActiveRecord\get_namespaces($class_name)) {
        $class_name = array_pop($namespaces);
        $directories = array();
        foreach ($namespaces as $directory) {
            $directories[] = $directory;
        }
        $namespace_directory = DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
    }
    $paths = count($paths) ? $paths : array('.');
    foreach ($paths as $path) {
        $root = realpath($path);
        $file = "{$root}{$namespace_directory}/{$class_name}.php";
        if (file_exists($file)) {
            require $file;
            return;
        }
    }
}