kanekescom/laravel-helperia
最新稳定版本:v2.1.15
Composer 安装命令:
composer require kanekescom/laravel-helperia
包简介
Laravel helper package for speeding up application development
README 文档
README
Laravel helper package for speeding up application development.
Support the Project
If you find this package helpful, consider supporting its development:
Installation
composer require kanekescom/laravel-helperia
Usage
Helper Functions
Reflection Helpers
Get method names from a class:
// Get all public methods (excluding constructor, destructor, internal) method_public(MyClass::class); // Collection of method names // Get all protected methods method_protected(MyClass::class); // Get all private methods method_private(MyClass::class); // Get all methods (public, protected, private) method_all(MyClass::class); // Also works with object instances $obj = new MyClass(); method_public($obj); // Same result as using class name
Date Helpers
Convert and parse date formats:
// Convert date from one format to another convert_date_format('01-01-2024', 'd-m-Y', 'Y-m-d'); // "2024-01-01" convert_date_format('01-01-2024 10:30:00', 'd-m-Y H:i:s', 'Y-m-d H:i:s'); // Parse date string to specified format parse_date_format('2024-01-01', 'd M Y'); // "01 Jan 2024" parse_date_format('2024-01-01 10:30:00', 'd M Y H:i:s'); // With default value for invalid/null input convert_date_format(null, 'd-m-Y', 'Y-m-d', 'N/A'); // "N/A" convert_date_format('invalid-date', 'd-m-Y', 'Y-m-d', 'fallback'); // "fallback" parse_date_format('not-a-date', 'Y-m-d', 'default'); // "default"
Support Classes
ClassExtender
A base class for wrapping other classes and forwarding method calls:
use Kanekescom\Helperia\Support\ClassExtender; class MyWrapper extends ClassExtender { public function __construct() { $this->class = new SomeOtherClass(); } } $wrapper = new MyWrapper(); $wrapper->someMethod(); // Calls SomeOtherClass::someMethod()
HasMethodCaller Trait
Trait for forwarding method calls to a wrapped class instance:
use Kanekescom\Helperia\Traits\HasMethodCaller; class MyClass { use HasMethodCaller; protected $class; public function __construct($wrappedClass) { $this->class = $wrappedClass; } } // Usage $wrapper = new MyClass(new SomeService()); $wrapper->serviceMethod(); // Forwards to SomeService::serviceMethod() // Static method calls are also supported MyClass::staticMethod(); // Forwards static calls
Note: If a method doesn't exist on either the wrapper or wrapped class, a
BadMethodCallExceptionwill be thrown.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 3.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-24