Skip to content

PassFields

Raxos\Wallet\Apple\Component\PassFields is the abstract base class shared by the five pass style containers. It holds the field arrays that appear on a pass.

php
abstract readonly class PassFields implements ComponentInterface

Implements Raxos\Contract\Wallet\ComponentInterface (see raxos/contract).

Constructor

ParameterTypeDescription
primaryFieldsPrimaryField[]|nullThe prominent fields.
secondaryFieldsSecondaryField[]|nullFields below the primary ones.
additionalInfoFieldsAdditionalInfoField[]|nullExtra informational fields.
auxiliaryFieldsAuxiliaryField[]|nullAuxiliary fields.
backFieldsBackField[]|nullFields on the back of the pass.
headerFieldsHeaderField[]|nullFields shown in the header.

Methods

jsonSerialize(): array

Returns the field arrays, filtering out any that are null or empty.

Subclasses

Generic, StoreCard, Coupon and EventTicket are empty final classes that extend PassFields and add no behavior. They name the style slot on a Pass.

BoardingPass extends PassFields and adds a required TransitType property, merging it into jsonSerialize(). Its constructor takes a single field instance per slot instead of an array.

php
<?php
declare(strict_types=1);

use Raxos\Wallet\Apple\Component\{BoardingPass, PrimaryField};
use Raxos\Wallet\Apple\Enum\TransitType;

$boardingPass = new BoardingPass(
    transitType: TransitType::TRAIN,
    primaryFields: new PrimaryField(key: 'from', value: 'Amsterdam', label: 'From')
);

Example

php
<?php
declare(strict_types=1);

use Raxos\Wallet\Apple\Component\{EventTicket, PrimaryField, SecondaryField};

$eventTicket = new EventTicket(
    primaryFields: [
        new PrimaryField(key: 'event', value: 'Summer Nights', label: 'Event')
    ],
    secondaryFields: [
        new SecondaryField(key: 'seat', value: 'Row 4', label: 'Seat')
    ]
);

See also