美文网首页
魔术方法(拦截器)

魔术方法(拦截器)

作者: 幻无虚生 | 来源:发表于2019-07-18 14:34 被阅读0次
<?php
class PersonWrite{

    function writeName(Person $p){
        print $p->getName()."\n";
    }


    function writeAge(Person $p){
        print $p->getAge()."\n";
    }

}



class Person{
    private $writer;

    public function __construct(PersonWrite $writer){
            $this->writer=$writer;
    }

    public function __call($mothod,$args){
        if(method_exists($this->writer,$mothod)){
            return $this->writer->$mothod($this);
        }
    }


    function getName(){
        return "Bob";
    }

    function getAge(){
        return "44";
    }

    public function __toString()
    {

       return $this->getAge();
    }

}


$person=new Person(new PersonWrite());

$person->writeName();

相关文章

  • 魔术方法(拦截器)

  • Python魔术方法

    Python魔术方法 Python 魔术方法指南 — PyCoder’s Weelky CNPython的魔术方法...

  • 拦截器Interceptor

    拦截器怎么写 拦截器配置可以从struts-default.xml中找到相关资源 拦截器拦截制定方法拦截指定的方法...

  • 0219 springmvc-拦截器和响应增强

    拦截器 拦截器分同步拦截器和异步拦截器; HandlerInterceptor 方法和执行时机 可以看Dispat...

  • 登录拦截器

    定义注解和拦截器 自定义注解,对标记了注解的方法进行拦截 定义拦截器,根据注解进行方法拦截 配置拦截器 使用

  • Python面向对象的魔术方法

    魔术方法 查看类的魔术方法 输出结果如下 在Python中,所有以__双下划线包起来的方法,都统称为魔术方法。比如...

  • 魔术方法及魔术常量详解

    魔术方法 魔术方法中充当了举足轻重的作用,大部分魔术方法起着报错补救措施的作用 __construct()类的构造...

  • Python学习打call第三十天:魔术方法

    1.什么是魔术方法 在Python中以两个下划线开头和结尾的方法被称为魔术方法,魔术方法都是一些内置方法; 2.基...

  • 129、【JavaEE】【SpringMVC】SpringMVC

    拦截器正常执行时拦截器方法的执行顺序为:配置文件中在前面的拦截器的preHandle()方法先执行,然后根据配置文...

  • SpringMVC入门知识8

    拦截器拦截器的操作是基于aop的拦截器的定义:定义拦截器实现HandlerInteceptor接口,接口中三个方法...

网友评论

      本文标题:魔术方法(拦截器)

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