本文整理匯總了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();
示例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";