當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Container::share方法代碼示例

本文整理匯總了PHP中Container::share方法的典型用法代碼示例。如果您正苦於以下問題:PHP Container::share方法的具體用法?PHP Container::share怎麽用?PHP Container::share使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Container的用法示例。


在下文中一共展示了Container::share方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testContainerToCallback

 public function testContainerToCallback()
 {
     $c = new Container();
     $c->share('service', function (Container $container) {
         return $container;
     });
     $this->assertInstanceOf(Container::class, $c->get('service'));
 }
開發者ID:nicklasos,項目名稱:BoringDI,代碼行數:8,代碼來源:ContainerTest.php

示例2: testShare

 public function testShare()
 {
     $this->object['obj'] = $this->object->share(function () {
         return new \stdClass();
     });
     $this->assertInstanceOf('\\stdClass', $this->object['obj']);
     $obj1 = $this->object['obj'];
     $obj2 = $this->object['obj'];
     $this->assertTrue($obj2 === $obj1);
 }
開發者ID:packfire,項目名稱:fuelblade,代碼行數:10,代碼來源:ContainerTest.php

示例3: testComplex

 public function testComplex()
 {
     $c = new Container();
     $c->share('A', function (Container $c) {
         return new A($c->get('B'), $c->get('C'));
     });
     $c->share('B', function (Container $c) {
         return new B($c->get('D'));
     });
     $c->share('C', function () {
         return new C();
     });
     $c->share('D', function () {
         return new D();
     });
     /** @var A $a */
     $a = $c->get('A');
     $this->assertEquals('ok', $a->x());
 }
開發者ID:nicklasos,項目名稱:BoringDI,代碼行數:19,代碼來源:ComplexTest.php

示例4: testExtendSharedServiceAfterConstruct

 /**
  * @expectedException        UnexpectedValueException
  * @expectedExceptionMessage Item "sharedService" is not a closure or invokable object and cannot be extended 
  */
 public function testExtendSharedServiceAfterConstruct()
 {
     $container = new Container();
     $container->share('sharedService', function ($container) {
         return new \stdClass();
     });
     $service = $container->get('sharedService');
     $container->extend('sharedService', function ($container) {
         $container->get('sharedService')->member = 'value';
     });
 }
開發者ID:frizzy,項目名稱:container,代碼行數:15,代碼來源:ContainerTest.php

示例5: testGetShared

 public function testGetShared()
 {
     $container = new Container();
     $container->share('service', function () {
         return new \stdClass();
     });
     $service1 = $container->service;
     $service2 = $container->service;
     $this->assertInstanceOf('stdClass', $service1);
     $this->assertInstanceOf('stdClass', $service2);
     $this->assertSame($service2, $service1);
 }
開發者ID:marcojetson,項目名稱:quark,代碼行數:12,代碼來源:ContainerTest.php


注:本文中的Container::share方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。