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

Public Member Functions

 __construct (array $configurationParameters=[])
 
 init ()
 
 getPdo ()
 
- Public Member Functions inherited from snuze\Persistence\AbstractStorageProvider
 getMapper (string $objectClass)
 
 getRequiredExtensionNames ()
 
 init ()
 
- Public Member Functions inherited from snuze\SnuzeObject
 __construct (array $args=null)
 
 _getSnuzeId ()
 
 _getSnuzeClass ()
 
 _ident ()
 

Public Attributes

const REQUIRED_EXTS = ['pdo_mysql']
 
const SCHEMA_DIR = __DIR__ . '/schema'
 
const SCHEMA_VERSION = 1000801
 

Private Member Functions

 validateSchema ()
 

Private Attributes

 $server = null
 
 $username = null
 
 $password = null
 
 $database = null
 
 $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
 
- Static Protected Attributes inherited from snuze\Persistence\AbstractStorageProvider
static $mappers = []
 

Detailed Description

This is the MySQL storage provider class. It provides the functionality required for Snuze to talk to a MySQL database via PDO.

If you want to develop your own Snuze storage provider, looking here is a good place to start. Your storage provider needs to:

  • Extend AbstractStorageProvider
  • Implement StorageProviderInterface and its methods
  • Establish communication with, write to, and read from the storage facility

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\StorageProvider::__construct ( array  $configurationParameters = [])

Creates a new MySQL\StorageProvider object.

You must pass an array with four elements whose keys are 'server', 'username', 'password', and 'database', and whose values will be used to establish a PDO connection to MySQL.

Parameters
string[]$configurationParameters An array with elements named 'server', 'username', 'password', and 'database'
Exceptions

Implements snuze\Persistence\Interfaces\StorageProviderInterface.

Member Function Documentation

◆ getPdo()

snuze\Persistence\MySQL\StorageProvider::getPdo ( )

Get the PDO object

Returns
\PDO

◆ init()

snuze\Persistence\MySQL\StorageProvider::init ( )

Open a PDO handle to the database and test for the expected schema version. If the schema is outdated or doesn't exist yet, the user is prompted to run the included utility script, which will install or upgrade the schema as needed.

Returns
void
Exceptions

Implements snuze\Persistence\Interfaces\StorageProviderInterface.

References snuze\Persistence\MySQL\StorageProvider\validateSchema().

◆ validateSchema()

snuze\Persistence\MySQL\StorageProvider::validateSchema ( )
private

Called by init().

Test for the presence of the "snuze" table in the database, and that its "schema_version" field matches self::SCHEMA_VERSION. If this fails, ask the user to go run the utility script to either install or upgrade the database schema.

This is specific to the MySQL storage provider. If implementing your own storage provider, you're welcome to mirror this design, but it's not a required feature of a Snuze storage provider in general.

Returns
bool

References snuze\Persistence\MySQL\StorageProvider\SCHEMA_VERSION.

Member Data Documentation

◆ REQUIRED_EXTS

const snuze\Persistence\MySQL\StorageProvider::REQUIRED_EXTS = ['pdo_mysql']

PHP extensions required by this storage provider

◆ SCHEMA_DIR

const snuze\Persistence\MySQL\StorageProvider::SCHEMA_DIR = __DIR__ . '/schema'

The directory containing .sql DDL files that define the base MySQL schema and the inter-version patches.

This is specific to the MySQL storage provider. If implementing your own storage provider, you're welcome to mirror this design, but it's not a required feature of a Snuze storage provider in general.

◆ SCHEMA_VERSION

const snuze\Persistence\MySQL\StorageProvider::SCHEMA_VERSION = 1000801

The schema version number that this version of the MySQL storage provider expects to be working with. This will always be the build number of Snuze when schema changes were last made.

This is specific to the MySQL storage provider. If implementing your own storage provider, you're welcome to mirror this design, but it's not a required feature of a Snuze storage provider in general.


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