YouTubePHP Documentation

Factory
in package

FinalYes

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
since
1.0.0
author

Valithor Obsidion valithor@valgorithms.com

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

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

part()

Builds one part.

public part(T> $class[, array<string, mixed> $attributes = [] ]) : T
Parameters
$class : T>
$attributes : array<string, mixed> = []
Tags
template
throws
PartException

When the class is not a part.

Return values
T

partClassFor()

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>|null

standalone()

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
Return values
self
On this page

Search results