當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。