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

Public Member Functions

 __construct ()
 getAfter ()
 getBefore ()
 _getSourceJson ()
 add ($thing)
 count ()
 getIterator ()
 toJson ()
 fromJson (string $json)
- Public Member Functions inherited from snuze\SnuzeObject
 __construct (array $args=null)
 _getSnuzeId ()
 _getSnuzeClass ()
 _ident ()

Protected Attributes

 $children = []
 $_sourceJson = ''
- Protected Attributes inherited from snuze\SnuzeObject
 $_snuzeId = null
 $_snuzeClass = null

Private Attributes

 $after = null
 $before = null
 $modhash = null

Additional Inherited Members

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

Detailed Description

A Listing represents a collection of Thing objects returned from the Reddit API in response to some request. It implements \IteratorAggregate and \Countable, so foreach() and count() can both be used directly on a Listing object.

A generic Listing can hold a heterogeneous mixture of all kinds of Things: Subreddits, Accounts, Comments, Messages, etc. For more strict collections, use a subtype: SubredditListing, LinkListing, CommentListing, etc.

This file is part of Snuze, a PHP client for the Reddit API. Copyright 2019 Shaun Cummiskey Repository: Documentation:

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

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.

Constructor & Destructor Documentation

◆ __construct()

snuze\Reddit\Listing\Listing::__construct ( )


Member Function Documentation

◆ _getSourceJson()

snuze\Reddit\Listing\Listing::_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!

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

◆ add()

snuze\Reddit\Listing\Listing::add (   $thing)

Add a Thing to the collection. Accurate type hinting of the argument isn't possible yet, so it must be tested manually.

\snuze\Reddit\Thing\Thing$thingA Thing object to add to the collection

◆ count()

snuze\Reddit\Listing\Listing::count ( )

Implement the \Countable interface. This allows count() to be called on Listing objects


◆ fromJson()

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

Given the raw JSON response to any API request that returns a listing, attempt to create a Listing object whose $children array is full of Thing descendants.

string$jsonThe raw JSON response from Reddit's API server

Implements snuze\Interfaces\Jsonable.

References snuze\Reddit\Listing\Listing\add(), snuze\Reddit\Thing\Thing\KIND_ACCOUNT, snuze\Reddit\Thing\Thing\KIND_AWARD, snuze\Reddit\Thing\Thing\KIND_COMMENT, snuze\Reddit\Thing\Thing\KIND_LINK, snuze\Reddit\Thing\Thing\KIND_MESSAGE, and snuze\Reddit\Thing\Thing\KIND_SUBREDDIT.

◆ getAfter()

snuze\Reddit\Listing\Listing::getAfter ( )

Get this listing's "after" specifier, if any. If a value is returned, it corresponds to the fullname of the last entity in the collection, and can be used for forward pagination.


◆ getBefore()

snuze\Reddit\Listing\Listing::getBefore ( )

Get this listing's "before" specifier, if any. If a value is returned, it corresponds to the fullname of the first entity in the collection, and can be used for reverse pagination.


◆ getIterator()

snuze\Reddit\Listing\Listing::getIterator ( )

Implement the \IteratorAggregate interface. This allows foreach() to be used productively on Listing objects


◆ toJson()

snuze\Reddit\Listing\Listing::toJson ( )

This method should return a JSON-formatted string that represents an array of the object's significant properties.

string A string containing well-formed JSON

Implements snuze\Interfaces\Jsonable.

References snuze\Reddit\Listing\Listing\count().

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