當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。