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


PHP Container::bind方法代码示例

本文整理汇总了PHP中Container::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::bind方法的具体用法?PHP Container::bind怎么用?PHP Container::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


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

示例1: testCanBindInterfaceToImplementationUsingBind

 public function testCanBindInterfaceToImplementationUsingBind()
 {
     $this->container->bind('NetRivet\\Container\\Test\\BarInterface', 'NetRivet\\Container\\Test\\Bar1');
     $foo = $this->container->make('NetRivet\\Container\\Test\\Foo');
     $bar = $foo->getBar();
     $this->assertInstanceOf('NetRivet\\Container\\Test\\Bar1', $bar);
 }
开发者ID:netrivet,项目名称:container,代码行数:7,代码来源:ContainerTest.php

示例2: setUp

 /**
  * Setup the tests
  */
 public function setUp()
 {
     $this->app = IlluminageServiceProvider::make();
     $this->app->instance('path.public', 'tests/public');
     // Bind mocked config
     $this->app->bind('config', function () {
         return Mockery::mock('config', function ($mock) {
             $mock->shouldReceive('get')->with('illuminage::image_engine', '')->andReturn('Gd');
             $mock->shouldReceive('get')->with('illuminage::quality', '')->andReturn(75);
             $mock->shouldReceive('get')->with('illuminage::cache_folder', '')->andReturn('');
         });
     });
     // Create some dummy instances
     $this->image = $this->app['illuminage']->image('foo.jpg');
     $this->thumb = $this->app['illuminage']->thumb('foo.jpg', 100, 100);
 }
开发者ID:anahkiasen,项目名称:illuminage,代码行数:19,代码来源:IlluminageTestCase.php

示例3: bind

class Container
{
    protected $binds;
    protected $instances;
    public function bind($abstract, $concrete)
    {
        if ($concrete instanceof Closure) {
            $this->binds[$abstract] = $concrete;
        } else {
            $this->instances[$abstract] = $concrete;
        }
    }
    public function make($abstract, $parameters = [])
    {
        if (isset($this->instances[$abstract])) {
            return $this->instances[$abstract];
        }
        array_unshift($parameters, $this);
        return call_user_func_array($this->binds[$abstract], $parameters);
    }
}
$container = new Container();
$container->bind('superman', function ($container, $moduleName) {
    return new Superman($container->make($moduleName));
});
$container->bind('xpower', function ($container) {
    return new Xpower();
});
$superman_1 = $container->make('superman', ['xpower']);
var_dump($superman_1);
var_dump($superman_1 instanceof Superman);
开发者ID:Justin1989,项目名称:Toolkit,代码行数:31,代码来源:IoC.php

示例4: testBindReadOnly

 /**
  * @covers            ::bind
  * @expectedException RuntimeException
  */
 public function testBindReadOnly()
 {
     $this->container->setReadOnly(true);
     $this->container->bind('something', $value);
 }
开发者ID:fuelphp,项目名称:display,代码行数:9,代码来源:ContainerTest.php

示例5: Container

<?php

namespace RomanNumerals;

error_reporting(E_ALL);
ini_set('display_errors', 1);
require __DIR__ . '/vendor/autoload.php';
$routes = [['GET', '/api/generate/{arabicNumber:\\w+}', 'RomanNumerals\\ConvertController@generate'], ['GET', '/api/parse/{romanNumber:\\w+}', 'RomanNumerals\\ConvertController@parse']];
$container = new Container();
$container->bind('RomanNumerals\\ConvertController', function () {
    $object = new ConvertController();
    $object->setRomanNumeralGenerator(new RomanNumeralGenerator());
    return $object;
});
$container->bind('RomanNumerals\\Controller', function () {
    return new ConvertController();
});
$app = new Application($container, new Router($routes));
$app->start();
开发者ID:alexlvcom,项目名称:RomanNumeralGenerator,代码行数:19,代码来源:index.php

示例6: make

        }
    }
    public function make($abstract, $parameters = [])
    {
        if (isset($this->instances[$abstract])) {
            return $this->instances[$abstract];
        }
        array_unshift($parameters, $this);
        return call_user_func_array($this->binds[$abstract], $parameters);
    }
}
// 创建一个容器(后面称作超级工厂)
$container = new Container();
// 向该 超级工厂添加超人的生产脚本
$container->bind('superman', function ($container, $moduleName) {
    return new Superman($container->make($moduleName));
});
// 向该 超级工厂添加超能力模组的生产脚本
$container->bind('xpower', function ($container) {
    return new XPower();
});
// 同上
$container->bind('ultrabomb', function ($container) {
    return new UltraBomb();
});
// echo '<pre>' . print_r($container, true) . '</pre>';# test
// ****************** 华丽丽的分割线 **********************
// 开始启动生产
$superman_1 = $container->make('superman', ['xpower']);
// $superman_2 = $container->make('superman', 'ultrabomb');
$superman_3 = $container->make('superman', ['xpower']);
开发者ID:sac071213,项目名称:dev,代码行数:31,代码来源:test.php


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