PHP Classes

File: Falcraft/tests/Loader/Module.php

Recommend this page to a friend!
  Classes of Asher Wolfstein   Flexible AutoLoader   Falcraft/tests/Loader/Module.php   Download  
File: Falcraft/tests/Loader/Module.php
Role: Example script
Content type: text/plain
Description: Module Test Script
Class: Flexible AutoLoader
Autoloader that supports PSR-0 and other methods
Author: By
Last change:
Date: 8 years ago
Size: 4,597 bytes
 

Contents

Class file image Download
<?php

require_once('../../Loader/Module.php');

use
Falcraft\Loader;
use
Falcraft\Components\File;

echo
"Falcraft\\Data\\Loader\\Module.php Test\n";
echo
"--------------------------------------\n\n";

echo
"Basic Instantiation -- \n";

echo
" Instantiation (path1, firstModule) -> ";

$success = true;

$top = $path1 = null;

try {
   
$path1 = 'first/module/path';
   
$top = new Loader\Module($path1, 'firstModule');
} catch (\
Exception $e) {
   
$success = false;
}

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

echo
"Additional Instantiation -- \n";

$success = true;

$child1 = $child2 = $child3 = null;

$path2 = $path3 = $path4 = null;

try {
    echo
" Instantiate Paths (2, 3, 4) -> ";
   
$path2 = 'second/module/path';
   
$path3 = 'third/module/path';
   
$path4 = 'fourth/module/path';
    echo
"Success!\n";
   
    echo
" Instantiation (path2, subModule1) -> ";
   
$child1 = new Loader\Module($path2, 'subModule1');
    echo
"Success!\n";
   
    echo
" Instantiation (path3, subModule2) -> ";
   
$child2 = new Loader\Module($path3, 'subModule2');
    echo
"Success!\n";
   
    echo
" Instantiation (path4, subModule3) -> ";
   
$child3 = new Loader\Module($path4, 'subModule3');
    echo
"Success!\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (!
$success) {
    echo
"EXCEPTION RAISED\n\n";
}

echo
"\nBasic Operations -- \n";

echo
" Add subModule1 to firstModule -> ";

$success = true;

try {
   
$top->addModule($child1, $child1->getIdentifier());
} catch (\
Exception $e) {
   
$success = false;
}

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

$paths = Loader\Module::getModuleIdentityPaths($top);

echo
"Identity Paths: \n";
foreach (
$paths as $path) {
    echo
" $path\n";
}

echo
"\n Add subModule3 to subModule1 -> ";

$success = true;

try {
   
$child1->addModule($child3, $child3->getIdentifier());
} catch (\
Exception $e) {
   
$success = false;
}

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

$paths = Loader\Module::getModuleIdentityPaths($top);

echo
"Identity Paths: \n";
foreach (
$paths as $path) {
    echo
" $path\n";
}

echo
"\n Add subModule2 to firstModule -> ";

$success = true;

try {
   
$top->addModule($child2, $child2->getIdentifier());
} catch (\
Exception $e) {
   
$success = false;
}

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

$paths = Loader\Module::getModuleIdentityPaths($top);

echo
"Identity Paths: \n";
foreach (
$paths as $path) {
    echo
" $path\n";
}

echo
" Retrieve As Array (root firstModule) -> ";

$success = true;

$folders = null;

try {
   
$folders = Loader\Module::getAsArray($top);
} catch (\
Exception $e) {
   
$success = false;
}

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

var_dump($folders);

echo
"\n Retrieve Using Data (path2) -> ";

$success = true;

$ret = null;

try {
   
$ret = Loader\Module::pathBelongsTo($path2, $top);
} catch (\
Exception $e) {
   
$success = false;
}

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

echo
" Retrieve Using Data (path3) -> ";

$success = true;

$ret = null;

try {
   
$ret = Loader\Module::pathBelongsTo($path3, $top);
} catch (\
Exception $e) {
   
$success = false;
}

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

echo
" Get From Path (firstModule/subModule2) -> ";

$success = true;

unset(
$ret);
$ret = null;

try {
   
$ret = Loader\Module::getFromModuleIdentityPath($top, 'firstModule/subModule2');
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success! Identifier: {$ret->getIdentifier()}\n";
} else {
    echo
"Failure...\n";
}

unset(
$ret);

echo
" Add To Module Identity Path (path5, subModule4) -- \n";

$success = true;

$granchild2 = null;

try {
    echo
" Instantiate subModule4 -> ";
   
$grandchild2 = new Loader\Module('path/to/last/module', 'subModule4');
    echo
"Success!\n";
   
    echo
" Add to Path (firstModule/subModule2) -> ";
   
Loader\Module::addToModuleIdentityPath(
       
$top,
       
'firstModule/subModule2',
       
$grandchild2,
       
$grandchild2->getIdentifier()
    );
} catch (\
Exception $e) {
   
$success = false;
}

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

$paths = Loader\Module::getModuleIdentityPaths($top);

echo
"Identity Paths: \n";
foreach (
$paths as $path) {
    echo
" $path\n";
}

echo
"\n";