-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from answear/data-fetching
Data fetching
- Loading branch information
Showing
26 changed files
with
1,192 additions
and
4 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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Enum; | ||
|
||
use MabeEnum\Enum; | ||
|
||
class Day extends Enum | ||
{ | ||
public const MONDAY = '1'; | ||
public const TUESDAY = '2'; | ||
public const WEDNESDAY = '3'; | ||
public const THURSDAY = '4'; | ||
public const FRIDAY = '5'; | ||
public const SATURDAY = '6'; | ||
public const SUNDAY = '7'; | ||
|
||
public static function monday(): self | ||
{ | ||
return static::get(static::MONDAY); | ||
} | ||
|
||
public static function tuesday(): self | ||
{ | ||
return static::get(static::TUESDAY); | ||
} | ||
|
||
public static function wednesday(): self | ||
{ | ||
return static::get(static::WEDNESDAY); | ||
} | ||
|
||
public static function thursday(): self | ||
{ | ||
return static::get(static::THURSDAY); | ||
} | ||
|
||
public static function friday(): self | ||
{ | ||
return static::get(static::FRIDAY); | ||
} | ||
|
||
public static function saturday(): self | ||
{ | ||
return static::get(static::SATURDAY); | ||
} | ||
|
||
public static function sunday(): self | ||
{ | ||
return static::get(static::SUNDAY); | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Enum; | ||
|
||
use MabeEnum\Enum; | ||
|
||
class Service extends Enum | ||
{ | ||
public const DELIVERY = '100'; | ||
public const COD = '101'; | ||
public const SWAP = '300'; | ||
public const DROPOFF_ONLINE = '200'; | ||
public const DROPOFF_OFFLINE = '201'; | ||
public const MONITORED_DOCUMENTS = 'P10'; | ||
public const ROD = 'P20'; | ||
public const TYRES = 'P30'; | ||
public const PALLET = 'P90'; | ||
|
||
public static function delivery(): self | ||
{ | ||
return static::get(static::DELIVERY); | ||
} | ||
|
||
public static function cod(): self | ||
{ | ||
return static::get(static::COD); | ||
} | ||
|
||
public static function swap(): self | ||
{ | ||
return static::get(static::SWAP); | ||
} | ||
|
||
public static function dropoffOnline(): self | ||
{ | ||
return static::get(static::DROPOFF_ONLINE); | ||
} | ||
|
||
public static function dropoffOffline(): self | ||
{ | ||
return static::get(static::DROPOFF_OFFLINE); | ||
} | ||
|
||
public static function monitoredDocuments(): self | ||
{ | ||
return static::get(static::MONITORED_DOCUMENTS); | ||
} | ||
|
||
public static function rod(): self | ||
{ | ||
return static::get(static::ROD); | ||
} | ||
|
||
public static function tyres(): self | ||
{ | ||
return static::get(static::TYRES); | ||
} | ||
|
||
public static function pallet(): self | ||
{ | ||
return static::get(static::PALLET); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Enum; | ||
|
||
use MabeEnum\Enum; | ||
|
||
class Type extends Enum | ||
{ | ||
public const STANDARD = '100'; | ||
public const CHAIN = '200'; | ||
public const DPD = '300'; | ||
public const SWIP_BOX_1 = '400401'; | ||
public const SWIP_BOX_2 = '400402'; | ||
public const POINT_PACK = '500501'; | ||
public const FOREIGN_LOCKER = '400'; | ||
|
||
public static function standard(): self | ||
{ | ||
return self::get(self::STANDARD); | ||
} | ||
|
||
public static function chain(): self | ||
{ | ||
return self::get(self::CHAIN); | ||
} | ||
|
||
public static function dpd(): self | ||
{ | ||
return self::get(self::DPD); | ||
} | ||
|
||
public static function swipBox1(): self | ||
{ | ||
return self::get(self::SWIP_BOX_1); | ||
} | ||
|
||
public static function swipBox2(): self | ||
{ | ||
return self::get(self::SWIP_BOX_2); | ||
} | ||
|
||
public static function pointPack(): self | ||
{ | ||
return self::get(self::POINT_PACK); | ||
} | ||
|
||
public static function foreignLocker(): self | ||
{ | ||
return self::get(self::FOREIGN_LOCKER); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Exception; | ||
|
||
class MalformedResponseException extends \RuntimeException | ||
{ | ||
private string $response; | ||
|
||
public function __construct(string $response) | ||
{ | ||
parent::__construct('Response is not a valid XML'); | ||
$this->response = $response; | ||
} | ||
|
||
public function getResponse(): string | ||
{ | ||
return $this->response; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Exception; | ||
|
||
class ServiceException extends \RuntimeException | ||
{ | ||
} |
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ services: | |
autoconfigure: true | ||
public: false | ||
|
||
Answear\DpdPlPickupServicesBundle\: | ||
resource: '../../{Service}' |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Service; | ||
|
||
class ConfigProvider | ||
{ | ||
private string $url; | ||
private string $key; | ||
private float $requestTimeout; | ||
|
||
public function __construct(string $url, string $key, float $requestTimeout) | ||
{ | ||
$this->url = rtrim($url, '/') . '/'; | ||
$this->key = $key; | ||
$this->requestTimeout = $requestTimeout; | ||
} | ||
|
||
public function getUrl(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
public function getRequestTimeout(): float | ||
{ | ||
return $this->requestTimeout; | ||
} | ||
} |
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,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Answear\DpdPlPickupServicesBundle\Service; | ||
|
||
use Answear\DpdPlPickupServicesBundle\Enum\Day; | ||
use Answear\DpdPlPickupServicesBundle\Enum\Service; | ||
use Answear\DpdPlPickupServicesBundle\Enum\Type; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\AdditionalInfo; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\Address; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\Coordinates; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\HolidayDates; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\OpeningTime; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\PUDO; | ||
use Answear\DpdPlPickupServicesBundle\ValueObject\WeekStoreHours; | ||
|
||
class PUDOFactory | ||
{ | ||
public function fromXmlElement(\SimpleXMLElement $xml): PUDO | ||
{ | ||
$pudo = new PUDO(); | ||
$pudo->active = 'true' === (string) $xml['active']; | ||
$pudo->id = (string) $xml->PUDO_ID; | ||
$pudo->type = Type::byValue((string) $xml->PUDO_TYPE); | ||
$pudo->language = (string) $xml->LANGUAGE; | ||
$pudo->address = $this->createAddress($xml); | ||
$pudo->coordinates = new Coordinates((float) $xml->LATITUDE, (float) $xml->LONGITUDE); | ||
$pudo->additionalInfo = $this->createAdditionalInfo($xml); | ||
$pudo->opened = $this->createOpeningTimes($xml); | ||
$pudo->holidays = $this->createHolidays($xml); | ||
|
||
return $pudo; | ||
} | ||
|
||
private function createAddress(\SimpleXMLElement $xml): Address | ||
{ | ||
$address = new Address(); | ||
$address->address1 = (string) $xml->ADDRESS1; | ||
$address->address2 = (string) $xml->ADDRESS2; | ||
$address->address3 = (string) $xml->ADDRESS3; | ||
$address->locationHint = (string) $xml->LOCATION_HINT; | ||
$address->zipCode = (string) $xml->ZIPCODE; | ||
$address->city = (string) $xml->CITY; | ||
$address->country = (string) $xml->COUNTRY; | ||
|
||
return $address; | ||
} | ||
|
||
private function createAdditionalInfo(\SimpleXMLElement $xml): AdditionalInfo | ||
{ | ||
$info = new AdditionalInfo(); | ||
foreach (explode(';', (string) $xml->SERVICE_PUDO) as $service) { | ||
$info->services[] = Service::byValue($service); | ||
} | ||
$info->wheelchairAccessible = 'true' === (string) $xml->HANDICAPE; | ||
$info->parking = 'true' === (string) $xml->PARKING; | ||
|
||
return $info; | ||
} | ||
|
||
private function createOpeningTimes(\SimpleXMLElement $xml): WeekStoreHours | ||
{ | ||
$openings = []; | ||
foreach ($xml->OPENING_HOURS_ITEMS->OPENING_HOURS_ITEM as $opening) { | ||
$openings[] = new OpeningTime( | ||
Day::byValue((string) $opening->DAY_ID), | ||
(string) $opening->START_TM, | ||
(string) $opening->END_TM | ||
); | ||
} | ||
|
||
return new WeekStoreHours(...$openings); | ||
} | ||
|
||
/** | ||
* @return HolidayDates[] | ||
*/ | ||
private function createHolidays(\SimpleXMLElement $xml): array | ||
{ | ||
$dates = []; | ||
foreach ($xml->HOLIDAY_ITEMS->HOLIDAY_ITEM as $holiday) { | ||
$dates[] = new HolidayDates( | ||
\DateTimeImmutable::createFromFormat('d/m/Y', (string) $holiday->START_TM)->setTime(0, 0, 0), | ||
\DateTimeImmutable::createFromFormat('d/m/Y', (string) $holiday->END_TM)->setTime(23, 59, 59) | ||
); | ||
} | ||
|
||
return $dates; | ||
} | ||
} |
Oops, something went wrong.