<?php
class Luntai
{
function roll ()
{
echo "lun tai zai gun dong";
}
}
class Bmw
{
protected $luntai;
function __construct ($luntai)
{
$this->luntai = $luntai;
}
function run ()
{
// $luntai = new Luntai();
$this->luntai->roll();
echo "kai zhe bao ma chi kao cuan";
}
}
class Container
{
static $register = [];
static function bind ($name, Closure $col)
{
self::$register[$name] = $col;
}
static function make ($name)
{
$col = self::$register[$name];
return $col();
}
}
Container::bind("luntai", function () {
return new Luntai();
});
Container::bind('bmw', function () {
return new Bmw(Container::make('luntai'));
});
$bmw = Container::make('bmw');
$bmw->run();
php高级实战-容器模式
最新推荐文章于 2025-06-09 20:03:58 发布