Skip to content

Instantly share code, notes, and snippets.

@atakde
Created April 13, 2024 09:48
Show Gist options
  • Save atakde/56b12701bfb6b20e77f7070d88a91209 to your computer and use it in GitHub Desktop.
Save atakde/56b12701bfb6b20e77f7070d88a91209 to your computer and use it in GitHub Desktop.
PHP Proxy pattern example
<?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