فهرست مستندات پروژه
مرجع API
مرجع کامل برای تمام کلاسها، رابطها و متدهای عمومی.
Ersal (نقطه ورود)
namespace Eram\Ersal;
final class Ersal
{
public function __construct(
?HttpClient $httpClient = null,
?Logger $logger = null,
?EventDispatcher $eventDispatcher = null,
?SoapClientFactory $soapFactory = null,
);
public function create(string $provider, object $config): ShippingInterface;
/** @return list<string> */
public static function available(): array;
}
Contracts
ShippingInterface
interface ShippingInterface
{
public function getName(): string;
/** @return list<Quote> */
public function quote(QuoteRequest $request): array;
public function createShipment(BookingRequest $request): ShipmentInterface;
public function track(ShipmentId $id): ShipmentInterface;
public function cancel(ShipmentId $id): ShipmentInterface;
}
ShipmentInterface
interface ShipmentInterface
{
public function getId(): ShipmentId;
public function getProviderName(): string;
public function getTrackingCode(): string;
public function getStatus(): ShipmentStatus;
public function getOrigin(): Address;
public function getDestination(): Address;
public function getParcel(): Parcel;
public function getCost(): ?Amount;
/** @return list<TrackingEvent> */
public function getHistory(): array;
/** @return array<string, mixed> */
public function getExtra(): array;
public function withStatus(ShipmentStatus $status): static;
/** @param list<TrackingEvent> $history */
public function withHistory(array $history): static;
}
رابطهای قابلیت
interface SupportsLabel
{
public function getLabel(ShipmentId $id): LabelResponse;
}
interface SupportsPickup
{
public function schedulePickup(ShipmentId $id, PickupRequest $request): ShipmentInterface;
}
interface SupportsBranches
{
/** @return list<Branch> */
public function listBranches(?string $city = null): array;
}
interface SupportsCOD {} // marker interface
Money
Amount
final class Amount
{
public static function fromRials(int $rials): self;
public static function fromToman(int $toman): self;
public function inRials(): int;
public function inToman(): int;
public function add(self $other): self;
public function subtract(self $other): self;
public function equals(self $other): bool;
public function greaterThan(self $other): bool;
public function lessThan(self $other): bool;
public function isZero(): bool;
public function __toString(): string; // ریال
}
Address و Parcel
Address
final class Address
{
public readonly string $phone; // نرمالشده به +989xxxxxxxxx
public function __construct(
public readonly string $firstName,
public readonly string $lastName,
string $phone, // قالبهای 09xx، +98، 0098
public readonly string $province,
public readonly string $city,
public readonly string $addressLine,
public readonly ?string $postalCode = null, // ۱۰ رقم
public readonly ?string $plate = null,
public readonly ?string $unit = null,
public readonly ?float $lat = null,
public readonly ?float $lng = null,
public readonly ?string $email = null,
public readonly ?string $nationalId = null, // ۱۰ رقم
);
public function fullName(): string;
public function hasGeoCoordinates(): bool;
}
Parcel
final class Parcel
{
public function __construct(
public readonly int $weightGrams,
public readonly ?int $lengthMm = null,
public readonly ?int $widthMm = null,
public readonly ?int $heightMm = null,
public readonly ?Amount $declaredValue = null,
public readonly ?string $contentsDescription = null,
public readonly bool $fragile = false,
);
public function hasDimensions(): bool;
public function volumetricWeightGrams(): ?int;
public function chargeableWeightGrams(): int;
}
Shipment
final class Shipment implements ShipmentInterface { /* ر.ک. ShipmentInterface */ }
final class ShipmentId
{
public function __construct(string $value);
public function value(): string;
public function equals(self $other): bool;
public function __toString(): string;
}
enum ShipmentStatus: string
{
case Draft = 'draft';
case Quoted = 'quoted';
case Booked = 'booked';
case PickedUp = 'picked_up';
case InTransit = 'in_transit';
case OutForDelivery = 'out_for_delivery';
case Delivered = 'delivered';
case Failed = 'failed';
case Returned = 'returned';
case Cancelled = 'cancelled';
public function isTerminal(): bool;
public function label(string $locale = 'fa'): string;
}
Tracking
final class TrackingEvent
{
public function __construct(
public readonly \DateTimeImmutable $at,
public readonly ShipmentStatus $status,
public readonly string $description,
public readonly ?string $location = null,
public readonly array $raw = [],
);
}
Requests
final class QuoteRequest { /* origin, destination, parcel, serviceLevel, codAmount, extra */ }
final class Quote { /* providerName, serviceLevel, cost, etaDays, quoteId, extra */ }
final class BookingRequest {
public function withCashOnDelivery(Amount $amount): self;
public function hasCashOnDelivery(): bool;
}
final class PickupRequest { /* windowStart, windowEnd, instructions, extra */ }
final class LabelResponse { /* format, bytes, url */ }
Catalog
final class Branch { /* id, name, city, address, phone, lat, lng, openingHours */ }
enum ServiceLevel: string
{
case Standard = 'standard';
case Express = 'express';
case SameDay = 'same_day';
case Economy = 'economy';
public function label(string $locale = 'fa'): string;
}
HTTP
interface HttpClient
{
public function request(string $method, string $url, ?string $body = null, array $headers = []): HttpResponse;
public function postJson(string $url, string $body, array $headers = []): HttpResponse;
public function getJson(string $url, array $headers = []): HttpResponse;
public function deleteJson(string $url, array $headers = []): HttpResponse;
}
final class HttpResponse
{
public int $statusCode;
public string $body;
public array $headers;
public function header(string $name): ?string;
public function isSuccessful(): bool;
}
interface Logger
{
public function debug(string $message, array $context = []): void;
}
interface EventDispatcher
{
public function dispatch(object $event): object;
}
Events
| رویداد | فیلدها |
|---|---|
ShipmentQuoted | providerName، request، quotes |
ShipmentCreated | providerName، shipment |
ShipmentTracked | providerName، shipment |
ShipmentCancelled | providerName، shipment |
ShipmentFailed | providerName، operation، reason، errorCode |
Exceptions
| استثنا | ارث میبرد از | متدهای اضافه |
|---|---|---|
ErsalException | RuntimeException | — |
InvalidAddressException | ErsalException | — |
InvalidParcelException | ErsalException | — |
InvalidAmountException | ErsalException | — |
ConnectionException | ErsalException | — |
ProviderException | ErsalException | getProviderName()، getErrorCode() |
BookingException | ProviderException | (ارث) |
TrackingException | ProviderException | (ارث) |
CancellationException | ProviderException | (ارث) |
⁅مرجع کامل برای تما کلاس رابط و متد عمومی namespace eram ersal final class ersal public function construct httpclient httpclient null logger logger null eventdispatcher eventdispatcher null soapclientfactory soapfactory null public function create string provider object config shippinginterface return list string public static function available array interface shippinginterface public function getname string return list quote public function quote quoterequest request array public function createshipment bookingrequest request shipmentinterface public function track shipmentid id shipmentinterface public function cancel shipmentid id shipmentinterface interface shipmentinterface public function getid shipmentid public function getprovidername string public function gettrackingcode string public function getstatus shipmentstatus public function getorigin address public function getdestination address public function getparcel parcel public function getcost amount return list trackingevent public function gethistory array return array string mixed public function getextra array public function withstatus shipmentstatus status static param list trackingevent history public function withhistory array history static interface supportslabel public function getlabel shipmentid id labelresponse interface supportspickup public function schedulepickup shipmentid id pickuprequest request shipmentinterface interface supportsbranches return list branch public function listbranches string city null array interface supportscod marker interface final class amount public static function fromrials int rials self public static function fromtoman int toman self public function inrials int public function intoman int public function add self other self public function subtract self other self public function equals self other bool public function greaterthan self other bool public function lessthan self other bool public function iszero bool public function tostring string ریال final class address public readonly string phone نرمالشد نرمال شد به 989xxxxxxxxx public function construct public readonly string firstname public readonly string lastname string phone قالب 09xx 98 0098 public readonly string province public readonly string city public readonly string addressline public readonly string postalcode null 10 رقم public readonly string plate null public readonly string unit null public readonly float lat null public readonly float lng null public readonly string email null public readonly string nationalid null 10 رقم public function fullname string public function hasgeocoordinates bool final class parcel public function construct public readonly int weightgrams public readonly int lengthmm null public readonly int widthmm null public readonly int heightmm null public readonly amount declaredvalue null public readonly string contentsdescription null public readonly bool fragile false public function hasdimensions bool public function volumetricweightgrams int public function chargeableweightgrams int final class shipment implements shipmentinterface ر ک shipmentinterface final class shipmentid public function construct string value public function value string public function equals self other bool public function tostring string enum shipmentstatus string case draft draft case quoted quoted case booked booked case pickedup picked up case intransit in transit case outfordelivery out for delivery case delivered delivered case failed failed case returned returned case cancelled cancelled public function isterminal bool public function label string locale fa string final class trackingevent public function construct public readonly datetimeimmutable at public readonly shipmentstatus status public readonly string description public readonly string location null public readonly array raw final class quoterequest origin destination parcel servicelevel codamount extra final class quote providername servicelevel cost etadays quoteid extra final class bookingrequest public function withcashondelivery amount amount self public function hascashondelivery bool final class pickuprequest windowstart windowend instructions extra final class labelresponse format bytes url final class branch id name city address phone lat lng openinghours enum servicelevel string case standard standard case express express case sameday same day case economy economy public function label string locale fa string interface httpclient public function request string method string url string body null array headers httpresponse public function postjson string url string body array headers httpresponse public function getjson string url array headers httpresponse public function deletejson string url array headers httpresponse final class httpresponse public int statuscode public string body public array headers public function header string name string public function issuccessful bool interface logger public function debug string message array context void interface eventdispatcher public function dispatch object event object رویداد فیلد shipmentquoted providername request quotes shipmentcreated providername shipment shipmenttracked providername shipment shipmentcancelled providername shipment shipmentfailed providername operation reason errorcode استثنا ارث برد از متد اضافه ersalexception runtimeexception invalidaddressexception ersalexception invalidparcelexception ersalexception invalidamountexception ersalexception connectionexception ersalexception providerexception ersalexception getprovidername geterrorcode bookingexception providerexception ارث trackingexception providerexception ارث cancellationexception providerexception ارث⁆
⁅مرجع api⁆
⁅ersal نقطه ورود contractsmoneyaddress و parcelshipmenttrackingrequestscataloghttpeventsexceptions⁆
⁅shippinginterfaceshipmentinterfaceرابط قابلیتamountaddressparcel⁆