本文整理汇总了PHP中Container::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::make方法的具体用法?PHP Container::make怎么用?PHP Container::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container::make方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanBindInterfaceUsingWhenNeedsGive
public function testCanBindInterfaceUsingWhenNeedsGive()
{
$this->container->when('NetRivet\\Container\\Test\\Foo')->needs('NetRivet\\Container\\Test\\BarInterface')->give('NetRivet\\Container\\Test\\Bar2');
$foo = $this->container->make('NetRivet\\Container\\Test\\Foo');
$bar = $foo->getBar();
$this->assertInstanceOf('NetRivet\\Container\\Test\\Bar2', $bar);
}
示例2: runMigrations
/**
* Runs the migrations for devise in our sqlite memory db
*
* @return void
*/
public static function runMigrations()
{
$migrations = static::$application->make('migration.repository');
if (!$migrations->repositoryExists()) {
$migrations->createRepository();
}
$migrator = static::$application->make('migrator');
$migrator->run(__DIR__ . '/../src/migrations');
}
示例3: makeModel
/**
* Make Model.
*
* @return Model
*
* @throws RepositoryException
*/
public function makeModel()
{
$model = $this->app->make($this->model());
if (!$model instanceof Model) {
throw new RepositoryException("Class {$this->model()}" . " must be an instance of Illuminate\\Database\\Eloquent\\Model");
}
return $this->model = $model;
}
示例4: make
/**
* @param $className
* @param bool $singleton
* @return object
*/
public static function make($className, $singleton = true)
{
return static::$container->make($className, $singleton);
}
示例5: 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);
示例6: createClassCallable
/**
* Transform class to callable
*
* @param string|callable $handler
* @param Container $container
* @return callable
*/
protected function createClassCallable($handler, $container)
{
list($class, $method) = $this->parseClassCallable($handler);
return [$container->make($class), $method];
}
示例7: make
/**
* Resolve the class out of the Container
*
* @param string $class
* @return mixed
*/
public function make($class)
{
return $this->container->make($class);
}