当前位置: 首页>>代码示例>>PHP>>正文


PHP Proxy::request方法代码示例

本文整理汇总了PHP中Proxy::request方法的典型用法代码示例。如果您正苦于以下问题:PHP Proxy::request方法的具体用法?PHP Proxy::request怎么用?PHP Proxy::request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Proxy的用法示例。


在下文中一共展示了Proxy::request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: request

 * Proxy pattern
 *
 * author:	0xnz
 */
interface Subject
{
    public function request();
}
class RealSubject implements Subject
{
    public function request()
    {
        printf("Handling request in real subject\n");
    }
}
class Proxy implements Subject
{
    var $subject;
    public function Proxy($subject)
    {
        $this->subject = $subject;
    }
    // pass request to real subject
    public function request()
    {
        $this->subject->request();
    }
}
$proxy = new Proxy(new RealSubject());
$proxy->request();
开发者ID:luisOO,项目名称:design-patterns,代码行数:30,代码来源:proxy.php

示例2: authenticate

}
class ProtectionProxy implements ISubject, IProtected
{
    private $subject;
    private $password = "Abracadabra";
    public function authenticate(string $supplied) : string
    {
        if ($supplied != $this->password) {
            return "Protection Proxy: No Access!";
        }
        $this->subject = new Subject();
        return "Protection Proxy: Authenticated";
    }
    public function request() : string
    {
        if ($this->subject == null) {
            return 'Protection Proxy: Authenticate first!';
        }
        return 'Protection Proxy: Call to ' . $this->subject->request();
    }
}
$subject = new Proxy();
echo $subject->request(), "\n";
echo $subject->request(), "\n";
$subject = new ProtectionProxy();
echo $subject->request(), "\n";
if ($subject instanceof IProtected) {
    echo $subject->authenticate("Secret"), "\n";
    echo $subject->authenticate("Abracadabra"), "\n";
}
echo $subject->request(), "\n";
开发者ID:edin,项目名称:php-design-patterns,代码行数:31,代码来源:Proxy.php


注:本文中的Proxy::request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。