Factory
in package
Builds {@see Part}s from raw API payloads.
The unit of work is a type token: a schema name from the discovery document
("LiveChatMessage"), a list of one ("Array of Thumbnail"), or a map keyed
by string ("Map of VideoLocalization", which is how localizations arrive).
Generated parts declare tokens in $casts and generated API methods declare
one as their result, so one hydrator covers nested objects and call results
alike.
Tags
Table of Contents
Constants
- PART_NAMESPACE : mixed = 'YouTube\Parts\\'
- Where generated parts live.
- LIST_PREFIX : mixed = 'Array of '
- MAP_PREFIX : mixed = 'Map of '
Properties
- $standalone : ?self
- $youtube : ?YouTube
Methods
- __construct() : mixed
- create() : mixed
- Hydrates a value according to its type token.
- getYouTube() : ?YouTube
- part() : T
- Builds one part.
- partClassFor() : Part>|null
- The part class a schema name maps to, or null when it names none.
- standalone() : self
- A factory with no client behind it, for parts built on their own - from a stored payload, say, or in a test.
Constants
PART_NAMESPACE
Where generated parts live.
public
mixed
PART_NAMESPACE
= 'YouTube\Parts\\'
LIST_PREFIX
private
mixed
LIST_PREFIX
= 'Array of '
MAP_PREFIX
private
mixed
MAP_PREFIX
= 'Map of '
Properties
$standalone
private
static ?self
$standalone
= null
$youtube read-only
private
?YouTube
$youtube
= null
Methods
__construct()
public
__construct([?YouTube $youtube = null ]) : mixed
Parameters
- $youtube : ?YouTube = null
create()
Hydrates a value according to its type token.
public
create(string $token, mixed $value) : mixed
Scalars pass through untouched, Array of X becomes a Collection
of parts (or a plain list, for scalars), Map of X keeps its keys and
hydrates its values, and a schema name becomes the matching part.
Parameters
- $token : string
- $value : mixed
getYouTube()
public
getYouTube() : ?YouTube
Return values
?YouTubepart()
Builds one part.
public
part(T> $class[, array<string, mixed> $attributes = [] ]) : T
Parameters
- $class : T>
- $attributes : array<string, mixed> = []
Tags
Return values
TpartClassFor()
The part class a schema name maps to, or null when it names none.
public
partClassFor(string $type) : Part>|null
Parameters
- $type : string
Return values
Part>|nullstandalone()
A factory with no client behind it, for parts built on their own - from a stored payload, say, or in a test.
public
static standalone() : self