1204 1205作业 (补)
- 文永原创转载
- 2019年12月09日 17:54:36583浏览
实例
<?php
namespace mvc;
require 'Model.php';
require 'View.php';
class Container1
{
protected $instance = [];
public function bind($alias, \Closure $process)
{
$this->instance[$alias] = $process;
}
public function make($alias, $params=[])
{
return call_user_func_array($this->instance[$alias], []);
}
}
$container = new Container1();
$container->bind('model', function () {return new Model();});
$container->bind('view', function () {return new View();});
class Facade
{
protected static $container = null;
protected static $data = [];
public static function initialize(Container1 $container)
{
static::$container = $container;
}
public static function getData()
{
static::$data = static::$container->make('model')->getData();
}
public static function fetch()
{
return static::$container->make('view')->fetch(static::$data);
}
}
class Student extends Facade
{
}
class Controller5
{
public function __construct(Container1 $container)
{
Student::initialize($container);
}
public function index()
{
Student::getData();
return Student::fetch();
}
}
$controller = new Controller5($container);
echo $controller->index();
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。