arunagirinathar/php-design-patterns
最新稳定版本:v1.3.1
Composer 安装命令:
composer require arunagirinathar/php-design-patterns
包简介
A lightweight PHP package implementing common design patterns like Singleton and Factory. Useful for clean and efficient object management in PHP projects.
README 文档
README
A lightweight PHP package implementing common design patterns like Singleton and Factory. Useful for clean and efficient object management in PHP projects.
Design Patterns (PHP)
A lightweight PHP package implementing common design patterns like Singleton and Factory. Useful for clean and efficient object management in PHP projects.
📌 Features
✅ Singleton – Ensures only one instance of a class exists.
✅ Factory – Creates objects without specifying the exact class type.
Polyfills (Extra Feature)
Older versions of PHP may not have certain function available. For example
json_validate() is not available in PHP versions older than 8.3.0.
This class transparently implements all this functionality as a shim / polyfill without disturbing environments where such functions are available.
Functions currently implemented in the polyfills
✅ json_validate
📥 Installation
Using Composer:
composer require arunagirinathar/design-patterns
🛠 Usage
Singleton Example
use Arunagirinathar\DesignPatterns\Singleton; class MySingleton extends Singleton { private string $data = "Hello, Singleton!"; public function getData(): string { return $this->data; } } $instance1 = MySingleton::getInstance(); $instance2 = MySingleton::getInstance(); echo $instance1->getData(); // Hello, Singleton! var_dump($instance1 === $instance2); // true (Both refer to the same instance)
📝 License
This project is licensed under the GNU GPLv3. See the LICENSE file for details.
📬 Contact
Maintainer: Arunagirinathar
📧 Email: arunagirinathar@gmail.com
🔗 GitHub: Arunagirinathar/DesignPatterns
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2025-03-12