Created
April 13, 2024 09:48
-
-
Save atakde/56b12701bfb6b20e77f7070d88a91209 to your computer and use it in GitHub Desktop.
PHP Proxy pattern example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface AnyInterface | |
{ | |
public function anyMethod(); | |
} | |
class AnyClass implements AnyInterface | |
{ | |
public function anyMethod() | |
{ | |
echo "AnyClass::anyMethod() called\n"; | |
} | |
} | |
class AnyProxy implements AnyInterface | |
{ | |
private $anyClass; | |
public function __construct(AnyInterface $anyClass) | |
{ | |
$this->anyClass = $anyClass; | |
} | |
public function anyMethod() | |
{ | |
echo "AnyProxy::anyMethod() called\n"; | |
$this->anyClass->anyMethod(); | |
} | |
} | |
$anyClass = new AnyClass(); | |
$anyProxy = new AnyProxy($anyClass); | |
$anyProxy->anyMethod(); | |
/* | |
* Output: | |
* AnyProxy::anyMethod() called | |
* AnyClass::anyMethod() called | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment