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; } } } } }
/** * 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; } }
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); } }
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", "/"); }
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']}"); } }
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()); } }
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'); }
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); }
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); }
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']}"); } }
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); }
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; }
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); } }
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; } } }
function activerecord_autoload($class_name) { // $path = ActiveRecord\Config::instance()->get_model_directory(); $paths = ActiveRecord\Config::instance()->get_model_directorise(); if ($paths) { foreach ($paths as $path) { $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; } } } } } } if (ENVIRONMENT === 'production') { $cfg_ar = ActiveRecord\Config::instance(); $cfg_ar->set_cache("OrmCache://localhost"); } }
<?php require 'Slim/Slim.php'; require 'vendor/php-activerecord/ActiveRecord.php'; require 'app/libs/S.php'; \Slim\Slim::registerAutoloader(); $app = new S(); $app->hook('slim.before', function () use($app) { $app->conn = ActiveRecord\Config::instance(); $app->conn->set_model_directory('app/models'); $app->conn->set_connections(array('development' => 'mysql://*****:*****@localhost/training_development', 'test' => 'mysql://*****:*****@localhost/training_test', 'production' => 'mysql://*****:*****@localhost/training_production')); header("Access-Control-Allow-Origin: *"); $app->response->header("Content-Type", "application/json; charset=utf-8"); }); $app->hook('slim.after', function () use($app) { $app->output(); }); $app->get('/', function () use($app) { $app->contents['messages'] = 'Welcome to S Web Services. Please provide application token to use the API.'; }); require 'app/routes.php'; $app->run();
public function __construct($db_user, $db_pass, $db_name, $server = 'localhost') { $cfg = ActiveRecord\Config::instance(); $cfg->set_model_directory('../models'); $cfg->set_connections(array('development' => 'mysql://' . $db_user . ':' . $db_pass . '@' . $server . '/' . $db_name)); }
public function testSetCharset() { $connectionString = ActiveRecord\Config::instance()->getConnection($this->connectionName); $conn = ActiveRecord\Connection::instance($connectionString . '?charset=utf8'); $this->assertEquals(';charset=utf8', $conn->dsnParams); }
public function testSetCharset() { $connectionString = ActiveRecord\Config::instance()->getConnection($this->connectionName); $conn = ActiveRecord\Connection::instance($connectionString . '?charset=utf8'); $this->assertEquals('SET NAMES ?', $conn->lastQuery); }
public function test_active_record_model_home_not_set() { $home = ActiveRecord\Config::instance()->get_model_directory(); ActiveRecord\Config::instance()->set_model_directory(__FILE__); $this->assert_equals(false, class_exists('TestAutoload')); ActiveRecord\Config::instance()->set_model_directory($home); }
public function tearDown() { if ($this->originalDefaultConnection) { ActiveRecord\Config::instance()->setDefaultConnection($this->originalDefaultConnection); } }
public function set_up() { $this->column = new Column(); $this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection()); }
<?php require "../../vendor/php-activerecord/php-activerecord/ActiveRecord.php"; date_default_timezone_set('America/Sao_Paulo'); $cfg = ActiveRecord\Config::instance(); $cfg->set_model_directory('../../app/models'); // $cfg->set_connections(array('development' => 'mysql://*****:*****@localhost/mudam510_base;charset=utf8')); // $cfg->set_connections(array('development' => 'mysql://*****:*****@localhost/bitfa068_mudamuda;charset=utf8')); $cfg->set_connections(array('development' => 'mysql://*****:*****@localhost/mudamuda;charset=utf8')); ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s';
public function test_set_charset() { $connection_string = ActiveRecord\Config::instance()->get_connection($this->connection_name); $conn = ActiveRecord\Connection::instance($connection_string . '?charset=utf8'); $this->assert_equals("SET NAMES 'utf8'", $conn->last_query); }
public function testActiveRecordModelHomeNotSet() { $home = ActiveRecord\Config::instance()->getModelDirectory(); ActiveRecord\Config::instance()->setModelDirectory(__FILE__); $this->assertEquals(false, class_exists('TestAutoload')); ActiveRecord\Config::instance()->setModelDirectory($home); }
public function test_set_charset() { $connection_string = ActiveRecord\Config::instance()->get_connection($this->connection_name); $conn = ActiveRecord\Connection::instance($connection_string . '?charset=utf8'); $this->assert_equals(';charset=utf8', $conn->dsn_params); }
public function test_explicit_default_expire() { ActiveRecord\Config::instance()->set_cache('memcache://localhost', array('expire' => 1)); $this->assert_equals(1, Cache::$options['expire']); }
/** * This inits activerecord, those require once looks ugly, but in practice make it faster. */ private function initActiveRecord() { require_once $this->lib_root . 'activerecord/ActiveRecord.php'; $cfg = ActiveRecord\Config::instance(); $cfg->set_model_directory($this->models_root); $conn = array($this->environment->instance => 'mysql://' . $this->environment->db_user . ':' . $this->environment->db_password . '@' . $this->environment->db_host . '/' . $this->environment->db_name . ''); $cfg->set_connections($conn, $this->environment->instance); }
public function test_assigning_php_datetime_gets_converted_to_date_class_with_custom_date_class() { ActiveRecord\Config::instance()->set_date_class('\\DateTime'); // use PHP built-in DateTime $author = new Author(); $author->created_at = $now = new \DateTime(); $this->assert_is_a("DateTime", $author->created_at); $this->assert_datetime_equals($now, $author->created_at); }
public function test_datetime_values_get_converted_to_strings() { $now = new \DateTime(); $a = $this->_a(array('only' => 'created_at'), new Author(array('created_at' => $now))); $this->assert_equals($now->format(ActiveRecord\Config::instance()->get_date_format()), $a['created_at']); }