Php Utils Package
There are many utils:
Enum
- EnumToArray.php
Exceptions
- LogicException.php
- RuntimeException.php
- UnprocessableException.php
- ValidationException.php
GeoLocation
- GpsCoordinates.php
Helpers
- Dumper.php
Http
- StatusCode.php
Add following to your composer.json
:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ulovdomov/php-utils"
}
]
}
And run:
composer require ulovdomov/utils
$lat = 50.33424;
$lng = 12.21344;
$coordinates = \UlovDomov\GeoLocation\GpsCoordinates::from($lat, $lng);
self::assertSame($lat, $coordinates->getLatitude());
self::assertSame($lng, $coordinates->getLongitude());
self::assertSame([
'lat' => $lat,
'lng' => $lng,
], $coordinates->toArray());
Check if your coordinates are in proximity with other coordinates
$maxLatTolerance = 0.007; // cca 500m latitude
$maxLngTolerance = 0.005; // cca 500m longitude
$checked = \UlovDomov\GeoLocation\GpsCoordinates::from(50.63821, 12.02224);
$coordinates->isInProximity($checked, $maxLatTolerance, $maxLngTolerance);
You can convert any value to string with method toString
:
$var = /* any value */;
echo UlovDomov\Helpers\Dumper::toString($var);
You can convert values to php code toPhp
:
$var = [
'foo' => 'bar',
];
$string = UlovDomov\Helpers\Dumper::toPhp($var);
// $string contains
"['foo' => 'bar']"
- Run for initialization
make init
- Run composer install
make composer
Use tasks in Makefile:
- To log into container
make docker
- To run code sniffer fix
make cs-fix
- To run PhpStan
make phpstan
- To run tests
make phpunit