本文整理汇总了PHP中Zend\Di\Di::configure方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::configure方法的具体用法?PHP Di::configure怎么用?PHP Di::configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Di\Di
的用法示例。
在下文中一共展示了Di::configure方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConfigurationCanConfigureInstanceManagerWithIniFile
public function testConfigurationCanConfigureInstanceManagerWithIniFile()
{
$ini = new \Zend\Config\Ini(__DIR__ . '/_files/sample.ini', 'section-a');
$config = new Configuration($ini->di);
$di = new Di();
$di->configure($config);
$im = $di->instanceManager();
$this->assertTrue($im->hasAlias('my-repository'));
$this->assertEquals('My\RepositoryA', $im->getClassFromAlias('my-repository'));
$this->assertTrue($im->hasAlias('my-mapper'));
$this->assertEquals('My\Mapper', $im->getClassFromAlias('my-mapper'));
$this->assertTrue($im->hasAlias('my-dbAdapter'));
$this->assertEquals('My\DbAdapter', $im->getClassFromAlias('my-dbAdapter'));
$this->assertTrue($im->hasTypePreferences('my-repository'));
$this->assertContains('my-mapper', $im->getTypePreferences('my-repository'));
$this->assertTrue($im->hasTypePreferences('my-mapper'));
$this->assertContains('my-dbAdapter', $im->getTypePreferences('my-mapper'));
$this->assertTrue($im->hasConfiguration('My\DbAdapter'));
$expected = array('parameters' => array('username' => 'readonly', 'password' => 'mypassword'), 'injections' => array());
$this->assertEquals($expected, $im->getConfiguration('My\DbAdapter'));
$this->assertTrue($im->hasConfiguration('my-dbAdapter'));
$expected = array('parameters' => array('username' => 'readwrite'), 'injections' => array());
$this->assertEquals($expected, $im->getConfiguration('my-dbAdapter'));
}
示例2: createDi
/**
* @param array $config
* @return Di
*/
protected function createDi($config)
{
$di = new Di();
if (isset($config['di'])) {
$di->configure(new DiConfig($config['di']));
}
return $di;
}
示例3: __invoke
public function __invoke(array $config = array())
{
$di = new Di();
$diConfig = array('definition' => array('class' => array('Zend\\Cache\\Storage\\Adapter' => array('instantiator' => array('Eva\\Cache\\StorageFactory', 'factory')), 'Eva\\Cache\\StorageFactory' => array('methods' => array('factory' => array('cfg' => array('required' => true, 'type' => false)))))), 'instance' => array('Eva\\Cache\\StorageFactory' => array('parameters' => array('cfg' => array('adapter' => array('name' => 'filesystem', 'options' => array('cacheDir' => EVA_ROOT_PATH . '/data/cache/model/')), 'plugins' => array('serializer'))))));
$globalConfig = $this->serviceLocator->get('Configuration');
$globalConfig = isset($globalConfig['cache']['model']) ? $globalConfig['cache']['model'] : array();
$diConfig = Config::mergeArray($diConfig, $globalConfig, $config);
$di->configure(new DiConfig($diConfig));
return $di->get('Eva\\Cache\\StorageFactory');
}
示例4: createService
/**
* Create and return abstract factory seeded by dependency injector
*
* Creates and returns an abstract factory seeded by the dependency
* injector. If the "di" key of the configuration service is set, that
* sub-array is passed to a DiConfiguration object and used to configure
* the DI instance. The DI instance is then used to seed the
* DiAbstractServiceFactory, which is then registered with the service
* manager.
*
* @param ServiceLocatorInterface $serviceLocator
* @return Di
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$di = new Di();
$config = $serviceLocator->get('Configuration');
if (isset($config['di'])) {
$di->configure(new DiConfiguration($config['di']));
}
if ($serviceLocator instanceof ServiceManager) {
// register as abstract factory as well:
$serviceLocator->addAbstractFactory(new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI));
}
return $di;
}
示例5: testConfigurationCanConfigureCompiledDefinition
public function testConfigurationCanConfigureCompiledDefinition()
{
$config = ConfigFactory::fromFile(__DIR__ . '/_files/sample.php', true);
$config = new Configuration($config->di);
$di = new Di();
$di->configure($config);
$definition = $di->definitions()->getDefinitionByType('Zend\\Di\\Definition\\ArrayDefinition');
$this->assertInstanceOf('Zend\\Di\\Definition\\ArrayDefinition', $definition);
$this->assertTrue($di->definitions()->hasClass('My\\DbAdapter'));
$this->assertTrue($di->definitions()->hasClass('My\\EntityA'));
$this->assertTrue($di->definitions()->hasClass('My\\Mapper'));
$this->assertTrue($di->definitions()->hasClass('My\\RepositoryA'));
$this->assertTrue($di->definitions()->hasClass('My\\RepositoryB'));
$this->assertFalse($di->definitions()->hasClass('My\\Foo'));
}
示例6: factory
public static function factory(array $config = array())
{
$defaultConfig = array('di' => array('definition' => array(), 'instance' => array('Eva\\File\\Transfer\\Adapter\\Http' => array('parameters' => array()), 'Eva\\File\\Transfer\\Transfer' => array('parameters' => array('adapter' => 'Eva\\File\\Transfer\\Adapter\\Http')))));
$globalConfig = Api::_()->getConfig();
if (isset($globalConfig['file_transfer'])) {
$config = array_merge($defaultConfig, $globalConfig['file_transfer'], $config);
} else {
$config = array_merge($defaultConfig, $config);
}
$diConfig = array();
if ($config['di']) {
$diConfig = $config['di'];
}
$di = new Di();
$di->configure(new DiConfig($diConfig));
$fileTransfer = $di->get('Eva\\File\\Transfer\\Transfer');
//p($fileTransfer, 1);
//@\Zend\Di\Display\Console::export($di);
return $fileTransfer;
}
示例7: testMarkingClassAsNotSharedInjectsNewInstanceIntoAllRequestersButDependentsAreShared
/**
* @group SharedInstance
*/
public function testMarkingClassAsNotSharedInjectsNewInstanceIntoAllRequestersButDependentsAreShared()
{
$di = new Di();
$di->configure(new Config(array('instance' => array('ZendTest\\Di\\TestAsset\\SharedInstance\\Lister' => array('shared' => false)))));
$movie = $di->get('ZendTest\\Di\\TestAsset\\SharedInstance\\Movie');
$venue = $di->get('ZendTest\\Di\\TestAsset\\SharedInstance\\Venue');
$this->assertNotSame($movie->lister, $venue->lister);
$this->assertSame($movie->lister->sharedLister, $venue->lister->sharedLister);
}
示例8: __construct
public function __construct(array $config = array())
{
$defaultConfig = array('transports' => array('smtp' => false, 'sendmail' => false, 'file' => true), 'message' => array(), 'di' => array('definition' => array('class' => array('Zend\\View\\Resolver\\AggregateResolver' => array('attach' => array('resolver' => array('required' => true, 'type' => 'Zend\\View\\Resolver\\TemplatePathStack'))))), 'instance' => array('Zend\\View\\Resolver\\TemplatePathStack' => array('parameters' => array('paths' => array(Message::VIEW_PATH_NAME => EVA_ROOT_PATH . '/data/'))), 'Zend\\View\\Resolver\\AggregateResolver' => array('injections' => array('Zend\\View\\Resolver\\TemplatePathStack')), 'Zend\\View\\Renderer\\PhpRenderer' => array('parameters' => array('resolver' => 'Zend\\View\\Resolver\\AggregateResolver')), 'Eva\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'view' => 'Zend\\View\\Renderer\\PhpRenderer', 'viewModel' => 'Zend\\View\\Model\\ViewModel', 'encoding' => 'UTF-8')), 'Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => EVA_ROOT_PATH . '/data/mail')), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions')))));
$globalConfig = Api::_()->getConfig();
if (isset($globalConfig['mail'])) {
$config = Config::mergeArray($defaultConfig, $globalConfig['mail'], $config);
} else {
$config = Config::mergeArray($defaultConfig['mail'], $config);
}
$diConfig = array();
if ($config['di']) {
$diConfig = $config['di'];
}
$di = new Di();
$di->configure(new DiConfig($diConfig));
$this->message = $di->get('Eva\\Mail\\Message');
$allowTransports = $this->transportsClasses;
$transportType = '';
if (is_string($config['transports'])) {
$transportType = $config['transports'];
$transportClass = isset($allowTransports[$transportType]) ? $allowTransports[$transportType] : null;
if (!$transportClass) {
throw new Exception\InvalidArgumentException(sprintf('Unknow transport type %s in method %s"', $transportType, __METHOD__));
}
$transport = $di->get($transportClass);
//\Zend\Di\Display\Console::export($di);
$this->transports[$transportType] = $transport;
} elseif (is_array($config['transports'])) {
$transportTypes = $config['transports'];
foreach ($transportTypes as $transportType => $value) {
if (!$value) {
continue;
}
$transportClass = isset($allowTransports[$transportType]) ? $allowTransports[$transportType] : null;
if (!$transportClass) {
throw new Exception\InvalidArgumentException(sprintf('Unknow transport type %s in method %s"', $transportType, __METHOD__));
}
$this->transports[$transportType] = $di->get($transportClass);
}
} else {
throw new Exception\InvalidArgumentException(sprintf('%s expects a string or array as transport config, "%s" received', __METHOD__, gettype($config['transports'])));
}
}
示例9: getAuthStorage
public function getAuthStorage()
{
if ($this->authService) {
return $this->authService->getStorage();
}
if ($this->authStorage) {
return $this->authStorage;
}
$this->initStorage();
$diConfig = $this->getDiConfig();
$di = new Di();
$di->configure(new DiConfig($diConfig));
return $this->authStorage = $di->get($this->storageClass);
}
示例10: array
<?php
require_once './autoloader.php';
use Zend\Mail\Message;
use Zend\Mail\Transport;
use Zend\Di\Di;
use Zend\Di\Config as DiConfig;
$diConfig = array('instance' => array('Zend\\Mail\\Transport\\FileOptions' => array('parameters' => array('path' => __DIR__)), 'Zend\\Mail\\Transport\\File' => array('injections' => array('Zend\\Mail\\Transport\\FileOptions')), 'Zend\\Mail\\Transport\\SmtpOptions' => array('parameters' => array('name' => 'sendgrid', 'host' => 'smtp.sendgrid.net', 'port' => 25, 'connectionClass' => 'login', 'connectionConfig' => array('username' => 'allo.vince@gmail.com', 'password' => 'password'))), 'Zend\\Mail\\Message' => array('parameters' => array('headers' => 'Zend\\Mail\\Headers', 'Zend\\Mail\\Message::setTo:emailOrAddressList' => 'allo.vince@gmail.com', 'Zend\\Mail\\Message::setTo:name' => 'EvaEngine', 'Zend\\Mail\\Message::setFrom:emailOrAddressList' => 'info@evaengine.com', 'Zend\\Mail\\Message::setFrom:name' => 'EvaEngine', 'setBody' => 'Zend\\View\\Renderer\\PhpRenderer::render')), 'Zend\\Mail\\Transport\\Smtp' => array('injections' => array('Zend\\Mail\\Transport\\SmtpOptions'))));
$di = new Di();
$di->configure(new DiConfig($diConfig));
$transport = $di->get('Zend\\Mail\\Transport\\Smtp');
$transport = $di->get('Zend\\Mail\\Transport\\Sendmail');
$transport = $di->get('Zend\\Mail\\Transport\\File');
$message = $di->get('Zend\\Mail\\Message');
$view = new Zend\View\Renderer\PhpRenderer();
$resolver = new Zend\View\Resolver\TemplatePathStack();
$resolver->setPaths(array('mailTemplate' => __DIR__));
$view->setResolver($resolver);
$viewModel = new Zend\View\Model\ViewModel();
$viewModel->setTemplate('mail/template')->setVariables(array('user' => 'AlloVince'));
$message->setSubject("Zend Mail with Template")->setBody($view->render($viewModel));
$transport->send($message);
示例11: getDumper
/**
* Retrieves a fresh dumper at every call
*
* @return Dumper
*/
protected function getDumper()
{
$di = new Di();
$di->configure(new Config($this->diConfigArray));
return new Dumper($di);
}
示例12: setUp
public function setUp()
{
$configuration = (require 'app/config-test.php');
$this->di = new Di();
$this->di->configure(new Configuration($configuration['di']));
}
示例13: Di
<?php
/**
* Application bootstrap file.
* Used to initialize DI container and return
* it's instance as a result of inclusion
*
* @author nfx
*/
require_once __DIR__ . '/../vendor/autoload.php';
use Zend\Di\Di;
use Zend\Di\Configuration;
/**
* PHP doesn't need special config file format in most cases
*/
$configuration = (include 'config.php');
$di = new Di();
$di->configure(new Configuration($configuration['di']));
return $di;