[Cs-content-commits] SF.net SVN: cs-content:[375] trunk/1.0/cs_siteConfig.class.php
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-05-06 15:23:07
|
Revision: 375 http://cs-content.svn.sourceforge.net/cs-content/?rev=375&view=rev Author: crazedsanity Date: 2009-05-06 15:23:00 +0000 (Wed, 06 May 2009) Log Message: ----------- Allow entire sections to be put into the GLOBALS array (request #271). /cs_siteConfig.class.php: * MAIN::: -- NEW (private) VAR: $setGlobalArrays=array() * parse_config(): -- check for "SETGLOBAL" on config sections (value disregarded), put into internal "setGlobalArrays" var for later. -- if there is anything in the internal "setGlobalArrays" var, loop through it and put that data into the $GLOBALS array using cs_arrayToPath::set_data(). Modified Paths: -------------- trunk/1.0/cs_siteConfig.class.php Modified: trunk/1.0/cs_siteConfig.class.php =================================================================== --- trunk/1.0/cs_siteConfig.class.php 2009-05-05 20:41:04 UTC (rev 374) +++ trunk/1.0/cs_siteConfig.class.php 2009-05-06 15:23:00 UTC (rev 375) @@ -60,6 +60,8 @@ /** Boolean flag to determine if the object has been properly initialized or not. */ private $isInitialized=false; + /** Store a list of items that need to be pushed into $GLOBALS on a given path. */ + private $setGlobalArrays=array(); //------------------------------------------------------------------------- /** @@ -172,6 +174,25 @@ //only handle UPPERCASE index names; lowercase indexes are special entries (i.e. "type" or "attributes" if($section == strtoupper($section)) { $this->configSections[] = $section; + + unset($secData['type']); + + if(is_array($secData['attributes'])) { + $sectionAttribs = $secData['attributes']; + unset($secData['attributes']); + + //put stuff into the globals scope... + if(isset($sectionAttribs['SETGLOBAL'])) { + $path = $section; + + $setPath = $path; + if(strlen($sectionAttribs['GLOBALARRAYLOCATION'])) { + $setPath = $sectionAttribs['GLOBALARRAYLOCATION']; + } + $this->setGlobalArrays[$path] = $setPath; + } + } + foreach($secData as $itemName=>$itemValue) { $attribs = array(); if(is_array($itemValue['attributes'])) { @@ -212,8 +233,25 @@ } } } + $this->a2p = new cs_arrayToPath($data); $this->isInitialized=true; + + if(count($this->setGlobalArrays)) { + $globA2p = new cs_arrayToPath(&$GLOBALS); + foreach($this->setGlobalArrays as $configPath=>$globalsPath) { + if($this->a2p->get_data($configPath)) { + $setMe = array(); + foreach($this->a2p->get_data($configPath) as $i=>$v) { + $setMe[$i] = $v['value']; + } + $globA2p->set_data($globalsPath, $setMe); + } + else { + throw new exception(__METHOD__ .": attempted to set global array from non-existent path (". $configPath .")"); + } + } + } } else { throw new exception(__METHOD__ .": xmlReader not created, object probably not initialized"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |