magium / mcm-zend-db-factory
使用 Magium 配置管理器配置 zendframework/zend-db 适配器的工厂
1.4
2017-05-09 21:19 UTC
Requires
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-15 01:41:31 UTC
README
这是一个简单的库,允许使用 Magium 配置管理器 配置 Zend DB 适配器。
设置
使用它非常简单。
首先通过 composer 安装
composer require magium/zend-db-factory
然后连接您的应用程序以使用 MCM。
$factory = new \Magium\Configuration\MagiumConfigurationFactory();
$config = $factory->getManager()->getConfiguration(getenv('ENVIRONMENT'));
$redis = \Magium\ZendDbFactory\ZendDbFactory::factory($config);
您还可以将您的 Zend DI 组件连接到它以协同工作
$config = [
'definition' => [
'class' => [
\Zend\Db\Adapter\Adapter::class => [
'instantiator' => [
\Magium\ZendDbFactory\ZendDbFactory::class,
'factory'
]
],
Magium\ZendDbFactory\ZendDbFactory::class => [
'methods' => [
'factory' => [
'config' => [
'type' => \Magium\Configuration\Config\ConfigurationRepository::class,
'required' => true
]
]
]
]
]
]
];
$factory = new \Magium\Configuration\MagiumConfigurationFactory();
$di = new \Zend\Di\Di();
$configuration = new \Zend\Di\Config($config);
$configuration->configure($di);
$di->instanceManager()->addSharedInstance(
$factory->getManager()->getConfiguration(),
\Magium\Configuration\Config\ConfigurationRepository::class
);
$adapter = $di->get(\Zend\Db\Adapter\Adapter::class);
更改设置
使用 MCM 配置管理器更改设置。例如,如果您打算使用 CLI 进行更改,您有以下选项
[kschroeder@dev ~]$ vendor/configuration-manager magium:configuration:list-keys
Valid configuration keys
database/zenddb/driver
database/zenddb/hostname
(A string containing a hostname or IP address of the database server. If the database is running on the same host as the PHP application, you may use 'localhost' or '127.0.0.1'.)
database/zenddb/username
(Account identifier for authenticating a connection to the RDBMS server.)
database/zenddb/password
(Account password credential for authenticating a connection to the RDBMS server.)
database/zenddb/dbname
(Database instance name on the RDBMS server.)
database/zenddb/port
(Some RDBMS servers can accept network connections on a administrator-specified port number. The port parameter allow you to specify the port to which your PHP application connects, to match the port configured on the RDBMS server.)
database/adapter/charset
(Specify the charset used for the connection.)
如果您需要更改配置以使用其他内容
[kschroeder@dev ~]$ vendor/bin/magium-configuration magium:configuration:set database/zenddb/hostname hostname
完成了!不需要部署。