mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
2.3 KiB
2.3 KiB
Meritoo Common Library
Common and useful classes, methods, exceptions etc.
Value Objects
Located in Meritoo\Common\ValueObject namespace and in src/ValueObject/ directory.
Address
Namespace
Meritoo\Common\ValueObject\Address
Info
Represents address of company, institution, user etc. Contains properties:
$street- the street$buildingNumber- the number of building$flatNumber- the number of flat$zipCode- the zip code$city- the city, location
New instance
New instance can be created using constructor
new Address('New York', '00123', '4th Avenue', '10', '200');
Methods
Has getters for each property, e.g. getFlatNumber() or getZipCode(), and 1 extra method:
getFullStreet()
that returns name of street with related numbers (building & flat number).
Example:
$address = new Address('New York', '00123', '4th Avenue', '10', '200');
$fullStreet = $address->getFullStreet(); // "4th Avenue 10/200"
Conversion to string (the __toString() method)
Instance of Address may be represented as string that contains all non-empty properties separated by , .
Example:
$address = new Address('New York', '00123', '4th Avenue', '10', '200');
$asString = (string)$address; // "4th Avenue 10/200, 00123, New York"
Version
Namespace
Meritoo\Common\ValueObject\Version
Info
Represents version of software. Contains properties:
$majorPart- the "major" part of version$minorPart- the "minor" part of version$patchPart- the "patch" part of version
New instance
New instance can be created using:
-
Constructor:
new Version(1, 0, 2); -
Static methods:
fromArray()- creates new instance using given version as array
Version::fromArray([1, 0, 2]);fromString()- creates new instance using given version as string:
Version::fromString('1.0.2');