hdgarau / common
Common Functions
Installs: 29
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/hdgarau/common
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-09-20 22:31:49 UTC
README
Description
Library with basics Classes.
Index
- Date
- Parse
- Functions
1. Date
Period
Description
Is a class with static methods. That one return a date (type \Datetime) from a date and period indicated.
Some options are:
- days
- weeks
- months
- years
- weekBegin (first previous Monday)
- weekDay (first previous [day])
- monthLastDay
- getByCode (ConstantClassCode + ' ' + param)
Examples
Period::days(-3)->format('Y-m-d')); //three days ago
Period::setDefault('1985-02-15');
Period::getByCode('D 5')->format('Y-m-d'); //1985-02-20
Parse
Description
Parse a string to object by a token then It generates Entity and EntityGroup objects. Each entityGroup object has a property level. that indicates if it is contained for the previous one or a child has finished. For example if we parse de parenthesis for "That is a test (just a simple (very) test) to do":
- EntityGroup (level:0) - entities:
- Entity (content:"That is a test")
- EntityGroup (level:1) - entities:
- Entity (content:"just a simple")
- EntityGroup: (level:2) - entities:
- Entity: (content:"very")
- Entity: (content:"test")
- Entity: (content:"to do")
You can return to build the original string with casting (string)
Example
$str = '( this is a ( Complex (test) Resource ) and (his (1(2,2b(3)2c)1 ) brother) something)';
$oParsedParenthesis = StringParse::strToParsedGroupParenthesis($str );
print_r($oParsedParenthesis); //print object
echo (string) $oParsedParenthesis; // reverse to string