当前位置: 首页>>代码示例>>PHP>>正文


PHP Di\Di类代码示例

本文整理汇总了PHP中Zend\Di\Di的典型用法代码示例。如果您正苦于以下问题:PHP Di类的具体用法?PHP Di怎么用?PHP Di使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Di类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testConfigurationCanConfigureBuilderDefinitionFromIni

 public function testConfigurationCanConfigureBuilderDefinitionFromIni()
 {
     $this->markTestIncomplete('Builder not updated to new DI yet');
     $ini = new \Zend\Config\Ini(__DIR__ . '/_files/sample.ini', 'section-b');
     $config = new Configuration($ini->di);
     $di = new Di($config);
     $definition = $di->getDefinition();
     
     $this->assertTrue($definition->hasClass('My\DbAdapter'));
     $this->assertEquals('__construct', $definition->getInstantiator('My\DbAdapter'));
     $this->assertEquals(
         array('username' => null, 'password' => null),
         $definition->getInjectionMethodParameters('My\DbAdapter', '__construct')
         );
     
     $this->assertTrue($definition->hasClass('My\Mapper'));
     $this->assertEquals('__construct', $definition->getInstantiator('My\Mapper'));
     $this->assertEquals(
         array('dbAdapter' => 'My\DbAdapter'),
         $definition->getInjectionMethodParameters('My\Mapper', '__construct')
         );
     
     $this->assertTrue($definition->hasClass('My\Repository'));
     $this->assertEquals('__construct', $definition->getInstantiator('My\Repository'));
     $this->assertEquals(
         array('mapper' => 'My\Mapper'),
         $definition->getInjectionMethodParameters('My\Repository', '__construct')
         );
     
 }
开发者ID:rickogden,项目名称:zf2,代码行数:30,代码来源:ConfigurationTest.php

示例2: setUp

 public function setUp()
 {
     $this->mock = $this->getMock('Tillikum\\Billing\\Event\\Strategy\\StrategyInterface');
     $di = new Di\Di();
     $im = $di->instanceManager();
     $im->addSharedInstance($this->mock, 'TestStrategyAlias');
     $this->processor = new BookingProcessor($di);
     $rule = new FacilityBookingRule();
     $config = new FacilityBookingRuleConfig();
     $config->amount = 10.0;
     $config->currency = 'USD';
     $config->start = new DateTime('2010-07-01');
     $config->end = new DateTime('2010-07-15');
     $config->strategy = 'TestStrategyAlias';
     $rule->configs->add($config);
     $config = new FacilityBookingRuleConfig();
     $config->amount = 20.0;
     $config->currency = 'USD';
     $config->start = new DateTime('2010-07-15');
     $config->end = new DateTime('2010-07-31');
     $config->strategy = 'TestStrategyAlias';
     $rule->configs->add($config);
     $this->event = new FacilityBookingEvent();
     $this->event->start = new DateTime('2010-07-01');
     $this->event->end = new DateTime('2010-07-15');
     $this->event->rule = $rule;
 }
开发者ID:tillikum,项目名称:tillikum-core-module,代码行数:27,代码来源:BookingProcessorTest.php

示例3: configureDi

 public function configureDi(Di $di)
 {
     $di->instanceManager()->addSharedInstance($this->configurationReader, get_class($this->configurationReader));
     $di->instanceManager()->addSharedInstance($this->classConfigurationReader, get_class($this->classConfigurationReader));
     $di->instanceManager()->addSharedInstance($this->environmentConfigurationReader, get_class($this->environmentConfigurationReader));
     $di->instanceManager()->addSharedInstance($this, get_class($this));
 }
开发者ID:magium,项目名称:magium,代码行数:7,代码来源:StandardConfigurationProvider.php

示例4: 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;
 }
开发者ID:royopa,项目名称:OcraDiCompiler,代码行数:12,代码来源:DiFactory.php

示例5: createService

 public function createService(ServiceLocatorInterface $oServiceLocator)
 {
     $oServiceLocator = $oServiceLocator->getServiceLocator();
     $oAppService = $oServiceLocator->get('AppService');
     $oDi = new Di();
     $oDi->instanceManager()->setParameters('API\\Controller\\IndexController', array('app' => $oAppService));
     return $oDi->get('API\\Controller\\IndexController');
 }
开发者ID:lstaszak,项目名称:zf2main,代码行数:8,代码来源:IndexController.php

示例6: indexAction

 public function indexAction()
 {
     $config = $this->getServiceLocator('Configuration')->get('Configuration');
     $di = new Di(null, null, new Config($config['Di']));
     $basemodel = $di->get('NedVisol\\Orm\\BaseModel');
     $ret = $basemodel->adapter->putRow('test', array('id' => 'row2', 'columns' => array('cf1.a' => '234', 'cf1.b' => '456'), 'checks' => array('cf1.a' => '999')));
     echo "****{$ret}***";
     return new ViewModel();
 }
开发者ID:nedvisol,项目名称:phporm,代码行数:9,代码来源:IndexController.php

示例7: init

 /**
  * Set up dependency injection framework
  *
  * @return ServiceManager
  */
 public function init()
 {
     $options = $this->getOptions();
     $doctrineContainer = $this->getBootstrap()->bootstrap('Doctrine')->getResource('Doctrine');
     $di = new ZendDi\Di(null, null, new ZendDi\Config($options));
     $di->instanceManager()->addSharedInstance(new Db\Adapter\Driver\Pdo\Pdo($doctrineContainer->getEntityManager()->getConnection()->getWrappedConnection()), 'Zend\\Db\\Adapter\\Driver\\Pdo\\Pdo');
     $di->instanceManager()->addSharedInstance($doctrineContainer->getEntityManager(), 'Doctrine\\ORM\\EntityManager');
     return $di;
 }
