design-patterns/resources/view/patterns/abstract-factory.php

40 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @package: patterns
* @author: Yevhen Odynets
* @date: 2025-07-03
* @time: 20:20
*/
declare(strict_types = 1);
use Pattern\Creational\AbstractFactory\{ParcelSender, ProvidersEnum as PostProvider};
/**
* @param array $parcels
*
* @return void
*/
function doDeliver(array $parcels): void
{
foreach ($parcels as $parcel) {
['provider' => $provider, 'destination_address' => $address] = $parcel;
$result = (new ParcelSender($provider, $address))->send();
echo $result ? "✔️ Sent successfully\n" : "❌ Sending failed\n";
}
}
$parcels = [
['provider' => PostProvider::NovaPost, 'destination_address' => "02020,\r\nм. Щастя, рХТЗ"],
[
'provider' => PostProvider::UkrPost,
'destination_address' => "Голобородько Семен Юхимович,\r\nn02020, Львівська обл.,\r\nм. Городок, вул. Головна, буд. 1, кв. 50",
],
['provider' => PostProvider::Meest, 'destination_address' => "Адреса 3"],
['provider' => PostProvider::Justin, 'destination_address' => "Відділення 777"],
];
doDeliver($parcels);