Snuze  0.8.1
snuze\Persistence\MySQL\SubredditMapper Class Reference
Inheritance diagram for snuze\Persistence\MySQL\SubredditMapper:

Public Member Functions

 __construct (StorageProviderInterface $storage)
 
 persist ($subreddit)
 
 retrieve ($displayName)
 
 delete ($object)
 
 retrieveById (string $id)
 
- Public Member Functions inherited from snuze\SnuzeObject
 __construct (array $args=null)
 
 _getSnuzeId ()
 
 _getSnuzeClass ()
 
 _ident ()
 

Private Attributes

 $pdo = 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)
 
- Protected Attributes inherited from snuze\SnuzeObject
 $_snuzeId = null
 
 $_snuzeClass = null
 

Detailed Description

A data mapper class for Subreddit objects using the MySQL StorageProvider.

This is where abstraction goes to die.


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.

Constructor & Destructor Documentation

◆ __construct()

snuze\Persistence\MySQL\SubredditMapper::__construct ( StorageProviderInterface  $storage)
Parameters
\snuze\Persistence\MySQL\StorageProvider$storageA MySQL StorageProvider object
Exceptions

Implements snuze\Persistence\Interfaces\MapperInterface.

Member Function Documentation

◆ delete()

snuze\Persistence\MySQL\SubredditMapper::delete (   $object)

Delete a Subreddit from the database.

Parameters
\snuze\Reddit\Thing\Subreddit$objectThe Subreddit to delete
Returns
bool True on success; otherwise, an exception is thrown
Exceptions

Implements snuze\Persistence\Interfaces\MapperInterface.

◆ persist()

snuze\Persistence\MySQL\SubredditMapper::persist (   $subreddit)

Insert or update a Subreddit to the MySQL database.

Parameters
\snuze\Reddit\Thing\Subreddit$subredditThe Subreddit to persist
Returns
bool True on success; otherwise, an exception is thrown
Exceptions

Implements snuze\Persistence\Interfaces\MapperInterface.

◆ retrieve()

snuze\Persistence\MySQL\SubredditMapper::retrieve (   $displayName)

Get a Subreddit from the database by its display name.

Parameters
string$displayNameThe display name (e.g. "recipes") of the Subreddit to retrieve
Returns
\snuze\Reddit\Thing\Subreddit|null

Boolean fields are stored as BIT (0 or 1) in the database. Snuze expects booleans, and uses strict typing. Here the 0s and 1s are massaged back to boolean values.

Array fields are stored in the database as JSON-encoded strings. Here they're massaged back into arrays so json_encode() (below) doesn't double-encode them.

Reddit provides epoch timestamps as floats. They're stored in the database as integers. Here they're massaged back into floats.

Implements snuze\Persistence\Interfaces\SubredditMapperInterface.

◆ retrieveById()

snuze\Persistence\MySQL\SubredditMapper::retrieveById ( string  $id)

Get a Subreddit from the database by its Reddit internal ID. This incurs an extra query penalty, as it first looks up the corresponding display name and then calls retrieve() to do the heavy lifting.

Parameters
string$idThe Reddit internal ID (e.g. "2qh56") of the Subreddit to retrieve
Returns
\snuze\Reddit\Thing\Subreddit|null
Exceptions

Implements snuze\Persistence\Interfaces\SubredditMapperInterface.

References snuze\Persistence\MySQL\SubredditMapper\retrieve().


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