2015-05-29 12:11:16 +02:00
|
|
|
`Proxy`__
|
|
|
|
=========
|
2015-04-02 00:03:33 +02:00
|
|
|
|
|
|
|
Purpose
|
|
|
|
-------
|
|
|
|
|
|
|
|
To interface to anything that is expensive or impossible to duplicate.
|
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
- Doctrine2 uses proxies to implement framework magic (e.g. lazy
|
|
|
|
initialization) in them, while the user still works with his own
|
|
|
|
entity classes and will never use nor touch the proxies
|
|
|
|
|
|
|
|
UML Diagram
|
|
|
|
-----------
|
|
|
|
|
|
|
|
.. image:: uml/uml.png
|
|
|
|
:alt: Alt Proxy UML Diagram
|
|
|
|
:align: center
|
|
|
|
|
|
|
|
Code
|
|
|
|
----
|
|
|
|
|
2017-04-03 19:14:10 -06:00
|
|
|
You can also find this code on `GitHub`_
|
2015-04-02 00:03:33 +02:00
|
|
|
|
2018-06-14 22:17:14 +02:00
|
|
|
BankAccount.php
|
2015-04-02 00:03:33 +02:00
|
|
|
|
2018-06-14 22:17:14 +02:00
|
|
|
.. literalinclude:: BankAccount.php
|
2015-04-02 00:03:33 +02:00
|
|
|
:language: php
|
|
|
|
:linenos:
|
|
|
|
|
2018-06-14 22:17:14 +02:00
|
|
|
HeavyBankAccount.php
|
2015-04-02 00:03:33 +02:00
|
|
|
|
2018-06-14 22:17:14 +02:00
|
|
|
.. literalinclude:: HeavyBankAccount.php
|
|
|
|
:language: php
|
|
|
|
:linenos:
|
|
|
|
|
|
|
|
BankAccountProxy.php
|
|
|
|
|
|
|
|
.. literalinclude:: BankAccountProxy.php
|
2015-04-02 00:03:33 +02:00
|
|
|
:language: php
|
|
|
|
:linenos:
|
|
|
|
|
|
|
|
Test
|
|
|
|
----
|
|
|
|
|
2019-09-12 21:13:40 +02:00
|
|
|
ProxyTest.php
|
|
|
|
|
|
|
|
.. literalinclude:: Tests/ProxyTest.php
|
|
|
|
:language: php
|
|
|
|
:linenos:
|
|
|
|
|
2020-06-20 11:27:02 -03:00
|
|
|
.. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/main/Structural/Proxy
|
2015-05-29 12:11:16 +02:00
|
|
|
.. __: http://en.wikipedia.org/wiki/Proxy_pattern
|