<?php 
 
require_once('../../Features/Configuration.php'); 
 
use Falcraft\Features; 
 
class ConfiguredClass { 
    use Features\Configuration; 
     
    public function __construct($configure) 
    { 
        $this->configure($configure); 
    } 
     
    public function getChildNode1() 
    { 
        return $this->conf->parentNode->childNode1; 
    } 
     
    public function getChildNode2() 
    { 
        return $this->conf->parentNode->childNode2; 
    } 
     
    public function getSingleNode() 
    { 
        return $this->conf->singleNode; 
    } 
     
    public function getTestHost($branch) 
    { 
        return $this->conf->$branch->database->params->host; 
    } 
     
    public function getTestDBName($branch) 
    { 
        return $this->conf->$branch->database->params->dbname; 
    } 
} 
 
echo "Falcraft\\Features\\Configuration.php Test\n"; 
echo "----------------------------------------\n\n"; 
 
echo "Instantiating Configuration Class With No Args -> "; 
 
$success = true; 
 
try { 
    $configuredObject = new ConfiguredClass(array()); 
} catch (\Exception $e) { 
    $success = false; 
} 
 
if ($success) { 
    echo "Success!\n"; 
} else { 
    echo "Failure...\n"; 
} 
 
echo "Instantiating Configuration Class with Array -> "; 
 
$success = true; 
 
try { 
    $configuredObject = new ConfiguredClass(array ( 
        'parentNode' => array( 
            'childNode1' => 'data1', 
            'childNode2' => 'data2',), 
        'singleNode' => 'data3')); 
} catch (\Exception $e) { 
    $success = false; 
} 
 
if ($success) { 
    echo "Success!\n"; 
} else { 
    echo "Failure...\n"; 
} 
 
echo "    Checking Configuration Variables -> \n"; 
 
$success = true; 
 
$childNode1 = $childNode2 = $singleNode = null; 
 
try { 
    $childNode1 = $configuredObject->getChildNode1(); 
    $childNode2 = $configuredObject->getChildNode2(); 
    $singleNode = $configuredObject->getSingleNode(); 
    if (!$childNode1 || !$childNode2 || !$singleNode) { 
        $success = false; 
    } 
} catch (\Exception $e) { 
    $success = false; 
} 
 
if ($success) { 
    echo "        childNode1: $childNode1\n"; 
    echo "        childNode2: $childNode2\n"; 
    echo "        singleNode: $singleNode -- Success!\n"; 
} else { 
    echo "        -- Failure!\n"; 
} 
 
echo "Instantiating Configuration Class with Ini File -> \n"; 
 
$success = true; 
 
$childNode1 = $childNode2 = $singleNode = null; 
 
try { 
    $configuredObject = new ConfiguredClass(array()); 
    $configuredObject->configure(__DIR__ . '/test.ini'); 
    $childNode1 = $configuredObject->getChildNode1(); 
    $childNode2 = $configuredObject->getChildNode2(); 
    $singleNode = $configuredObject->getSingleNode(); 
    if (!$childNode1 || !$childNode2 || !$singleNode) { 
        $success = false; 
    } 
} catch (\Exception $e) { 
    $success = false; 
} 
 
echo "    Checking Configuration Variables -> \n"; 
 
if ($success) { 
    echo "        childNode1: $childNode1\n"; 
    echo "        childNode2: $childNode2\n"; 
    echo "        singleNode: $singleNode -- Success!\n"; 
} else { 
    echo "        -- Failure!\n"; 
} 
 
echo "Instantiating Configuration Class with XML File -> \n"; 
 
$success = true; 
 
$testHostStaging = $testDBNameStaging = null; 
$testHostProduction = null; 
 
try { 
    $configuredObject = new ConfiguredClass(array()); 
    $configuredObject->configure(__DIR__ . '/test.xml'); 
    $testHostStaging = $configuredObject->getTestHost('staging'); 
    $testDBNameStaging = $configuredObject->getTestDBName('staging'); 
    $testHostProduction = $configuredObject->getTestHost('production'); 
} catch (\Exception $e) { 
    $success = false; 
} 
 
echo "    Checking Configuration Variables -> \n"; 
 
if ($success) { 
    echo "        testHostStaging: $testHostStaging\n"; 
    echo "        testDBNameStaging: $testDBNameStaging\n"; 
    echo "        testHostProduction: $testHostProduction -- Success!\n\n"; 
} else { 
    echo "        -- Failure!\n\n"; 
} 
 
echo "-- NOTE!  testDBNameStaging may be empty, Zend may not be 'extending' properly\n\n"; 
 
echo "Instantiating Configuration Class with JSON File -> \n"; 
 
$success = true; 
 
$testHostStaging = $testDBNameStaging = null; 
$testHostProduction = null; 
 
//try { 
    $configuredObject = new ConfiguredClass(array()); 
    $configuredObject->configure(__DIR__ . '/test.json'); 
     
    $testHostStaging = $configuredObject->getTestHost('staging'); 
    $testDBNameStaging = $configuredObject->getTestDBName('staging'); 
    $testHostProduction = $configuredObject->getTestHost('production'); 
//} catch (\Exception $e) { 
//    $success = false; 
//} 
 
echo "    Checking Configuration Variables -> \n"; 
 
if ($success) { 
    echo "        testHostStaging: $testHostStaging\n"; 
    echo "        testDBNameStaging: $testDBNameStaging\n"; 
    echo "        testHostProduction: $testHostProduction -- Success!\n\n"; 
} else { 
    echo "        -- Failure!\n\n"; 
} 
 
echo "-- NOTE!  testDBNameStaging may be empty, Zend may not be 'extending' properly\n\n"; 
 
 
 |