-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f4202e
commit 85ec223
Showing
25 changed files
with
877 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GPlacesPhp\ApiClient\Client; | ||
|
||
use GPlacesPhp\ApiClient\Client\FindPlace\Candidate; | ||
|
||
final class FindPlace | ||
{ | ||
/** @var Candidate[] */ | ||
private $candidates; | ||
|
||
private function __construct(Candidate ...$candidates) | ||
{ | ||
$this->candidates = $candidates; | ||
} | ||
|
||
/** @return Candidate[] */ | ||
public function candidates(): array | ||
{ | ||
return $this->candidates; | ||
} | ||
|
||
public static function fromArray(array $data): self | ||
{ | ||
return new self( | ||
...\array_map( | ||
function (array $candidateData): Candidate { | ||
return Candidate::fromArray($candidateData); | ||
}, | ||
$data ?? [] | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GPlacesPhp\ApiClient\Client\FindPlace; | ||
|
||
use GPlacesPhp\ApiClient\Client\Geometry; | ||
|
||
final class Candidate | ||
{ | ||
/** @var string */ | ||
private $formattedAddress; | ||
/** @var Geometry */ | ||
private $geometry; | ||
/** @var string */ | ||
private $name; | ||
/** @var string */ | ||
private $placeId; | ||
/** @var string */ | ||
private $id; | ||
|
||
private function __construct( | ||
string $formattedAddress, | ||
Geometry $geometry, | ||
string $name, | ||
string $placeId, | ||
string $id | ||
) { | ||
$this->formattedAddress = $formattedAddress; | ||
$this->geometry = $geometry; | ||
$this->name = $name; | ||
$this->placeId = $placeId; | ||
$this->id = $id; | ||
} | ||
|
||
public function placeId(): string | ||
{ | ||
return $this->placeId; | ||
} | ||
|
||
public function id(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function geometry(): Geometry | ||
{ | ||
return $this->geometry; | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public static function fromArray(array $data): self | ||
{ | ||
return new self( | ||
$data['formatted_address'] ?? '', | ||
Geometry::fromArray($data['geometry'] ?? []), | ||
$data['name'] ?? '', | ||
$data['place_id'] ?? '', | ||
$data['id'] ?? '' | ||
); | ||
} | ||
|
||
public function formattedAddress(): string | ||
{ | ||
return $this->formattedAddress; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GPlacesPhp\ApiClient\Client\FindPlace; | ||
|
||
final class OptionalParameters | ||
{ | ||
/** @var null|string */ | ||
private $language; | ||
/** @var array */ | ||
private $fields; | ||
|
||
private function __construct(?string $language = null, array $fields = []) | ||
{ | ||
$this->language = $language; | ||
$this->fields = $fields; | ||
} | ||
|
||
public static function fromArray(array $data): self | ||
{ | ||
return new self( | ||
$data['language'] ?? null, | ||
\array_map( | ||
function (string $field): string { | ||
return $field; | ||
}, | ||
$data['fields'] ?? [] | ||
) | ||
); | ||
} | ||
|
||
/** @param string[] $fields */ | ||
public static function fromArguments(?string $language = null, array $fields = []): self | ||
{ | ||
return new self( | ||
$language, | ||
\array_map( | ||
function (string $field): string { | ||
return $field; | ||
}, | ||
$fields | ||
) | ||
); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return \array_filter( | ||
[ | ||
'language' => $this->language, | ||
'fields' => \implode(',', $this->fields), | ||
], | ||
function ($value): bool { | ||
return !empty($value); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.