本文整理汇总了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";