Example #1
0
/**
 * Load PHP Files When Autoloader Doesn't Exist
 * 
 * The following uses the patterns namespace to instantiate a registry object
 * and then check that registry object for the standard Falcraft AutoLoader
 * singleton, defined standard in the Loader/Bootstrap.php.  These results are
 * cached, but can be refreshed later.  If there is no loader we include
 * the files passed to the function.
 * 
 * @param array $libraries files to load relative to this file
 * @param string $context the context of the file including
 * @param mixed $refresh refresh the loader contents with another value
 * 
 */
function falcraftLoad(array $libraries, $context = 'global', $refresh = false)
{
    static $falcraftRegistry, $falcraftLoader;
    if (!$falcraftRegistry) {
        // Access global registry
        $falcraftRegistry = Patterns\Registry::instantiate();
        $falcraftLoader = $falcraftRegistry->get('Falcraft\\Singletons\\Autoloader');
    }
    if ($refresh) {
        $falcrafLoader = $refresh;
    }
    if ($falcraftLoader instanceof Types\Null) {
        foreach ($libraries as $include) {
            if (realpath(__DIR__ . str_replace('/', DIRECTORY_SEPARATOR, $include)) === false) {
                throw new \RuntimeException("falcraftLoad - {$context}: include {$include} not found");
            }
            require_once realpath(__DIR__ . str_replace('/', DIRECTORY_SEPARATOR, $include));
        }
    }
}
Example #2
0
 /**
  * Initialize the registry
  * 
  * Inserts a copy of the array into the registry singleton under
  * 'Falcraft\TaggedUnion\Restrictions
  * 
  * Note: static::registry has already been defined as array() in definition
  * 
  * @static
  * 
  */
 private static function initRegistry()
 {
     $registry = Patterns\Registry::instantiate();
     $registry->setReference('Falcraft\\TaggedUnion\\Restrictions', self::$registry);
 }
Example #3
0
    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);