nowmovesoft / helpers
PHP helpers
v1.0
2019-11-21 06:05 UTC
Requires
- php: >=7.0
Requires (Dev)
- codeception/base: ^3.0
- codeception/specify: ^1.0
- codeception/verify: ^1.0
This package is auto-updated.
Last update: 2025-04-13 13:16:48 UTC
README
Installation
Install via Composer
If you do not have Composer, you may install it by following the instructions at getcomposer.org.
You can then install this library using the following command:
composer require nowmovesoft/helpers
Basic usage
DateHelper
use nms\helpers\DateHelper; /* * Gets years range or one year if specified year is current. * For example, in 2019 it returns "2019", but in 2020 it returns "2019-2020" */ echo DateHelper::getYearsRange(2019);
ObjectHelper
If you have a method, which returns a class name, you can use ObjectHelper instead of this construction:
use nms\helpers\ObjectHelper; // instead of using tempotary variable... $className = Module::getInstance()->useClass; $model = new $className($paramOne, $paramTwo /* Other parameters */); // ...you can use ObjectHelper $model = ObjectHelper::create(Module::getInstance()->useClass, $paramOne, $paramTwo /* Other parameters */);
If you want to call static method, you can use ObjectHelper instead of this construction:
use nms\helpers\ObjectHelper; // instead of this... $result = Module::getInstance()->useClass::staticMethod($paramOne, $paramTwo /* Other parameters */); // ...you can use ObjectHelper $result = ObjectHelper::call(Module::getInstance()->useClass, 'staticMethod', $paramOne, $paramTwo /* Other parameters */);
If you want to populate your public class properties you can do it this way:
use nms\helpers\ObjectHelper; $object = new class { public $property = false; }; $object = ObjectHelper::configure($object, ['property' => true]); // name-value pairs var_dump($object->property); // true