6.1 프록시
Minor는 Java 및 Proxy 클래스의 InvocationHandler 인터페이스와 유사한 프록시 모드 구현을 제공합니다. 자세한 내용은 내 문서(http://)를 참조하세요. www.cnblogs.com/orlion/p/5350752.html
6.1.1
<span>class</span> FooController <span>extends</span><span> Controller { </span><span>public</span><span>function</span> bar(<span>$productName</span><span>) { </span><span>$log</span> = <span>new</span><span> LogHandler(); </span><span>$shop</span> = <span>new</span><span> Shop(); </span><span>$shopProxy</span> = Proxy::newProxyInstance(<span>$shop</span>, <span>$log</span><span>); </span><span>$shopProxy</span>->buy(<span>$productName</span><span>); } }</span>
<?<span>php namespace App\Lib; </span><span>use</span><span> Minor\Proxy\InvocationHandler; </span><span>class</span> LogHandler <span>implements</span><span> InvocationHandler { </span><span>public</span><span>function</span> invoke(<span>$target</span>, \ReflectionMethod <span>$method</span>, <span>Array</span><span>$args</span> =<span> []) { </span><span>$this</span>-><span>before(); </span><span>$result</span> = <span>$method</span>->invokeArgs(<span>$target</span>, <span>$args</span><span>); </span><span>$this</span>-><span>after(); </span><span>return</span><span>$result</span><span>; } </span><span>public</span><span>function</span><span> before() { </span><span>echo</span> '[LogHandler] before<br/><br/>'<span>; } </span><span>public</span><span>function</span><span> after() { </span><span>echo</span> '[LogHandler] after<br/><br/>'<span>; } }</span>사용
<?<span>php namespace App\Lib; </span><span>class</span><span> Shop { </span><span>private</span><span>$mail</span> = <span>null</span><span>; </span><span>public</span><span>function</span> boot(MailProvider <span>$mail</span><span>) { </span><span>$this</span>-><span>mail</span> = <span>$mail</span><span>; } </span><span>public</span><span>function</span> buy(<span>$productName</span><span>) { </span><span>echo</span> '[Shop] buy ' . <span>$productName</span> . '<br/><br/>'<span>; </span>!<span>is_null</span>(<span>$this</span>-><span>mail</span>) && <span>$this</span>-><span>mail</span>->send('DemoUser'<span>); } }</span>
위 내용은 무단프록시와 겉보기프록시의 내용을 포함하여 무단프록시와 겉보기프록시 Minor6 프록시를 소개한 내용이 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.