美文网首页
前端控制器模式

前端控制器模式

作者: 散装咖啡 | 来源:发表于2017-05-30 02:55 被阅读49次
//frontController
class HomeView
{
    public function show()
    {
        echo "Displaying Home Page". "<br />";
    }
}

class StudentView
{
    public function show()
    {
        echo "Displaying Student Page". "<br />";
    }
}

class Dispatcher
{
    private $studentView = null;
    private $homeView = null;
    
    public function __construct()
    {
        $this->studentView = new StudentView();
        $this->homeView = new HomeView();
    }
    
    public function dispatch($request)
    {
        //返回0就是相等
        if (!strcasecmp('STUDENT', $request)) {
            $this->studentView->show();
        } else {
            $this->homeView->show();
        }
    }
}

class FrontController
{
    private $dispatcher = null;
    public function __construct()
    {
        $this->dispatcher = new Dispatcher();
    }
    public function isAuthenticUser(){
        echo "User is authenticated successfully.";
        return true;
    }
    public function trackRequest($request)
    {
        echo "Page requested: " . $request;
    }
    
    public function dispatchRequest($request)
    {
        //记录每一个请求
        $this->trackRequest($request);
        //对用户进行身份验证
      if($this->isAuthenticUser()){
         $this->dispatcher->dispatch($request);
      }
    }
}

$FrontController = new FrontController();
$FrontController->dispatchRequest("HOME");
$FrontController->dispatchRequest("STUDENT");

参考文章 http://www.runoob.com/design-pattern/front-controller-pattern.html

相关文章

  • 无标题文章

    前端控制器模式前端控制器模式(Front Controller Pattern)是用来提供一个集中的请求处理机制,...

  • Java设计模式(3):前端控制器模式

    前端控制器模式(Front Controller Pattern)提供一种可以集中管理请求的控制器,即所谓的前端控...

  • DispatcherServlet作用

    3.1、DispatcherServlet作用 DispatcherServlet是前端控制器设计模式的实现,提供...

  • DispatcherServlet-解析

    DispatcherServlet作用 DispatcherServlet是前端控制器设计模式的实现,提供Spri...

  • (二) Dispather

    3.1、DispatcherServlet作用DispatcherServlet是前端控制器设计模式的实现,提供S...

  • Spring核心-DispatcherServlet详解

    1. DispatcherServlet功能 DispatcherServlet是前端控制器设计模式的实现,提供了...

  • Spring MVC总体结构图和原理解析

    前端控制器 上图是前端控制器的原理图 为什么叫做前端控制器?举个例子: 前端控制器很类似医院的分诊台。 在前端控制...

  • springmvc

    springMVC SpringMVC:前端控制器,映射器,适配器,控制器,试图解析器 前端控制器 前端控制器在w...

  • SpringMVC框架

    springMVC SpringMVC:前端控制器,映射器,适配器,控制器,试图解析器 前端控制器 前端控制器在w...

  • SpringMVC

    SpringMVC SpringMVC:前端控制器,映射器,适配器,控制器,试图解析器 前端控制器 前端控制器在w...

网友评论

      本文标题:前端控制器模式

      本文链接:https://www.haomeiwen.com/subject/yrglfxtx.html