PHP Classes

File: Falcraft/examples/Patterns/Registry.php

Recommend this page to a friend!
  Classes of Asher Wolfstein   PHP Registry with Singleton Trait   Falcraft/examples/Patterns/Registry.php   Download  
File: Falcraft/examples/Patterns/Registry.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: PHP Registry with Singleton Trait
Set and get registry values using singleton trait
Author: By
Last change:
Date: 9 years ago
Size: 1,112 bytes
 

Contents

Class file image Download
<?php

require_once('../../Patterns/Registry.php');

use
Falcraft\Patterns;

echo
"Falcraft\\Patterns\\Registry.php Test\n";
echo
"-----------------------------------\n\n";

echo
"Instantiating Singleton -> ";

$success = true;

$testRegistryInstance = null;

try {
   
$testRegistryInstance = Patterns\Registry::instantiate();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Add Registry Slot: exampleKey => exampleValue -> ";

$success = true;

try {
   
$testRegistryInstance->set('exampleKey', 'exampleValue');
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
} else {
    echo
"Failure...\n\n";
}

var_dump($testRegistryInstance);

echo
"Instantiate Again Into Alternate Local Variable -> ";

$success = true;

$testRegistryInstanceTwo = null;

try {
   
$testRegistryInstanceTwo = Patterns\Registry::instantiate();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

var_dump($testRegistryInstanceTwo);