Thread: [Cs-content-commits] SF.net SVN: cs-content:[314] trunk/0.10
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-01-14 03:04:26
|
Revision: 314 http://cs-content.svn.sourceforge.net/cs-content/?rev=314&view=rev Author: crazedsanity Date: 2009-01-14 03:04:15 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Unit tests (using Simple Test). Added Paths: ----------- trunk/0.10/tests/ trunk/0.10/tests/example_test.php trunk/0.10/tests/testOfCSContent.php Added: trunk/0.10/tests/example_test.php =================================================================== --- trunk/0.10/tests/example_test.php (rev 0) +++ trunk/0.10/tests/example_test.php 2009-01-14 03:04:15 UTC (rev 314) @@ -0,0 +1,20 @@ +<?php +/* + * Created on Jan 13, 2009 + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + +require_once(dirname(__FILE__) .'/testOfCSContent.php'); + + +$test = &new TestOfCSContent(); +$test->run(new HtmlReporter()); + +?> Property changes on: trunk/0.10/tests/example_test.php ___________________________________________________________________ Added: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision Added: trunk/0.10/tests/testOfCSContent.php =================================================================== --- trunk/0.10/tests/testOfCSContent.php (rev 0) +++ trunk/0.10/tests/testOfCSContent.php 2009-01-14 03:04:15 UTC (rev 314) @@ -0,0 +1,181 @@ +<?php +/* + * Created on Jan 13, 2009 + * + * + * FILE INFORMATION: + * + * $HeadURL$ + * $Id$ + * $LastChangedDate$ + * $LastChangedBy$ + * $LastChangedRevision$ + */ + + + + + + +//============================================================================= +class TestOfCSContent extends UnitTestCase { + + //------------------------------------------------------------------------- + function __construct() { + require_once(dirname(__FILE__) .'/../cs_globalFunctions.php'); + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function test_cleanString() { + + $gf = new cs_globalFunctions(); + + $cleanThis = '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS'; + $testSQL = array( + 'none' => $cleanThis, + 'query' => '@_=;34:/JuST THIS', + 'theDefault' => '34JuSTTHIS', + 'alphanumeric' => '34JuSTTHIS', + 'sql' => '~`!@#$^&*()_+-=[]{}|;34:\\\'<>?,.//\".JuST THIS', + 'sql_insert' => '~`!@#$^&*()_+-=[]{}|;34:\\\\\'<>?,.//".JuST THIS', + 'sql92_insert' => '~`!@#$^&*()_+-=[]{}|;34:\'\'<>?,.//".JuST THIS', + 'double_quote' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\.JuST THIS', + 'htmlspecial' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'htmlspecial_q' => '~`!@#$^&*()_+-=[]\{}|;34:\\'\<>?,.//\".JuST THIS', + 'htmlspecial_nq' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'htmlentity' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'htmlentity_plus_brackets' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\".JuST THIS', + 'double_entity' => '~`!@#$^&*()_+-=[]\{}|;34:\\\'\<>?,.//\.JuST THIS', + 'meta' => '~`!@#\$\^&\*\(\)_\+-=\[\]\\\\{}|;34:\\\\\'\\\<>\?,\.//\\\\"\.JuST THIS', + 'email' => '@_-34..JuSTTHIS', + 'email_plus_spaces' => '@_-34..JuST THIS', + 'phone_fax' => '()+-34 ', + 'integer' => '34', + 'numeric' => '34', + 'decimal' => '34..', + 'float' => '34..', + 'name' => '\'JuSTTHIS', + 'names' => '\'JuSTTHIS', + 'alpha' => 'JuSTTHIS', + 'bool' => 't', + 'varchar' => '\'@_=;34:/JuST THIS\'', + 'date' => '-34', + 'datetime' => '-34:\'.//.JuST THIS', + 'all' => '34JuSTTHIS' + ); + + foreach($testSQL as $name=>$expected) { + $cleanedData = $gf->cleanString($cleanThis, $name); + + //NOTE::: passing "%" in the message data causes an exception with the simpletest framework. + $this->assertEqual($expected, $cleanedData); + } + + + //test quoting (with a few exceptions). + $testQuotes = $testSQL; + unset($testQuotes['none'], $testQuotes['sql92_insert']); + foreach($testQuotes as $name=>$expected) { + $gf->switch_force_sql_quotes(1); + $cleanedDataPlusQuotes = $gf->cleanString($cleanThis, $name, 1); + $this->assertEqual("'". $expected ."'", $cleanedDataPlusQuotes, "Failed quoting with style=(". $name .")"); + + $gf->switch_force_sql_quotes(0); + $this->assertEqual("'". $expected ."'", $cleanedDataPlusQuotes, "Failed quoting with style=(". $name .")"); + } + + + //TEST NULLS + { + + $this->assertEqual($gf->cleanString("", "numeric",0), ""); + $this->assertEqual($gf->cleanString("", "numeric",1), "''"); + $this->assertEqual($gf->cleanString("", "integer",0), ""); + $this->assertEqual($gf->cleanString("", "integer",1), "''"); + $this->assertEqual($gf->cleanString(null, "numeric",0), "NULL"); + $this->assertEqual($gf->cleanString(null, "numeric",1), "NULL"); + $this->assertEqual($gf->cleanString(null, "integer",0), "NULL"); + $this->assertEqual($gf->cleanString(null, "integer",1), "NULL"); + + $this->assertEqual($gf->cleanString(null, "varchar",0), "NULL"); + $this->assertEqual($gf->cleanString(null, "varchar",1), "'NULL'"); + $this->assertEqual($gf->cleanString("", "varchar",0), "NULL"); + $this->assertEqual($gf->cleanString("", "varchar",1), "'NULL'"); + } + + }//end test_cleanString() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function test_string_from_array() { + $gf = new cs_globalFunctions; + $gf->switch_force_sql_quotes(0); + + //Test some SQL-Specific stuff. + $testSQL = array( + 'column1' => "'my value ' OR 'x'='x'", + 'column two' => "Stuff" + ); + + //Test INSERT style. + { + $expected = "(column1, column two) VALUES ('my value ' OR 'x'='x','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert'), $expected); + + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql'), $expected); + + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql_insert'), $expected); + + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, 'sql92_insert'), $expected); + + //now let's see what happens if we pass an array signifying how it should be cleaned. + $expected = "(column1, column two) VALUES ('\'my value \' OR \'x\'=\'x\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql', 'column two'=>'sql')), $expected); + $expected = "(column1, column two) VALUES ('\\\\\'my value \\\\\' OR \\\\\'x\\\\\'=\\\\\'x\\\\\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql_insert', 'column two'=>'sql_insert')), $expected); + $expected = "(column1, column two) VALUES ('\'\'my value \'\' OR \'\'x\'\'=\'\'x\'\'','Stuff')"; + $this->assertEqual($gf->string_from_array($testSQL, 'insert', null, array('column1'=>'sql92_insert', 'column two'=>'sql92_insert')), $expected); + + } + + }//end test_string_from_array() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + function test_interpret_bool() { + $gf=new cs_globalFunctions; + + $this->assertEqual($gf->interpret_bool('true'), true); + $this->assertEqual($gf->interpret_bool('false'), false); + $this->assertEqual($gf->interpret_bool('0'), false); + $this->assertEqual($gf->interpret_bool('1'), true); + $this->assertEqual($gf->interpret_bool(0), false); + $this->assertEqual($gf->interpret_bool(1), true); + $this->assertEqual($gf->interpret_bool('f'), false); + $this->assertEqual($gf->interpret_bool('t'), true); + $this->assertEqual($gf->interpret_bool("1stuff"), true); + $this->assertEqual($gf->interpret_bool(""), false); + $this->assertEqual($gf->interpret_bool(" true "), true); + $this->assertEqual($gf->interpret_bool(" false "), false); + + //now go through the same thing, but this time tell it to give back a specific value for true and false. + $this->assertEqual($gf->interpret_bool(false, array(0=>'FaLSe',1=>"crap")), 'FaLSe'); + $this->assertEqual($gf->interpret_bool(false, array(0=>"crap",1=>'FaLSe')), 'crap'); + }//end test_interpret_bool() + //------------------------------------------------------------------------- + + + +}//end TestOfCSContent +//============================================================================= +?> Property changes on: trunk/0.10/tests/testOfCSContent.php ___________________________________________________________________ Added: svn:keywords + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-01-19 17:38:47
|
Revision: 317 http://cs-content.svn.sourceforge.net/cs-content/?rev=317&view=rev Author: crazedsanity Date: 2009-01-19 17:38:36 +0000 (Mon, 19 Jan 2009) Log Message: ----------- New cs_siteConfig{} class with unit tests. Modified Paths: -------------- trunk/0.10/tests/testOfCSContent.php Added Paths: ----------- trunk/0.10/cs_siteConfig.class.php Copied: trunk/0.10/cs_siteConfig.class.php (from rev 315, trunk/0.10/cs_phpDB.php) =================================================================== --- trunk/0.10/cs_siteConfig.class.php (rev 0) +++ trunk/0.10/cs_siteConfig.class.php 2009-01-19 17:38:36 UTC (rev 317) @@ -0,0 +1,163 @@ +<?php + +/* + * A class for handling configuration of database-driven web applications. + * + * NOTICE::: this class requires that cs-phpxml and cs-arraytopath are both available + * at the same directory level as cs-content; all projects are SourceForge.net projects, + * using their unix names ("cs-phpxml" and "cs-arrayToPath"). The cs-phpxml project + * requires cs-arrayToPath for parsing XML paths. + * + * SVN INFORMATION::: + * SVN Signature:::::::: $Id$ + * Last Committted Date: $Date$ + * Last Committed Path:: $HeadURL$ + * + */ + +require_once(dirname(__FILE__). '/../cs-phpxml/xmlParserClass.php'); +require_once(dirname(__FILE__) .'/../cs-phpxml/xmlBuilderClass.php'); + +class cs_siteConfig { + + private $xmlReader; + private $xmlWriter; + private $xmlBuilder; + private $fs; + private $readOnly; + private $configDirname; + + /** Active section of the full site configuration. */ + private $activeSection; + + /** The FULL configuration file, instead of just the active section. */ + private $fullConfig=array(); + + /** arrayToPath{} object. */ + private $a2p; + + + //------------------------------------------------------------------------- + /** + * Constructor. + * + * @$configFileLocation (str) URI for config file. + */ + public function __construct($configFileLocation, $section='MAIN', $setVarPrefix=null) { + + //TODO: don't use cs_globalFunctions{} if unneeded. + $this->gf = new cs_globalFunctions; + $this->gf->debugPrintOpt=1; + + $this->set_active_section($section); + + if(strlen($configFileLocation) && file_exists($configFileLocation)) { + + $this->configDirname = dirname($configFileLocation); + $this->fs = new cs_fileSystemClass($this->configDirname); + + $this->xmlReader = new XMLParser($this->fs->read($configFileLocation)); + + if($this->fs->is_writable($configFileLocation)) { + $this->readOnly = false; + } + else { + $this->readOnly = true; + } + } + else { + throw new exception(__METHOD__ .": invalid configuration file (". $configFileLocation .")"); + } + + if(strlen($section)) { + try { + $this->parse_config(); + $this->config = $this->get_section($section); + } + catch(exception $e) { + throw new exception(__METHOD__ .": invalid section (". $section ."), DETAILS::: ". $e->getMessage()); + } + } + else { + throw new exception(__METHOD__ .": no section given (". $section .")"); + } + }//end __construct() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function set_active_section($section) { + $this->activeSection = strtoupper($section); + }//end set_active_section($section) + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function parse_config() { + $data = $this->xmlReader->get_path($this->xmlReader->get_root_element()); + + $specialVars = array( + '_DIRNAMEOFFILE_' => $this->configDirname + ); + $parseThis = 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 .")"); + foreach($secData as $itemName=>$itemValue) { + $itemValue = $itemValue['value']; + if(preg_match("/{/", $itemValue)) { + $origVal = $itemValue; + $itemValue = $this->gf->mini_parser($itemValue, $specialVars, '{', '}'); + $itemValue = $this->gf->mini_parser($itemValue, $parseThis, '{', '}'); + $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); + } + $parseThis[$itemName] = $itemValue; + $parseThis[$section ."/". $itemName] = $itemValue; + $data[$section][$itemName]['value'] = $itemValue; + } + } + } + $this->a2p = new arrayToPath($data); + }//end parse_config() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + 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') { + unset($data['type']); + $retval = $data; + } + else { + throw new exception(__METHOD__ .": invalid section or no data (". $data['type'] .")"); + } + + return($retval); + }//end get_section() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function get_value($index) { + if(preg_match("/\//", $index)) { + //section NOT given, assume they're looking for something in the active section. + $index = $this->activeSection ."/". $index; + } + $retval = $this->a2p->get_data($index .'/value'); + return($retval); + }//end get_value() + //------------------------------------------------------------------------- + + +}//end cs_siteConfig + +?> Property changes on: trunk/0.10/cs_siteConfig.class.php ___________________________________________________________________ Added: svn:eol + native Added: svn:keywords + Id HeadURL Date Revision Author Added: svn:mergeinfo + Added: svn:eol-style + native Modified: trunk/0.10/tests/testOfCSContent.php =================================================================== --- trunk/0.10/tests/testOfCSContent.php 2009-01-19 16:43:10 UTC (rev 316) +++ trunk/0.10/tests/testOfCSContent.php 2009-01-19 17:38:36 UTC (rev 317) @@ -14,15 +14,13 @@ - - - //============================================================================= class TestOfCSContent extends UnitTestCase { //------------------------------------------------------------------------- function __construct() { require_once(dirname(__FILE__) .'/../cs_globalFunctions.php'); + require_once(dirname(__FILE__) .'/../cs_siteConfig.class.php'); }//end __construct() //------------------------------------------------------------------------- @@ -176,6 +174,35 @@ + //------------------------------------------------------------------------- + public function test_siteConfig() { + $configFile = dirname(__FILE__) .'/files/sampleConfig.xml'; + $sc = new cs_siteConfig($configFile); + + //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')); + $this->assertEqual($sc->get_value('SITEROOT'), $sc->get_value('siteroot')); + $this->assertEqual($sc->get_value('SITEROOT'), $sc->get_value('siteRoot')); + + //make sure if we request an index that doesn't exist, it is returned as null + $this->assertTrue(is_null($sc->get_value('NONExISTENT___'))); + + //make sure some values have been replaced. + $this->assertTrue(!preg_match("/{/", $sc->get_value('libdir'))); + $this->assertTrue( + preg_match("/^". preg_replace("/\//", "\/", $sc->get_value('siteroot')) ."/", $sc->get_value('libdir')), + "LIBDIR (". $sc->get_value('libdir') .") doesn't contain SITEROOT (". $sc->get_value('siteroot') .")" + ); + $this->assertEqual( + $sc->get_value('main/tmpldir'), + $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') .")" + ); + }//end test_siteConfig() + //------------------------------------------------------------------------- + + + }//end TestOfCSContent //============================================================================= ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <cra...@us...> - 2009-01-20 05:18:26
|
Revision: 321 http://cs-content.svn.sourceforge.net/cs-content/?rev=321&view=rev Author: crazedsanity Date: 2009-01-20 05:18:20 +0000 (Tue, 20 Jan 2009) Log Message: ----------- Minor requirement additions, better errors, and removed unneeded methods. /cs_siteConfig.class.php: * MAIN::: -- require cs_globalFunctions and cs_fileSystemClass. * parse_config(): -- throw an exception if xmlReader isn't an object; this is basically a check to make debugging easier. * create_site_config() [DELETED]: -- it is easier for a person to copy the sample configuration file than to attempt to create a generic one. /tests/testOfCSContent.php: * remove unneeded debug_print() statement. 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 19:27:21 UTC (rev 320) +++ trunk/0.10/cs_siteConfig.class.php 2009-01-20 05:18:20 UTC (rev 321) @@ -15,6 +15,8 @@ * */ +require_once(dirname(__FILE__) .'/cs_globalFunctions.php'); +require_once(dirname(__FILE__) .'/cs_fileSystemClass.php'); require_once(dirname(__FILE__). '/../cs-phpxml/xmlParserClass.php'); require_once(dirname(__FILE__) .'/../cs-phpxml/xmlBuilderClass.php'); @@ -156,47 +158,58 @@ * @return exception (FAIL) exception indicates problem encountered. */ private function parse_config() { - $data = $this->xmlReader->get_path($this->xmlReader->get_root_element()); - - $specialVars = array( - '_DIRNAMEOFFILE_' => $this->configDirname - ); - $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->configSections[] = $section; - foreach($secData as $itemName=>$itemValue) { - $attribs = array(); - if(is_array($itemValue['attributes'])) { - $attribs = $itemValue['attributes']; + if(is_object($this->xmlReader)) { + $data = $this->xmlReader->get_path($this->xmlReader->get_root_element()); + + $specialVars = array( + '_DIRNAMEOFFILE_' => $this->configDirname + ); + $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->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; + $itemValue = $this->gf->mini_parser($itemValue, $specialVars, '{', '}'); + $itemValue = $this->gf->mini_parser($itemValue, $parseThis, '{', '}'); + $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); + } + + if($attribs['CLEANPATH']) { + $itemValue = $this->fs->resolve_path_with_dots($itemValue); + } + + $parseThis[$itemName] = $itemValue; + $parseThis[$section ."/". $itemName] = $itemValue; + $data[$section][$itemName]['value'] = $itemValue; + + $setVarIndex = $this->setVarPrefix . $itemName; + if($attribs['SETGLOBAL']) { + $GLOBALS[$setVarIndex] = $itemValue; + } + if($attribs['SETCONSTANT']) { + define($setVarIndex, $itemValue); + } } - $itemValue = $itemValue['value']; - if(preg_match("/{/", $itemValue)) { - $origVal = $itemValue; - $itemValue = $this->gf->mini_parser($itemValue, $specialVars, '{', '}'); - $itemValue = $this->gf->mini_parser($itemValue, $parseThis, '{', '}'); - $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); - } - $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); - } } } + $this->a2p = new arrayToPath($data); + $this->isInitialized=true; } - $this->a2p = new arrayToPath($data); - $this->isInitialized=true; + else { + throw new exception(__METHOD__ .": xmlReader not created, object probably not initialized"); + } }//end parse_config() //------------------------------------------------------------------------- @@ -289,13 +302,6 @@ }//end get_valid_sections() //------------------------------------------------------------------------- - - - //------------------------------------------------------------------------- - public function create_site_config() { - }//end create_site_config() - //------------------------------------------------------------------------- - }//end cs_siteConfig ?> Modified: trunk/0.10/tests/testOfCSContent.php =================================================================== --- trunk/0.10/tests/testOfCSContent.php 2009-01-19 19:27:21 UTC (rev 320) +++ trunk/0.10/tests/testOfCSContent.php 2009-01-20 05:18:20 UTC (rev 321) @@ -213,7 +213,6 @@ $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'])) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2009-01-26 02:20:14
|
Revision: 325 http://cs-content.svn.sourceforge.net/cs-content/?rev=325&view=rev Author: crazedsanity Date: 2009-01-26 01:33:48 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Reverse merge (HEAD:311) to match /releases/0.10 Modified Paths: -------------- trunk/0.10/cs_globalFunctions.php trunk/0.10/db_types/cs_phpDB__pgsql.class.php Removed Paths: ------------- trunk/0.10/cs_siteConfig.class.php trunk/0.10/tests/ Modified: trunk/0.10/cs_globalFunctions.php =================================================================== --- trunk/0.10/cs_globalFunctions.php 2009-01-26 01:29:21 UTC (rev 324) +++ trunk/0.10/cs_globalFunctions.php 2009-01-26 01:33:48 UTC (rev 325) @@ -17,17 +17,10 @@ public function __construct() { //These checks have been implemented for pseudo backwards-compatibility // (internal vars won't change if GLOBAL vars changed). - if(defined('DEBUGREMOVEHR')) { - $this->debugRemoveHr = constant('DEBUGREMOVEHR'); - } - elseif(isset($GLOBALS['DEBUGREMOVEHR'])) { + if(isset($GLOBALS['DEBUGREMOVEHR'])) { $this->debugRemoveHr = $GLOBALS['DEBUGREMOVEHR']; } - - if(defined('DEBUGPRINTOPT')) { - $this->debugPrintOpt = constant('DEBUGPRINTOPT'); - } - elseif(isset($GLOBALS['DEBUGPRINTOPT'])) { + if(isset($GLOBALS['DEBUGPRINTOPT'])) { $this->debugPrintOpt = $GLOBALS['DEBUGPRINTOPT']; } $this->set_version_file_location(dirname(__FILE__) . '/VERSION'); @@ -62,13 +55,15 @@ $this->oldForceSqlQuotes = $this->forceSqlQuotes; $this->forceSqlQuotes = $newSetting; $retval = true; + $this->debug_print(__METHOD__ .": swapped (OLD=". $this->oldForceSqlQuotes .", CUR=". $this->forceSqlQuotes .")"); } else { $retval = false; + $this->debug_print(__METHOD__ .": no swap (OLD=". $this->oldForceSqlQuotes .", CUR=". $this->forceSqlQuotes .")"); } return($retval); - }//end switch_force_sql_quotes() + }//end force_sql_quotes() //========================================================================= @@ -380,7 +375,6 @@ */ $evilChars = array("\$", "%", "~", "*",">", "<", "-", "{", "}", "[", "]", ")", "(", "&", "#", "?", ".", "\,","\/","\\","\"","\|","!","^","+","`","\n","\r"); $cleanThis = preg_replace("/\|/","",$cleanThis); - $cleanThis = preg_replace("/\'/", "", $cleanThis); $cleanThis = str_replace($evilChars,"", $cleanThis); $cleanThis = stripslashes(addslashes($cleanThis)); break; @@ -519,7 +513,7 @@ case "name": case "names": - //allows only things in the "alpha" case and single quotes. + //removes everything in the "alpha" case, but allows "'". $cleanThis = preg_replace("/[^a-zA-Z']/", "", $cleanThis); break; @@ -531,7 +525,7 @@ case "bool": case "boolean": //makes it either T or F (gotta lower the string & only check the first char to ensure accurate results). - $cleanThis = $this->interpret_bool($cleanThis, array('f', 't')); + $cleanThis = interpret_bool($cleanThis, array('f', 't')); break; case "varchar": @@ -777,67 +771,6 @@ return($retval); }//end array_as_option_list() //########################################################################## - - - - //########################################################################## - public function interpret_bool($interpretThis, array $trueFalseMapper=null) { - $interpretThis = preg_replace('/ /', '', $interpretThis); - if(is_array($trueFalseMapper)) { - if(count($trueFalseMapper) == 2 && isset($trueFalseMapper[0]) && isset($trueFalseMapper[1])) { - $realVals = $trueFalseMapper; - } - else { - throw new exception(__METHOD__ .": invalid true/false map"); - } - } - else { - //set an array that defines what "0" and "1" return. - $realVals = array( - 0 => false, - 1 => true - ); - } - - //now figure out the value to return. - if(is_numeric($interpretThis)) { - settype($interpretThis, 'integer'); - if($interpretThis == '0') { - $index=0; - } - else { - $index=1; - } - } - elseif(is_bool($interpretThis)) { - if($interpretThis == true) { - $index=1; - } - else { - $index=0; - } - } - elseif(preg_match('/^true$/i', $interpretThis) || preg_match('/^false$/', $interpretThis) || preg_match("/^[tf]$/", $interpretThis)) { - if(preg_match('/^true$/i', $interpretThis) || preg_match('/^t$/', $interpretThis)) { - $index=1; - } - else { - $index=0; - } - } - else { - //straight-up PHP if/else evaluation. - if($interpretThis) { - $index=1; - } - else { - $index=0; - } - } - - return($realVals[$index]); - }//end interpret_bool() - //########################################################################## }//end cs_globalFunctions{} Deleted: trunk/0.10/cs_siteConfig.class.php =================================================================== --- trunk/0.10/cs_siteConfig.class.php 2009-01-26 01:29:21 UTC (rev 324) +++ trunk/0.10/cs_siteConfig.class.php 2009-01-26 01:33:48 UTC (rev 325) @@ -1,307 +0,0 @@ -<?php - -/* - * A class for handling configuration of database-driven web applications. - * - * NOTICE::: this class requires that cs-phpxml and cs-arraytopath are both available - * at the same directory level as cs-content; all projects are SourceForge.net projects, - * using their unix names ("cs-phpxml" and "cs-arrayToPath"). The cs-phpxml project - * requires cs-arrayToPath for parsing XML paths. - * - * SVN INFORMATION::: - * SVN Signature:::::::: $Id$ - * Last Committted Date: $Date$ - * Last Committed Path:: $HeadURL$ - * - */ - -require_once(dirname(__FILE__) .'/cs_globalFunctions.php'); -require_once(dirname(__FILE__) .'/cs_fileSystemClass.php'); -require_once(dirname(__FILE__). '/../cs-phpxml/cs_phpxmlParser.class.php'); -require_once(dirname(__FILE__) .'/../cs-phpxml/cs_phpxmlBuilder.class.php'); - -class cs_siteConfig { - - /** XMLParser{} object, for reading XML config file. */ - private $xmlReader; - - /** cs_fileSystemClass{} object, for writing/updating XML config file - * (only available if file is writable) - */ - private $xmlWriter; - - /** XMLBuilder{} object, for updating XML. */ - private $xmlBuilder; - - /** cs_fileSystemClass{} object, for handling generic file operations (i.e. reading) */ - private $fs; - - /** boolean flag indicating if the given config file is readOnly (false=read/write) */ - private $readOnly; - - /** Directory for the config file. */ - private $configDirname; - - /** Active section of the full site configuration. */ - private $activeSection; - - /** The FULL configuration file, instead of just the active section. */ - private $fullConfig=array(); - - /** cs_arrayToPath{} object. */ - private $a2p; - - /** Prefix to add to every index in GLOBALS and CONSTANTS. */ - private $setVarPrefix; - - /** Sections available within the config */ - private $configSections=array(); - - /** Boolean flag to determine if the object has been properly initialized or not. */ - private $isInitialized=false; - - - //------------------------------------------------------------------------- - /** - * Constructor. - * - * @param $configFileLocation (str) URI for config file. - * @param $section (str,optional) set active section (default=MAIN) - * @param $setVarPrefix (str,optional) prefix to add to all global & constant names. - * - * @return NULL (PASS) object successfully created - * @return exception (FAIL) failed to create object (see exception message) - */ - public function __construct($configFileLocation, $section='MAIN', $setVarPrefix=null) { - - $section = strtoupper($section); - $this->setVarPrefix=$setVarPrefix; - - $this->gf = new cs_globalFunctions; - $this->gf->debugPrintOpt=1; - - if(strlen($configFileLocation) && file_exists($configFileLocation)) { - - $this->configDirname = dirname($configFileLocation); - $this->fs = new cs_fileSystemClass($this->configDirname); - - $this->xmlReader = new cs_phpxmlParser($this->fs->read($configFileLocation)); - - if($this->fs->is_writable($configFileLocation)) { - $this->readOnly = false; - $this->xmlWriter = new cs_fileSystemClass($this->configDirname); - - } - else { - $this->readOnly = true; - } - } - else { - throw new exception(__METHOD__ .": invalid configuration file (". $configFileLocation .")"); - } - - if(strlen($section)) { - try { - $this->parse_config(); - $this->set_active_section($section); - $this->config = $this->get_section($section); - } - catch(exception $e) { - throw new exception(__METHOD__ .": invalid section (". $section ."), DETAILS::: ". $e->getMessage()); - } - } - else { - throw new exception(__METHOD__ .": no section given (". $section .")"); - } - - }//end __construct() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Sets the active section. - * - * @param $section (str) section to be set as active. - * - * @return VOID (PASS) section was set successfully. - * @return exception (FAIL) problem encountred setting section. - */ - public function set_active_section($section) { - if($this->isInitialized === true) { - $section = strtoupper($section); - if(in_array($section, $this->configSections)) { - $this->activeSection = $section; - } - else { - throw new exception(__METHOD__ .": invalid section (". $section .")"); - } - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - }//end set_active_section($section) - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Parse the configuration file. Handles replacing {VARIABLES} in values, - * sets items as global or as constants, and creates array indicating the - * available sections from the config file. - * - * @param VOID (void) no arguments accepted. - * - * @return NULL (PASS) successfully parsed configuration - * @return exception (FAIL) exception indicates problem encountered. - */ - private function parse_config() { - if(is_object($this->xmlReader)) { - $data = $this->xmlReader->get_path($this->xmlReader->get_root_element()); - - $specialVars = array( - '_DIRNAMEOFFILE_' => $this->configDirname - ); - $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->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; - $itemValue = $this->gf->mini_parser($itemValue, $specialVars, '{', '}'); - $itemValue = $this->gf->mini_parser($itemValue, $parseThis, '{', '}'); - $itemValue = preg_replace("/[\/]{2,}/", "/", $itemValue); - } - - if($attribs['CLEANPATH']) { - $itemValue = $this->fs->resolve_path_with_dots($itemValue); - } - - $parseThis[$itemName] = $itemValue; - $parseThis[$section ."/". $itemName] = $itemValue; - $data[$section][$itemName]['value'] = $itemValue; - - $setVarIndex = $this->setVarPrefix . $itemName; - if($attribs['SETGLOBAL']) { - $GLOBALS[$setVarIndex] = $itemValue; - } - if($attribs['SETCONSTANT']) { - define($setVarIndex, $itemValue); - } - } - } - } - $this->a2p = new cs_arrayToPath($data); - $this->isInitialized=true; - } - else { - throw new exception(__METHOD__ .": xmlReader not created, object probably not initialized"); - } - }//end parse_config() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Retrieve all data about the given section. - * - * @param $section (str) section to retrieve. - * - * @return array (PASS) array contains section data. - * @return exception (FAIL) exception indicates problem. - */ - public function get_section($section) { - if($this->isInitialized === true) { - $data = $this->a2p->get_data($section); - - if(is_array($data) && count($data) && $data['type'] == 'open') { - unset($data['type']); - $retval = $data; - } - else { - throw new exception(__METHOD__ .": invalid section or no data (". $data['type'] .")"); - } - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - - return($retval); - }//end get_section() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Retrieves value from the active section, or from another (other sections - * specified like "SECTION/INDEX"). - * - * @param $index (str) index name of value to retrieve. - * - * @return mixed (PASS) returns value of given index. - * - * NOTE::: this will return NULL if the given index or section/index does - * not exist. - */ - public function get_value($index) { - if($this->isInitialized === true) { - if(preg_match("/\//", $index)) { - //section NOT given, assume they're looking for something in the active section. - $index = $this->activeSection ."/". $index; - } - $retval = $this->a2p->get_data($index .'/value'); - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - return($retval); - }//end get_value() - //------------------------------------------------------------------------- - - - - //------------------------------------------------------------------------- - /** - * Retrieves list of valid configuration sections, as defined by - * parse_config(). - * - * @param VOID (void) no parameters accepted. - * - * @return array (PASS) array holds list of valid sections. - * @return exception (FAIL) exception gives error. - */ - public function get_valid_sections() { - if($this->isInitialized === true) { - if(is_array($this->configSections) && count($this->configSections)) { - $retval = $this->configSections; - } - else { - throw new exception(__METHOD__ .": no sections defined, probably invalid configuration"); - } - } - else { - throw new exception(__METHOD__ .": not initialized"); - } - - return($retval); - }//end get_valid_sections() - //------------------------------------------------------------------------- - -}//end cs_siteConfig - -?> Modified: trunk/0.10/db_types/cs_phpDB__pgsql.class.php =================================================================== --- trunk/0.10/db_types/cs_phpDB__pgsql.class.php 2009-01-26 01:29:21 UTC (rev 324) +++ trunk/0.10/db_types/cs_phpDB__pgsql.class.php 2009-01-26 01:33:48 UTC (rev 325) @@ -136,7 +136,7 @@ $requiredCount = 0; foreach($required as $index) { - if(isset($params[$index]) || $index == 'password') { + if(isset($params[$index])) { $this->$index = $params[$index]; $requiredCount++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |