예제 #1
1
<?php

/**
 * Bootstrap for the test environment.
 *
 * @package    PhouchDb
 * @subpackage Tests
 * @author     Mike Holloway <*****@*****.**>
 */
require_once __DIR__ . '/../vendor/autoload.php';
$envConfig = __DIR__ . '/configs/testing.config.php';
$config = new \Phalcon\Config(include __DIR__ . '/configs/config.php');
// merge local config, if it exists
if (file_exists($envConfig)) {
    $config->merge(new \Phalcon\Config(include $envConfig));
}
unset($envConfig);
$di = new \Phalcon\DI();
// store the config so it doesn't have to be parsed again
$di->set('config', $config);
$di->set('collectionManager', function () {
    return new \Phalcon\Mvc\Collection\Manager();
});
$di->set('couchdb', function () use($config) {
    $client = \Phalcon\Http\Client\Request::getProvider();
    $client->setBaseUri($config->couchdb->baseUri);
    $client->header->set('Content-Type', 'application/json');
    return $client;
});
예제 #2
0
 public function testConfigMerge()
 {
     $config1 = new \Phalcon\Config(array("controllersDir" => "../x/y/z", "modelsDir" => "../x/y/z", "database" => array("adapter" => "Mysql", "host" => "localhost", "username" => "scott", "password" => "cheetah", "name" => "test_db", "charset" => array("primary" => "utf8"), "alternatives" => array("primary" => "latin1", "second" => "latin1"))));
     $config2 = new \Phalcon\Config(array("modelsDir" => "../x/y/z", "database" => array("adapter" => "Postgresql", "host" => "localhost", "username" => "peter", "options" => array("case" => "lower"), "alternatives" => array("primary" => "swedish", "third" => "american"))));
     $config1->merge($config2);
     $expected = \Phalcon\Config::__set_state(array('controllersDir' => '../x/y/z', 'modelsDir' => '../x/y/z', 'database' => \Phalcon\Config::__set_state(array('adapter' => 'Postgresql', 'host' => 'localhost', 'username' => 'peter', 'password' => 'cheetah', 'name' => 'test_db', 'charset' => \Phalcon\Config::__set_state(array('primary' => 'utf8')), 'alternatives' => \Phalcon\Config::__set_state(array('primary' => 'swedish', 'second' => 'latin1', 'third' => 'american')), 'options' => \Phalcon\Config::__set_state(array('case' => 'lower'))))));
     $this->assertEquals($expected, $config1);
 }
예제 #3
0
 public function testConfigMergeArray()
 {
     $conf1 = array("keys" => array("scott", "cheetah"));
     $conf2 = array("keys" => array("peter"));
     $config1 = new Phalcon\Config($conf1);
     $config2 = new Phalcon\Config($conf2);
     $config1->merge($config2);
     $expected = Phalcon\Config::__set_state(array('keys' => Phalcon\Config::__set_state(array('0' => 'scott', '1' => 'cheetah', '2' => 'peter'))));
     $this->assertEquals($config1, $expected);
     $config1 = new Phalcon\Config($conf1);
     $config2 = new Phalcon\Config($conf2);
     $config2->merge($config1);
     $expected = Phalcon\Config::__set_state(array('keys' => Phalcon\Config::__set_state(array('0' => 'peter', '1' => 'scott', '2' => 'cheetah'))));
     $this->assertEquals($config2, $expected);
 }
예제 #4
0
<?php

