コード例 #1
0
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;
                }
            }
        }
    }
}
コード例 #2
0
ファイル: common.php プロジェクト: rosianesrocha/nanico
/**
 * 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;
	}
}
コード例 #3
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);
     }
 }
コード例 #4
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", "/");
}
コード例 #5
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']}");
     }
 }
コード例 #6
0
ファイル: ColumnTest.php プロジェクト: EFreezen/M2_CMS
 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());
     }
 }
コード例 #7
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');
 }
コード例 #8
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);
 }
コード例 #9
0
ファイル: AR.php プロジェクト: nasrulhazim/php-activerecord
 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);
 }
コード例 #10
0
 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']}");
     }
 }
コード例 #11
0
 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);
 }
コード例 #12
0
ファイル: controller.php プロジェクト: whztt07/agsattrack
 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;
 }
コード例 #13
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);
     }
 }
コード例 #14
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;
        }
    }
}
コード例 #15
0
ファイル: ActiveRecord.php プロジェクト: comdan66/zeusdesign
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");
    }
}
コード例 #16
0
<?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();
コード例 #17
0
 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));
 }
コード例 #18
0
 public function testSetCharset()
 {
     $connectionString = ActiveRecord\Config::instance()->getConnection($this->connectionName);
     $conn = ActiveRecord\Connection::instance($connectionString . '?charset=utf8');
     $this->assertEquals(';charset=utf8', $conn->dsnParams);
 }
コード例 #19
0
 public function testSetCharset()
 {
     $connectionString = ActiveRecord\Config::instance()->getConnection($this->connectionName);
     $conn = ActiveRecord\Connection::instance($connectionString . '?charset=utf8');
     $this->assertEquals('SET NAMES ?', $conn->lastQuery);
 }
コード例 #20
0
 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);
 }
コード例 #21
0
 public function tearDown()
 {
     if ($this->originalDefaultConnection) {
         ActiveRecord\Config::instance()->setDefaultConnection($this->originalDefaultConnection);
     }
 }
コード例 #22
0
 public function set_up()
 {
     $this->column = new Column();
     $this->conn = ActiveRecord\ConnectionManager::get_connection(ActiveRecord\Config::instance()->get_default_connection());
 }
コード例 #23
0
ファイル: connect_func.php プロジェクト: KikoPoaRS/mudamuda
<?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';
コード例 #24
0
 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);
 }
コード例 #25
0
 public function testActiveRecordModelHomeNotSet()
 {
     $home = ActiveRecord\Config::instance()->getModelDirectory();
     ActiveRecord\Config::instance()->setModelDirectory(__FILE__);
     $this->assertEquals(false, class_exists('TestAutoload'));
     ActiveRecord\Config::instance()->setModelDirectory($home);
 }
コード例 #26
0
ファイル: OciAdapterTest.php プロジェクト: killich/JustFrame
 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);
 }
コード例 #27
0
 public function test_explicit_default_expire()
 {
     ActiveRecord\Config::instance()->set_cache('memcache://localhost', array('expire' => 1));
     $this->assert_equals(1, Cache::$options['expire']);
 }
コード例 #28
0
ファイル: quantum.php プロジェクト: carriercomm/quantum2
 /**
  * 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);
 }
コード例 #29
0
 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);
 }
コード例 #30
0
 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']);
 }