Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willavelar/php-design-pattern-structural-proxy
About a simple php example about the structural pattern: Proxy
https://github.com/willavelar/php-design-pattern-structural-proxy
design-patterns php proxy structural-patterns
Last synced: 6 days ago
JSON representation
About a simple php example about the structural pattern: Proxy
- Host: GitHub
- URL: https://github.com/willavelar/php-design-pattern-structural-proxy
- Owner: willavelar
- Created: 2023-11-20T13:56:57.000Z (almost 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-20T13:59:12.000Z (almost 1 year ago)
- Last Synced: 2023-11-20T14:49:15.765Z (almost 1 year ago)
- Topics: design-patterns, php, proxy, structural-patterns
- Language: PHP
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Proxy
Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.
-----
We need to create a discount calculator, where the calculation makes a request to an external API
### The problem
If we do it this way, we are held hostage by the API if it takes too long
```php
value * 0.1;(new RedisLog())->save($discountCalc);
return $discountCalc;
}
}
```
```php
discountCalculator = $discountCalculator;
}public function calc(Budget $budget): float
{
if ($this->calcProxy == 0) {
$this->calcProxy = $this->discountCalculator->calc($budget);
}return $this->calcProxy;
}
}
```-----
### Installation for test
![PHP Version Support](https://img.shields.io/badge/php-7.4%2B-brightgreen.svg?style=flat-square) ![Composer Version Support](https://img.shields.io/badge/composer-2.2.9%2B-brightgreen.svg?style=flat-square)
```bash
composer install
``````bash
php wrong/test.php
php right/test.php
```