defined('APP_PATH') || define('APP_PATH', realpath('.'));
$config = new \Phalcon\Config(array('database' => array('adapter' => 'Mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'test', 'charset' => 'utf8'), 'application' => array('controllersDir' => BASE_PATH . '/controllers/', 'viewsDir' => BASE_PATH . '/views/', 'modelsDir' => APP_PATH . '/models/', 'pluginsDir' => APP_PATH . '/plugins/', 'libraryDir' => APP_PATH . '/library/', 'langDir' => APP_PATH . '/lang/', 'migrationsDir' => APP_PATH . '/migrations/', 'cacheDir' => APP_PATH . '/cache/', 'staticUri' => '/phalcon/')));
$config->merge(new \Phalcon\Config(include __DIR__ . DIRECTORY_SEPARATOR . ENVIRONMENT . DIRECTORY_SEPARATOR . 'config.php'));
return $config;
예제 #5
0
<?php

$config = new \Phalcon\Config(array("application" => array("controllersDir" => __DIR__ . "/../../app/Controllers/", "modelsDir" => __DIR__ . "/../../app/Models/", "viewsDir" => __DIR__ . "/../../app/Views/", "pluginsDir" => __DIR__ . "/../../app/Plugins/", "libraryDir" => __DIR__ . "/../../app/Library/", "cacheDir" => __DIR__ . "/../../app/Cache/")));
$dbConfig = (include __DIR__ . "/dbconfig.php");
$config->merge($dbConfig);
return $config;
예제 #6
0
<?php

$config = new \Phalcon\Config(array('database' => array('host' => 'localhost', 'dbname' => 'test_db'), 'debug' => 1));
$config2 = new \Phalcon\Config(array('database' => array('username' => 'scott', 'password' => 'secret')));
$config->merge($config2);
print_r($config);
예제 #7
0
define('BASEPATH', $basePath);
define('APPPATH', BASEPATH . 'app/');
/*
|--------------------------------------------------------------------------
| Magic config
|--------------------------------------------------------------------------
|
| A simple system to fetch the app/config/config.php file and autoload 
| your custom config files added in the app/config/config.php into the 
| array "autoload => configs"
|
| @link http://docs.phalconphp.com/en/latest/api/Phalcon_Config.html
|
*/
// Init config var
$config = new \Phalcon\Config([]);
// Load config file of system
$tmp = (require APPPATH . 'config/config.php');
// Merge with the init config
$config->merge($tmp);
// Load custom config from autoload
if (isset($config->get('autoload')['configs'])) {
    $autoloadConfigs = $config->get('autoload')['configs'];
    if (!empty($autoloadConfigs)) {
        foreach ($autoloadConfigs as $configToLoad) {
            if (!empty($configToLoad)) {
                $tmp = (require APPPATH . 'config/' . $configToLoad . '.php');
                $config->merge($tmp);
            }
        }
    }
예제 #8
0
<?php

defined('APP_PATH') || define('APP_PATH', realpath('.'));
$app_config_file = APP_PATH . '/config.ini';
$app_config = new \Phalcon\Config\Adapter\Ini($app_config_file);
$config = new \Phalcon\Config(array('application' => array('controllersDir' => APP_PATH . '/app/controllers/', 'modelsDir' => APP_PATH . '/app/models/', 'migrationsDir' => APP_PATH . '/app/migrations/', 'viewsDir' => APP_PATH . '/app/views/', 'pluginsDir' => APP_PATH . '/app/plugins/', 'libraryDir' => APP_PATH . '/app/library/', 'cacheDir' => APP_PATH . '/app/cache/'), 'highlight_languages' => array('auto' => 'Autodetect', 'accesslog' => 'Access Log', 'armasm' => 'ARM ASM', 'apache' => 'Apache', 'bash' => 'Bash', 'brainfuck' => 'Brainfuck', 'coffeescript' => 'CoffeeScript', 'cmake' => 'CMake', 'cpp' => 'C++', 'cs' => 'C#', 'css' => 'CSS', 'diff' => 'Diff', 'dns' => 'DNS Zone File', 'erlang' => 'Erlang', 'fortran' => 'Fortran', 'glsl' => 'GLSL', 'go' => 'Go', 'gradle' => 'Gradle', 'groovy' => 'Groovy', 'haml' => 'HAML', 'haskell' => 'Haskell', 'xml' => 'HTML/XML', 'http' => 'HTTP', 'ini' => 'INI', 'java' => 'Java', 'javascript' => 'JavaScript', 'json' => 'JSON', 'kotlin' => 'Kotlin', 'lisp' => 'Lisp', 'lua' => 'Lua', 'makefile' => 'Makefile', 'markdown' => 'Markdown', 'mathematica' => 'Mathematica', 'matlab' => 'Matlab', 'nginx' => 'Nginx', 'objectivec' => 'Objective-C', 'perl' => 'Perl', 'php' => 'PHP', 'none' => 'Plain Text', 'powershell' => 'Powershell', 'puppet' => 'Puppet', 'python' => 'Python', 'ruby' => 'Ruby', 'rust' => 'Rust', 'scala' => 'Scala', 'scilab' => 'Scilab', 'scheme' => 'Scheme', 'scss' => 'SCSS', 'sql' => 'SQL', 'tcl' => 'Tcl', 'tex' => 'TeX', 'typescript' => 'TypeScript', 'vala' => 'Vala', 'vbnet' => 'VB.net', 'vbscript' => 'VBScript', 'vim' => 'Vim', 'x86asm' => 'x86 ASM')));
$config->merge($app_config);
return $config;
예제 #9
0
<?php

$namespace = (require APP_ROOT . 'apps/config/namespace.php');
$loader = new \Phalcon\Loader();
$loader->registerNamespaces($namespace)->register();
$di->setShared('loader', function () use($loader) {
    return $loader;
});
$di->setShared('config', function () {
    $configPath = (require APP_ROOT . 'apps/config/config.php');
    $config = new \Phalcon\Config($configPath);
    $qconf = new \Xz\Conf(APP_ENV);
    $config->merge($qconf->sys);
    $config->merge($qconf->url);
    $config->merge($qconf->common);
    $config->merge($qconf->cate);
    return $config;
});
//注入gongchangcate数据库
$di->setShared('cateDb', function () use($di) {
    $dbclass = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $di['config']->cateDb->driver;
    return new $dbclass(array('host' => $di['config']->cateDb->host, 'username' => $di['config']->cateDb->username, 'password' => $di['config']->cateDb->password, 'dbname' => $di['config']->cateDb->database, 'charset' => $di['config']->cateDb->charset));
});
$di->setShared("forbuyersproonline", function () use($di) {
    $dbclass = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $di['config']->cateDb->driver;
    return new $dbclass(array('host' => "192.168.1.155", 'username' => "enseluser", 'password' => "enseluser7232275", 'dbname' => "engongchang", 'charset' => "utf8"));
});
$di->setShared("forbuyerspro", function () use($di) {
    $dbclass = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $di['config']->cateDb->driver;
    return new $dbclass(array('host' => "192.168.8.198", 'username' => "root", 'password' => "123456", 'dbname' => "fbproduct", 'charset' => "utf8"));
});
예제 #10
0
 public function testSetState()
 {
     $config = new \Phalcon\Config(array('a' => 'b'));
     $configCopy = \Phalcon\Config::__set_state($config->toArray());
     $this->assertEquals($configCopy->toArray(), $config->toArray());
 }
예제 #11
0
 public function testConfigWithMergeAndGarbageCollection()
 {
     $config = new Phalcon\Config(array('test1' => 1, 'test2' => 2));
     $config->merge(new Phalcon\Config(array('test2')));
     gc_collect_cycles();
 }
예제 #12
0
<?php

include __DIR__ . '/../../vendor/autoload.php';
$dot_env = new Dotenv\Dotenv(__DIR__ . '/../../');
$dot_env->load();
defined('APP_PATH') || define('APP_PATH', realpath('.'));
$main_config = new \Phalcon\Config(array('database' => array('adapter' => 'Mysql', 'host' => getenv('DATABASE_HOST'), 'username' => getenv('DATABASE_USER'), 'password' => getenv('DATABASE_PASS'), 'dbname' => getenv('DATABASE_NAME') . '_dev', 'charset' => 'utf8'), 'application' => array('controllersDir' => APP_PATH . '/app/Controllers/', 'modelsDir' => APP_PATH . '/app/Models/', 'migrationsDir' => APP_PATH . '/app/Db/Migrations/', 'baseUri' => '/api/', 'domain' => getenv('APP_DOMAIN')), 'namespaces' => array('App' => APP_PATH . '/app/', 'Faker' => APP_PATH . '/vendor/fzaninotto/faker/src/Faker/'), 'fb' => array('appId' => getenv('FB_CLIENT_ID'), 'secret' => getenv('FB_CLIENT_SECRET'), 'callback' => 'register/facebook/callback'), 'debug' => true));
// By default development environment
$env = getenv('APP_ENV');
if ($env) {
    $env_config = (include APP_PATH . '/app/config/environments/' . $env . '.php');
    return $main_config->merge($env_config);
} else {
    return $main_config;
}
예제 #13
0
파일: Micro.php 프로젝트: flyingbuddha/eyas
 /**
  * Set Dependency Injector with configuration variables
  *
  * @throws Exception        on bad database adapter
  * @param string $file      full path to configuration file
  */
 public function setConfig($file)
 {
     if (!file_exists($file)) {
         throw new \Exception('Unable to load configuration file');
     }
     $environment = getenv('APPLICATION_ENV') ?: 'production';
     // load in application config
     $config = new \Phalcon\Config(require $file);
     $envConfig = $this->getConfigPath() . '/' . $environment . '.' . $this->getConfigFileName();
     // load in alternative configs for the environment
     if (file_exists($envConfig)) {
         $config2 = new \Phalcon\Config(include $envConfig);
         $config->merge($config2);
     }
     $di = $this->getDI();
     if (null === $di) {
         $di = new \Phalcon\DI\FactoryDefault();
     }
     $di->set('config', $config);
     $di->set('db', function () use($di) {
         $type = strtolower($di->get('config')->database->adapter);
         $creds = array('host' => $di->get('config')->database->host, 'username' => $di->get('config')->database->username, 'password' => $di->get('config')->database->password, 'dbname' => $di->get('config')->database->dbname);
         if ($type == 'mysql') {
             $connection = new \Phalcon\Db\Adapter\Pdo\Mysql($creds);
         } elseif ($type == 'postgres') {
             $connection = new \Phalcon\Db\Adapter\Pdo\Postgesql($creds);
         } elseif ($type == 'sqlite') {
             $connection = new \Phalcon\Db\Adapter\Pdo\Sqlite($creds);
         } else {
             throw new \Exception('Bad Database Adapter');
         }
         return $connection;
     });
     $this->setDI($di);
     unset($environment, $config);
 }