[Cs-content-commits] SF.net SVN: cs-content:[318] trunk/0.10
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-01-19 18:33:40
|
Revision: 318
http://cs-content.svn.sourceforge.net/cs-content/?rev=318&view=rev
Author: crazedsanity
Date: 2009-01-19 18:33:34 +0000 (Mon, 19 Jan 2009)
Log Message:
-----------
Code for setting globals & constants along with associated tests.
Modified Paths:
--------------
trunk/0.10/cs_siteConfig.class.php
trunk/0.10/tests/testOfCSContent.php
Modified: trunk/0.10/cs_siteConfig.class.php
===================================================================
--- trunk/0.10/cs_siteConfig.class.php 2009-01-19 17:38:36 UTC (rev 317)
+++ trunk/0.10/cs_siteConfig.class.php 2009-01-19 18:33:34 UTC (rev 318)
@@ -36,7 +36,13 @@
/** arrayToPath{} object. */
private $a2p;
+ /** Prefix to add to every index in GLOBALS and CONSTANTS. */
+ private $setVarPrefix;
+ /** Sections available within the config */
+ private $configSections=array();
+
+
//-------------------------------------------------------------------------
/**
* Constructor.
@@ -45,7 +51,9 @@
*/
public function __construct($configFileLocation, $section='MAIN', $setVarPrefix=null) {
- //TODO: don't use cs_globalFunctions{} if unneeded.
+ $section = strtoupper($section);
+ $this->setVarPrefix=$setVarPrefix;
+
$this->gf = new cs_globalFunctions;
$this->gf->debugPrintOpt=1;
@@ -103,11 +111,18 @@
);
$parseThis = array();
+
+ $this->configSections = array();
+
foreach($data as $section=>$secData) {
//only handle UPPERCASE index names; lowercase indexes are special entries (i.e. "type" or "attributes"
if($section == strtoupper($section)) {
- $this->gf->debug_print(__METHOD__ .": handling (". $section .")");
+ $this->configSections[] = $section;
foreach($secData as $itemName=>$itemValue) {
+ $attribs = array();
+ if(is_array($itemValue['attributes'])) {
+ $attribs = $itemValue['attributes'];
+ }
$itemValue = $itemValue['value'];
if(preg_match("/{/", $itemValue)) {
$origVal = $itemValue;
@@ -118,6 +133,13 @@
$parseThis[$itemName] = $itemValue;
$parseThis[$section ."/". $itemName] = $itemValue;
$data[$section][$itemName]['value'] = $itemValue;
+
+ if($attribs['SETGLOBAL']) {
+ $GLOBALS[$this->setVarPrefix . $itemName] = $itemValue;
+ }
+ if($attribs['SETCONSTANT']) {
+ define($this->setVarPrefix . $itemName, $itemValue);
+ }
}
}
}
@@ -129,7 +151,6 @@
//-------------------------------------------------------------------------
public function get_section($section) {
- $this->gf->debug_print(__METHOD__ .": section=(". $section .")");
$data = $this->a2p->get_data($section);
if(is_array($data) && count($data) && $data['type'] == 'open') {
@@ -158,6 +179,14 @@
//-------------------------------------------------------------------------
+
+ //-------------------------------------------------------------------------
+ public function get_valid_sections() {
+ return($this->configSections);
+ }//end get_valid_sections()
+ //-------------------------------------------------------------------------
+
+
}//end cs_siteConfig
?>
Modified: trunk/0.10/tests/testOfCSContent.php
===================================================================
--- trunk/0.10/tests/testOfCSContent.php 2009-01-19 17:38:36 UTC (rev 317)
+++ trunk/0.10/tests/testOfCSContent.php 2009-01-19 18:33:34 UTC (rev 318)
@@ -21,6 +21,9 @@
function __construct() {
require_once(dirname(__FILE__) .'/../cs_globalFunctions.php');
require_once(dirname(__FILE__) .'/../cs_siteConfig.class.php');
+
+ $this->gf = new cs_globalFunctions;
+ $this->gf->debugPrintOpt=1;
}//end __construct()
//-------------------------------------------------------------------------
@@ -177,7 +180,8 @@
//-------------------------------------------------------------------------
public function test_siteConfig() {
$configFile = dirname(__FILE__) .'/files/sampleConfig.xml';
- $sc = new cs_siteConfig($configFile);
+ $varPrefix = preg_replace("/:/", "_", __METHOD__ ."-");
+ $sc = new cs_siteConfig($configFile, 'main', $varPrefix);
//make sure that specifying the section "main" section works just like NOT specifying it.
$this->assertEqual($sc->get_value('SITEROOT'), $sc->get_value('MAIN/SITEROOT'));
@@ -198,6 +202,45 @@
$sc->get_value('cs-content/tmpldir'),
"path replacement for cs-content/tmpldir (". $sc->get_value('cs-content/tmpldir') .") didn't match main/tmpldir (". $sc->get_value('main/tmpldir') .")"
);
+
+ //make sure all of the items that are supposed to be set as globals & constants actually were.
+
+ //Do some testing of sections....
+ $this->assertTrue(is_array($sc->get_valid_sections()));
+ $this->assertEqual($sc->get_valid_sections(), array('MAIN', 'CS-CONTENT'));
+
+ //now let's make sure we got all of the proper globals & constants set.... first, get the list of things that should be globals/constants.
+ $setAsGlobals = array();
+ $setAsConstants = array();
+ foreach($sc->get_valid_sections() as $section) {
+ $this->gf->debug_print(__METHOD__ .": evaluating section (". $section .")");
+ $sectionData = $sc->get_section($section);
+ foreach($sectionData as $name=>$value) {
+ if(is_array($value['attributes'])) {
+ if(isset($value['attributes']['SETGLOBAL'])) {
+ $setAsGlobals[$name] = $value['value'];
+ }
+ if(isset($value['attributes']['SETCONSTANT'])) {
+ $setAsConstants[$name] = $value['value'];
+ }
+ }
+ }
+ }
+
+ foreach($setAsGlobals as $name=>$val) {
+ $index = $varPrefix . $name;
+ $this->assertNotEqual($name, $index);
+ $this->assertTrue(isset($GLOBALS[$index]));
+ $this->assertEqual($GLOBALS[$index], $val);
+ }
+
+ foreach($setAsConstants as $name=>$val) {
+ $index = $varPrefix . $name;
+ $this->assertNotEqual($name, $index);
+ $this->assertTrue(defined($index));
+ $this->assertEqual(constant($index), $val);
+ }
+
}//end test_siteConfig()
//-------------------------------------------------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|