开发者ID:tillikum,项目名称:tillikum-core-module,代码行数:14,代码来源:Di.php

示例8: __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');
 }
开发者ID:ahyswang,项目名称:eva-engine,代码行数:10,代码来源:ModelCache.php

示例9: testWillDiscoverInjectedMethodParameters

 public function testWillDiscoverInjectedMethodParameters()
 {
     $di = new Di();
     $a = new A();
     $di->instanceManager()->setParameters('ZendTest\\Di\\TestAsset\\SetterInjection\\B', array('a' => $a));
     $proxy = new DependencyInjectorProxy($di);
     $b = $proxy->get('ZendTest\\Di\\TestAsset\\SetterInjection\\B');
     $methods = $b->getMethods();
     $this->assertSame('setA', $methods[0]['method']);
     $this->assertSame($a, $methods[0]['params'][0]);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:11,代码来源:DependencyInjectorProxyTest.php

示例10: run

 /**
  * Run
  *
  * @return mixed
  */
 public function run()
 {
     $dic = new Model\DiC($this->_di);
     $dic->assemble();
     /** @var \App\Bot\Updater $updater */
     $botUpdater = $this->_di->get('BotUpdater');
     $botUpdater->checkUpdates();
     /** @var \App\Redmine\Updater $redmineUpdater */
     $redmineUpdater = $this->_di->get('RedmineUpdater');
     $redmineUpdater->checkUpdates();
 }
开发者ID:VaD1ke,项目名称:redmine_telegram_notifier,代码行数:16,代码来源:App.php

示例11: 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;
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:26,代码来源:DiFactory.php

示例12: doProxy

 /**
  * @param Di $locator
  * @return mixed
  */
 public function doProxy(Di $locator)
 {
     $options = $this->getOptions();
     $result = null;
     if ('get' === $options['method']) {
         $result = $locator->get($options['name'], $options['params']);
     } elseif ('newInstance' === $options['method']) {
         $result = $locator->newInstance($options['name'], $options['params'], $options['isShared']);
     } else {
         throw new InvalidArgumentException("'{$options['method']}' is undefined method'");
     }
     return $result;
 }
开发者ID:canaydogan,项目名称:ukala,代码行数:17,代码来源:StandardProxy.php

示例13: 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'));
 }
开发者ID:navassouza,项目名称:zf2,代码行数:15,代码来源:ConfigurationTest.php

示例14: render

    public function render(Di $di)
    {

        echo 'Definitions: ' . PHP_EOL;
        foreach ($di->definitions() as $definition) {
            foreach ($definition->getClasses() as $class) {
                echo PHP_EOL . '  Parameters For Class: ' . $class . PHP_EOL;
                foreach ($definition->getMethods($class) as $methodName => $methodIsRequired) {
                    foreach ($definition->getMethodParameters($class, $methodName) as $fqName => $pData) {
                        echo '    ' . $pData[0] . ' [type: ';
                        echo ($pData[1]) ? $pData[1] : 'scalar';
                        echo ($pData[2] === true && $methodIsRequired) ? ', required' : ', not required';
                        echo ', injection-method: ' . $methodName;
                        echo ' fq-name: ' . $fqName;
                        echo ']' . PHP_EOL;
                    }
                }
            }
        }

        echo PHP_EOL . 'Instance Configuration Info:' . PHP_EOL;

        echo PHP_EOL . '  Aliases:' . PHP_EOL;

        $configuredTypes = array();
        foreach ($di->instanceManager()->getAliases() as $alias => $class) {
            echo '    ' . $alias . ' [type: ' . $class . ']' . PHP_EOL;
            $configuredTypes[] = $alias;
        }

        echo PHP_EOL . '  Classes:' . PHP_EOL;

        foreach ($di->instanceManager()->getClasses() as $class) {
            echo '    ' . $class . PHP_EOL;
            $configuredTypes[] = $class;
        }

        echo PHP_EOL . '  Configurations:' . PHP_EOL;
        
        foreach ($configuredTypes as $type) {
            $info = $di->instanceManager()->getConfiguration($type);
            echo '    ' . $type . PHP_EOL;
            foreach ($info['parameters'] as $param => $value) {
                echo '      ' . $param . ' = ' . $value . PHP_EOL;
            }
        }

    }
开发者ID:rickogden,项目名称:zf2,代码行数:48,代码来源:Console.php

示例15: __construct

 protected function __construct(Di $oDi)
 {
     $this->oJobQueueDb = $oDi->get('Classes\\Db\\JobQueue');
     $this->oBoxDb = $oDi->get('Classes\\Db\\Box');
     $this->oFolioDb = $oDi->get('Classes\\Db\\Folio');
     $this->oItemDb = $oDi->get('Classes\\Db\\Item');
     $this->oErrorLogDb = $oDi->get('Classes\\Db\\ErrorLog');
     $this->oFile = $oDi->get('Classes\\Helpers\\File');
     $this->oLogger = $oDi->get('Classes\\Helpers\\Logger');
 }
开发者ID:tomcbe,项目名称:cbp-transcription-desk,代码行数:10,代码来源:TaskAbstract.php


注:本文中的Zend\Di\Di类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。