Snuze  0.8.1
snuze\Reddit\Thing\Thing Class Reference
Inheritance diagram for snuze\Reddit\Thing\Thing:

Public Member Functions

 __construct (string $kind)
 
 _getSourceJson ()
 
 getId ()
 
 getKind ()
 
 getCreated ()
 
 getCreatedUtc ()
 
 getFullname ()
 
 toJson ()
 
 fromJson (string $json)
 
- Public Member Functions inherited from snuze\SnuzeObject
 __construct (array $args=null)
 
 _getSnuzeId ()
 
 _getSnuzeClass ()
 
 _ident ()
 

Static Public Member Functions

static getValidKinds ()
 

Public Attributes

const KIND_COMMENT = 't1'
 
const KIND_ACCOUNT = 't2'
 
const KIND_LINK = 't3'
 
const KIND_MESSAGE = 't4'
 
const KIND_SUBREDDIT = 't5'
 
const KIND_AWARD = 't6'
 
const REGEX_VALID_ID = '|^[a-z0-9]{1,13}$|i'
 

Protected Member Functions

 setId (string $id)
 
 setKind (string $kind)
 
 setCreated (float $created)
 
 setCreatedUtc (float $createdUtc)
 
 getPropertyTranslationMap ()
 
- Protected Member Functions inherited from snuze\SnuzeObject
 debug (string $message, bool $echo=false)
 
 info (string $message, bool $echo=false)
 
 warning (string $message, bool $echo=false)
 
 error (string $message, bool $echo=false)
 

Protected Attributes

 $_kind = null
 
 $_propertyNames = []
 
 $_propertyTranslationRegex = '|([a-z])([A-Z0-9])|'
 
 $_sourceJson = ''
 
 $id = null
 
 $created = 0.0
 
 $createdUtc = 0.0
 
- Protected Attributes inherited from snuze\SnuzeObject
 $_snuzeId = null
 
 $_snuzeClass = null
 

Detailed Description

The Thing class represents the common properties of all Reddit "things." Various subtypes of Thing exist to define the properties specific to those objects.

You can't instantiate a generic Thing object; instead, you should create and use the various subtypes: Subreddit, Link, Account, Comment, etc.


This file is part of Snuze, a PHP client for the Reddit API. Copyright 2019 Shaun Cummiskey shaun.nosp@m.@sha.nosp@m.unc.c.nosp@m.om https://shaunc.com/ Repository: https://github.com/snuze/snuze/ Documentation: https://snuze.shaunc.com/

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Member Function Documentation

◆ _getSourceJson()

snuze\Reddit\Thing\Thing::_getSourceJson ( )

Get the original JSON used to create this object via fromJson(), if applicable. This is intended for use by the test suite. You probably want toJson() instead!

Returns
string If this object was created using fromJson(), the original JSON provided; otherwise, an empty string

◆ fromJson()

snuze\Reddit\Thing\Thing::fromJson ( string  $json)

Accepts a JSON-formatted string, uses it to build a Thing object, and returns that object. This satisfies a promise made in the Jsonable interface.

Parameters
string$json
Returns
Some subtype of \snuze\Reddit\Thing\Thing
See also
\snuze\Interfaces\Jsonable

Implements snuze\Interfaces\Jsonable.

References snuze\Reddit\Thing\Thing\getPropertyTranslationMap().

◆ getCreated()

snuze\Reddit\Thing\Thing::getCreated ( )

Get the epoch time this Thing was created. Reddit provides this as a float value, but the fractional part is always zero.

Returns
float A unix epoch timestamp as a float

◆ getCreatedUtc()

snuze\Reddit\Thing\Thing::getCreatedUtc ( )

Get the UTC epoch time this Thing was created. Reddit provides this as a float value, but the fractional part is always zero.

Returns
float A unix epoch timestamp as a float

◆ getFullname()

snuze\Reddit\Thing\Thing::getFullname ( )

Get the Reddit fullname for this object. A fullname is comprised of the Thing's kind, an underscore, and the Thing's ID, e.g. "t2_bva6"

Returns
string The Reddit fullname for this object
Exceptions

◆ getId()

snuze\Reddit\Thing\Thing::getId ( )

Get the Reddit internal identifier for this object.

Returns
string|null The Reddit internal identifier for this object

◆ getPropertyTranslationMap()

snuze\Reddit\Thing\Thing::getPropertyTranslationMap ( )
protected

Return an array whose keys are the class's camelCase property names, and whose values are the corresponding under_score names from Reddit's JSON. This map is used by the toJson() and fromJson() methods. This is mildly more convenient than manually mapping property names in each child class.

All Thing children must set their own $this->_propertyNames variable in their constructor.

Returns
array An array of property names as described above
Exceptions

◆ getValidKinds()

static snuze\Reddit\Thing\Thing::getValidKinds ( )
static

Get an array of supported Thing kinds.

Returns
array Thing's KIND_ constants and their values

◆ setCreated()

snuze\Reddit\Thing\Thing::setCreated ( float  $created)
protected

Set the epoch time this Thing was created. Reddit provides this as a float value, but the fractional part is always zero.

Parameters
float$createdA unix epoch timestamp as a float
Returns
$this This Thing object

◆ setCreatedUtc()

snuze\Reddit\Thing\Thing::setCreatedUtc ( float  $createdUtc)
protected

Set the UTC epoch time this Thing was created. Reddit provides this as a float value, but the fractional part is always zero.

Parameters
float$createdUtcA unix epoch timestamp as a float
Returns
$this This Thing object

◆ setId()

snuze\Reddit\Thing\Thing::setId ( string  $id)
protected

Set the Reddit internal identifier for this object.

Parameters
string$id
Returns
$this This Thing object

◆ toJson()

snuze\Reddit\Thing\Thing::toJson ( )

Returns a JSON-formatted string representing this Thing's properties. Ideally, this should match Reddit's own data structure for returning "things" from the API.

Returns
string

Implements snuze\Interfaces\Jsonable.

References snuze\Reddit\Thing\Thing\getPropertyTranslationMap().

Member Data Documentation

◆ KIND_ACCOUNT

const snuze\Reddit\Thing\Thing::KIND_ACCOUNT = 't2'

Defines the kind discriminator for an account

◆ KIND_AWARD

const snuze\Reddit\Thing\Thing::KIND_AWARD = 't6'

Defines the kind discriminator for an award

◆ KIND_COMMENT

const snuze\Reddit\Thing\Thing::KIND_COMMENT = 't1'

Defines the kind discriminator for a comment

◆ KIND_LINK

const snuze\Reddit\Thing\Thing::KIND_LINK = 't3'

Defines the kind discriminator for a link (story, submission)

◆ KIND_MESSAGE

const snuze\Reddit\Thing\Thing::KIND_MESSAGE = 't4'

Defines the kind discriminator for a message (direct message, modmail)

◆ KIND_SUBREDDIT

const snuze\Reddit\Thing\Thing::KIND_SUBREDDIT = 't5'

Defines the kind discriminator for a subreddit

◆ REGEX_VALID_ID

const snuze\Reddit\Thing\Thing::REGEX_VALID_ID = '|^[a-z0-9]{1,13}$|i'

Defines a valid Thing ID. This is the base36 ID only, without the t1, t2, t3, etc. "kind" prefix.


The documentation for this class was generated from the following file: