Skip to content

Commit

Permalink
Move providers to new namespace (#604)
Browse files Browse the repository at this point in the history
* Started to move providers to new namespace

* Moved all providers and tests to a new folder

* Updated composer json

* Moved around the GeoIP2Adapter

* Added changelog

* Added more composer.json files

* minor fixes

* Namespace local (#1)

* fix

* bugfix

* Make sure we run tests for common

* tests

* debug

* Added some config

* Updated path to phpunit

* debug

* debub

* added phpunit file

* minor

* Fixed to get phpunit-bridge to work

* Do not use simple-phpunit

* Fixed broken tests

* Fixed broken tests

* Use curl-client and guzzlehttp/psr7: ^1.4

* Remove Guzzle

* Require latest version of CurlClient

* Updated style config

* Style fix

* Namespace patch 1 (#2)

* Make sure tests run

* Use Curl

* Renamed cached files
  • Loading branch information
Nyholm committed May 13, 2017
0 parents commit d2db6d3
Show file tree
Hide file tree
Showing 59 changed files with 4,341 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Assert.php
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder;

class Assert
{
/**
* @param float $value
* @param string $message
*/
public static function latitude($value, $message = '')
{
if (!is_float($value)) {
throw new \InvalidArgumentException(
sprintf($message ?: 'Expected a double. Got: %s', self::typeToString($value))
);
}

if ($value < -90 || $value > 90) {
throw new \InvalidArgumentException(
sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)
);
}
}

/**
* @param float $value
* @param string $message
*/
public static function longitude($value, $message = '')
{
if (!is_float($value)) {
throw new \InvalidArgumentException(
sprintf($message ?: 'Expected a doable. Got: %s', self::typeToString($value))
);
}

if ($value < -180 || $value > 180) {
throw new \InvalidArgumentException(
sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)
);
}
}

private static function typeToString($value)
{
return is_object($value) ? get_class($value) : gettype($value);
}
}
47 changes: 47 additions & 0 deletions Collection.php
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder;

/**
* This is the interface that is always return from a Geocoder.
*
* @author William Durand <william.durand1@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
interface Collection extends \IteratorAggregate, \Countable
{
/**
* @return Location
*/
public function first();

/**
* @return Location[]
*/
public function slice($offset, $length = null);

/**
* @return bool
*/
public function has($index);

/**
* @return Location
*
* @throws \OutOfBoundsException
*/
public function get($index);

/**
* @return Location[]
*/
public function all();
}
29 changes: 29 additions & 0 deletions Dumper/Dumper.php
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder\Dumper;

use Geocoder\Location;

/**
* @author William Durand <william.durand1@gmail.com>
*/
interface Dumper
{
/**
* Dumps an `Location` object as a string representation of
* the implemented format.
*
* @param Location $location
*
* @return string
*/
public function dump(Location $location);
}
61 changes: 61 additions & 0 deletions Dumper/GeoArray.php
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder\Dumper;

use Geocoder\Location;

/**
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
*/
class GeoArray implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location)
{
$properties = array_filter($location->toArray(), function ($value) {
return !empty($value);
});

unset(
$properties['latitude'],
$properties['longitude'],
$properties['bounds']
);

if (0 === count($properties)) {
$properties = null;
}

$lat = 0;
$lon = 0;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}

$array = [
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [$lon, $lat],
],
'properties' => $properties,
];

if (null !== $bounds = $location->getBounds()) {
$array['bounds'] = $bounds->toArray();
}

return $array;
}
}
61 changes: 61 additions & 0 deletions Dumper/GeoJson.php
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder\Dumper;

use Geocoder\Location;

/**
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class GeoJson implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location)
{
$properties = array_filter($location->toArray(), function ($value) {
return !empty($value);
});

unset(
$properties['latitude'],
$properties['longitude'],
$properties['bounds']
);

if (0 === count($properties)) {
$properties = null;
}

$lat = 0;
$lon = 0;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}

$json = [
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [$lon, $lat],
],
'properties' => $properties,
];

if (null !== $bounds = $location->getBounds()) {
$json['bounds'] = $bounds->toArray();
}

return json_encode($json);
}
}
96 changes: 96 additions & 0 deletions Dumper/Gpx.php
@@ -0,0 +1,96 @@
<?php

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder\Dumper;

use Geocoder\Geocoder;
use Geocoder\Location;

/**
* @author William Durand <william.durand1@gmail.com>
*/
class Gpx implements Dumper
{
/**
* @param Location $location
*
* @return string
*/
public function dump(Location $location)
{
$gpx = sprintf(<<<'GPX'
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx
version="1.0"
creator="Geocoder" version="%s"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
GPX
, Geocoder::VERSION);

if (null !== $bounds = $location->getBounds()) {
$gpx .= sprintf(<<<'GPX'
<bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>
GPX
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
}

$lat = null;
$lon = null;
if (null !== $coordinates = $location->getCoordinates()) {
$lat = $coordinates->getLatitude();
$lon = $coordinates->getLongitude();
}

$gpx .= sprintf(<<<'GPX'
<wpt lat="%.7f" lon="%.7f">
<name><![CDATA[%s]]></name>
<type><![CDATA[Address]]></type>
</wpt>
GPX
, $lat, $lon, $this->formatName($location));

$gpx .= <<<'GPX'
</gpx>
GPX;

return $gpx;
}

/**
* @param Location $address
*
* @return string
*/
protected function formatName(Location $address)
{
$name = [];
$array = $address->toArray();
$attrs = [
['streetNumber'],
['streetName'],
['postalCode'],
['locality'],
['adminLevels', 2, 'name'],
['adminLevels', 1, 'name'],
['country'],
];

foreach ($attrs as $attr) {
$name[] = \igorw\get_in($array, $attr);
}

return implode(', ', array_filter($name));
}
}

0 comments on commit d2db6d3

Please sign in to comment.