Oihana PHP System

SetContactPointTrait

Injects the contact points of an entity from flat property expressions.

The consumer class must declare a contactPoint property. Each flat key, e.g. default_telephone, mobile or home_email, is routed to the ContactPoint of the matching ContactType, created or updated on demand.

Tags
author

Marc Alcaraz (eKameleon)

since
1.3.0

Table of Contents

Methods

contactPointList()  : array<string|int, mixed>
The contact points as a list, whatever shape the property holds.
findContactPointByType()  : ContactPoint|null
Find a specific ContactPoint reference by type.
isValidPhoneNumber()  : bool
Validate a phone number expression (basic check, any country).
setContactPointProperty()  : bool
Internal method to inject custom properties in the PostalAddress property of the place.

Methods

contactPointList()

The contact points as a list, whatever shape the property holds.

protected contactPointList() : array<string|int, mixed>

contactPoint is declared as null|ContactPoint|array|string wherever this trait is composed, but the code around it only ever makes sense on a list. A lone ContactPoint and an unresolved string reference are therefore wrapped rather than discarded — nothing is lost, and the caller can iterate and append without checking first.

Return values
array<string|int, mixed> —

The contact points, always a list.

findContactPointByType()

Find a specific ContactPoint reference by type.

protected findContactPointByType(string|null $type) : ContactPoint|null

Entries that are not hydrated ContactPoint instances — the raw arrays a base read hands back, or an unresolved reference — are skipped rather than dereferenced, so only a real instance is ever returned.

Parameters
$type : string|null

The type of the resource to find.

Return values
ContactPoint|null

isValidPhoneNumber()

Validate a phone number expression (basic check, any country).

protected isValidPhoneNumber(string $phone[, string|null $defaultRegion = 'FR' ]) : bool
Parameters
$phone : string

The phone number to validate.

$defaultRegion : string|null = 'FR'

region that we are expecting the number to be from. This is only used if the number being parsed is not written in international format. The country_code for the number in this case would be stored as that of the default region supplied. If the number is guaranteed to start with a '+' followed by the country calling code, then "ZZ" or null can be supplied.

Return values
bool —

True if valid, false otherwise.

setContactPointProperty()

Internal method to inject custom properties in the PostalAddress property of the place.

protected setContactPointProperty(string $name, mixed $value) : bool
Parameters
$name : string

The name of the property to transform.

$value : mixed

The value of the property.

Return values
bool
On this page

Search results