instance() public static method

- static, for singleton, for creating a global instance of this object
public static instance ( ) : -
return -
Example #1
0
 /**
  * method instance.
  * 	- static, for singleton, for creating a global instance of this object
  *
  * @return - PDOWrapper Object
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new PDOWrapper();
     }
     return self::$instance;
 }
Example #2
0
File: handler.php Project: Zbee/api
<?php

#Specifying that the return is JSON
header('Content-Type: application/json');
#Include passwords and keys
require '_secret_keys.php';
#Include functions
require 'libs/functions.php';
#Include database abstraction
require 'vendor/mikehenrty/thin-pdo-wrapper/src/PDOWrapper.php';
#Set up database abstraction
$pdo = PDOWrapper::instance();
$pdo->configMaster($db[0], $db[1], $db[2], $db[3]);
#setup in _secret_keys.php
#Require a key (private endpoints)
function requireKey()
{
    global $argumentsU;
    global $arguments;
    global $pdo;
    if (!array_key_exists("key", $arguments)) {
        throw new Exception('Key required to access this private endpoint (arguments: ' . $argumentsU . ')');
    }
    if (strlen($arguments["key"]) != 20) {
        throw new Exception('Key provided is of an incorrect length (' . $arguments["key"] . ' (' . strlen($arguments["key"]) . '))');
    }
}
#Require initial data
function requirePost($fields)
{
    foreach ($fields as $field => $type) {
 /**
  * Constructor.
  * Note:
  *   This function is set to private in order to prevent others from calling this function. Only this class itself can call this function.
  *   You can find an other example(in Japanese) at http://d.hatena.ne.jp/ja9/20090515/1242374821
  *
  * @param String $dsn      dsn string to connect database
  * @param String $username username to connect
  * @param String $password password to connect
  */
 private function __construct($dsn, $username, $password)
 {
     self::$instance = new PDO($dsn, $username, $password);
 }