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

Public Member Functions

 __construct (StorageProviderInterface $storage)
 
 persist ($account)
 
 retrieve ($username)
 
 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 Account subtype 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\AccountMapper::__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\AccountMapper::delete (   $object)

Delete an account from the database.

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

Implements snuze\Persistence\Interfaces\MapperInterface.

◆ persist()

snuze\Persistence\MySQL\AccountMapper::persist (   $account)

Insert or update an Account subtype to the MySQL database.

If a MyAccount object is supplied, only the properties associated with a UserAccount are persisted; attributes that are specific to MyAccount won't be stored.

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

Implements snuze\Persistence\Interfaces\MapperInterface.

◆ retrieve()

snuze\Persistence\MySQL\AccountMapper::retrieve (   $username)

Get an account from the database by its username.

Parameters
string$usernameThe username of the account to retrieve
Returns
\snuze\Reddit\Thing\Account\UserAccount|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\AccountMapperInterface.

◆ retrieveById()

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

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

Parameters
string$idThe Reddit internal ID (e.g. "bva2") of the account to retrieve
Returns
\snuze\Reddit\Thing\Account\UserAccount|null
Exceptions

Implements snuze\Persistence\Interfaces\AccountMapperInterface.

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


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