[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[122] trunk/0.3
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-08-20 16:21:57
|
Revision: 122 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=122&view=rev Author: crazedsanity Date: 2009-08-20 16:21:45 +0000 (Thu, 20 Aug 2009) Log Message: ----------- Moved cs_versionAbstract to cs-content, abstract class into abstract folder. NOTE::: as stated in a recent commit to cs-content, moving cs_versionAbstract into the cs-content project means the two projects are not inextricably attached to one another, and that this project is truly an extension of cs-content. Previously, since everything in cs-content required cs_versionAbstract{}, this project would ALWAYS have to be available (which wasn't a problem when cs_versionAbstract{} was in it's own project, "cs-versionparse"). /cs_authToken.class.php: * fix location of cs_webapplibsAbstract. /cs_version.abstract.class.php [MOVED]: * moved to cs-content/abstract/ /cs_webdblogger.class.php: * fix location of cs_webapplibsAbstract. /cs_webdbupgrade.class.php: * fix location of cs_webapplibsAbstract. /tests/testOfCSWebAppLibs.php: * test_version_basics() [DELETED] * test_check_higher() [DELETED] * middleTestClass{} [DELETED] /tests/files/version* [DELETED]: * moved to cs-content for testing cs_versionAbstract Modified Paths: -------------- trunk/0.3/cs_authToken.class.php trunk/0.3/cs_webdblogger.class.php trunk/0.3/cs_webdbupgrade.class.php trunk/0.3/tests/testOfCSWebAppLibs.php Added Paths: ----------- trunk/0.3/abstract/ trunk/0.3/abstract/cs_webapplibs.abstract.class.php Removed Paths: ------------- trunk/0.3/cs_version.abstract.class.php trunk/0.3/cs_webapplibs.abstract.class.php trunk/0.3/tests/files/version1 trunk/0.3/tests/files/version2 trunk/0.3/tests/files/version3 Copied: trunk/0.3/abstract/cs_webapplibs.abstract.class.php (from rev 119, trunk/0.3/cs_webapplibs.abstract.class.php) =================================================================== --- trunk/0.3/abstract/cs_webapplibs.abstract.class.php (rev 0) +++ trunk/0.3/abstract/cs_webapplibs.abstract.class.php 2009-08-20 16:21:45 UTC (rev 122) @@ -0,0 +1,20 @@ +<?php +/* + * Created on Aug 19, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + +require_once(constant('LIBDIR') .'/cs-content/abstract/cs_version.abstract.class.php'); + + +abstract class cs_webapplibsAbstract extends cs_versionAbstract { + +} + +?> Modified: trunk/0.3/cs_authToken.class.php =================================================================== --- trunk/0.3/cs_authToken.class.php 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/cs_authToken.class.php 2009-08-20 16:21:45 UTC (rev 122) @@ -11,7 +11,7 @@ */ -require_once(dirname(__FILE__) .'/cs_webapplibs.abstract.class.php'); +require_once(dirname(__FILE__) .'/abstract/cs_webapplibs.abstract.class.php'); class cs_authToken extends cs_webapplibsAbstract { Deleted: trunk/0.3/cs_version.abstract.class.php =================================================================== --- trunk/0.3/cs_version.abstract.class.php 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/cs_version.abstract.class.php 2009-08-20 16:21:45 UTC (rev 122) @@ -1,398 +0,0 @@ -<?php -/* - * Created on January 01, 2009 by Dan Falconer - * - * SVN INFORMATION::: - * ------------------- - * Last Author::::::::: $Author$ - * Current Revision:::: $Revision$ - * Repository Location: $HeadURL$ - * Last Updated:::::::: $Date$ - */ - -abstract class cs_versionAbstract { - - public $isTest = FALSE; - - - - private $versionFileLocation=null; - private $fullVersionString; - private $suffixList = array( - 'ALPHA', //very unstable - 'BETA', //kinda unstable, but probably useable - 'RC' //all known bugs fixed, searching for unknown ones - ); - - - - abstract public function __construct(); - - - - //========================================================================= - /** - * Retrieve our version string from the VERSION file. - */ - final public function get_version($asArray=false) { - $retval = NULL; - - $this->auto_set_version_file(); - - if(file_exists($this->versionFileLocation)) { - $myMatches = array(); - $findIt = preg_match('/VERSION: (.+)/', file_get_contents($this->versionFileLocation), $matches); - - if($findIt == 1 && count($matches) == 2) { - $fullVersionString = $matches[1]; - $versionInfo = $this->parse_version_string($fullVersionString); - $this->fullVersionString = $this->build_full_version_string($versionInfo); - - - if($asArray) { - $retval = $versionInfo; - $retval['version_string'] = $this->fullVersionString; - } - else { - $retval = $this->build_full_version_string($versionInfo); - } - } - else { - throw new exception(__METHOD__ .": failed to retrieve version string in file " . - "(". $this->versionFileLocation .")"); - } - } - else { - throw new exception(__METHOD__ .": failed to retrieve version information, file " . - "(". $this->versionFileLocation .") does not exist or was not set"); - } - - return($retval); - }//end get_version() - //========================================================================= - - - - //========================================================================= - public function __get($var) { - return($this->$var); - }//end __get() - //========================================================================= - - - - //========================================================================= - final public function get_project() { - $retval = NULL; - $this->auto_set_version_file(); - if(file_exists($this->versionFileLocation)) { - $myMatches = array(); - $findIt = preg_match('/PROJECT: (.+)/', file_get_contents($this->versionFileLocation), $matches); - - if($findIt == 1 && count($matches) == 2 && strlen($matches[1])) { - $retval = $matches[1]; - } - else { - throw new exception(__METHOD__ .": failed to retrieve project string"); - } - } - else { - throw new exception(__METHOD__ .": failed to retrieve project information"); - } - - return($retval); - }//end get_project() - //========================================================================= - - - - //========================================================================= - public function set_version_file_location($location) { - if(file_exists($location)) { - $this->versionFileLocation = $location; - } - else { - throw new exception(__METHOD__ .": invalid location of VERSION file (". $location .")"); - } - }//end set_version_file_location() - //========================================================================= - - - - //========================================================================= - protected function auto_set_version_file() { - if(!strlen($this->versionFileLocation)) { - $bt = debug_backtrace(); - foreach($bt as $callNum=>$data) { - if(strlen($data['class'])) { - if($data['class'] != __CLASS__) { - $dir = dirname($data['file']); - if(preg_match('/tests$/', $dir)) { - $dir = preg_replace('/\/tests$/', '', $dir); - } - elseif(preg_match('/test$/', $dir)) { - $dir = preg_replace('/\/test$/', '', $dir); - } - break; - } - } - else { - throw new exception(__METHOD__ .": failed to locate the calling class in backtrace"); - } - } - - if(file_exists($dir .'/VERSION')) { - $this->set_version_file_location($dir .'/VERSION'); - } - else { - throw new exception(__METHOD__ .": failed to automatically set version file (tried ". $dir ."/VERSION)"); - } - } - }//end auto_set_version_file() - //========================================================================= - - - - //========================================================================= - /** - * - * TODO: add logic to split apart the suffix (i.e. "-ALPHA5" broken into "ALPHA" and "5"). - */ - public function parse_version_string($version) { - if(is_string($version) && strlen($version) && preg_match('/\./', $version)) { - $version = preg_replace('/ /', '', $version); - - $pieces = explode('.', $version); - $retval = array( - 'version_major' => $pieces[0], - 'version_minor' => $pieces[1] - ); - if(isset($pieces[2]) && strlen($pieces[2])) { - $retval['version_maintenance'] = $pieces[2]; - } - else { - $retval['version_maintenance'] = 0; - } - - if(preg_match('/-/', $retval['version_maintenance'])) { - $bits = explode('-', $retval['version_maintenance']); - $retval['version_maintenance'] = $bits[0]; - $suffix = $bits[1]; - } - elseif(preg_match('/-/', $retval['version_minor'])) { - $bits = explode('-', $retval['version_minor']); - $retval['version_minor'] = $bits[0]; - $suffix = $bits[1]; - } - else { - $suffix = ""; - } - $retval['version_suffix'] = $suffix; - } - else { - throw new exception(__METHOD__ .": invalid version string passed (". $version .")"); - } - - return($retval); - }//end parse_version_string() - //========================================================================= - - - - //========================================================================= - public function build_full_version_string(array $versionInfo) { - $requiredIndexes = array( - 'version_major', 'version_minor', 'version_maintenance', 'version_suffix' - ); - - $missing=""; - $count=0; - foreach($requiredIndexes as $indexName) { - if(isset($versionInfo[$indexName])) { - $count++; - } - else { - if(strlen($missing)) { - $missing .= ", ". $indexName; - } - else { - $missing = $indexName; - } - } - } - - if($count == count($requiredIndexes) && !strlen($missing)) { - $suffix = $versionInfo['version_suffix']; - unset($versionInfo['version_suffix']); - - $retval = ""; - foreach($versionInfo as $name=>$value) { - if(strlen($retval)) { - $retval .= ".". $value; - } - else { - $retval = $value; - } - } - if(strlen($suffix)) { - $retval .= "-". $suffix; - } - } - else { - throw new exception(__METHOD__ .": missing indexes in given array (". $missing .")"); - } - - return($retval); - - }//end build_full_version_string() - //========================================================================= - - - - //========================================================================= - public function is_higher_version($version, $checkIfHigher) { - $retval = FALSE; - $this->gfObj = new cs_globalFunctions; - if(!is_string($version) || !is_string($checkIfHigher)) { - throw new exception(__METHOD__ .": no valid version strings, version=(". $version ."), checkIfHigher=(". $checkIfHigher .")"); - } - elseif($version == $checkIfHigher) { - $retval = FALSE; - } - else { - $curVersionArr = $this->parse_version_string($version); - $checkVersionArr = $this->parse_version_string($checkIfHigher); - - unset($curVersionArr['version_string'], $checkVersionArr['version_string']); - - - $curVersionSuffix = $curVersionArr['version_suffix']; - $checkVersionSuffix = $checkVersionArr['version_suffix']; - - - unset($curVersionArr['version_suffix']); - - foreach($curVersionArr as $index=>$versionNumber) { - $checkThis = $checkVersionArr[$index]; - - if(is_numeric($checkThis) && is_numeric($versionNumber)) { - //set them as integers. - settype($versionNumber, 'int'); - settype($checkThis, 'int'); - - if($checkThis > $versionNumber) { - $retval = TRUE; - break; - } - elseif($checkThis == $versionNumber) { - //they're equal... - } - else { - //TODO: should there maybe be an option to throw an exception (freak out) here? - } - } - else { - throw new exception(__METHOD__ .": ". $index ." is not numeric in one of the strings " . - "(versionNumber=". $versionNumber .", checkThis=". $checkThis .")"); - } - } - - //now deal with those damnable suffixes, but only if the versions are so far identical: if - // the "$checkIfHigher" is actually higher, don't bother (i.e. suffixes don't matter when - // we already know there's a major, minor, or maintenance version that's also higher. - if($retval === FALSE) { - //EXAMPLE: $version="1.0.0-BETA3", $checkIfHigher="1.1.0" - // Moving from a non-suffixed version to a suffixed version isn't supported, but the inverse is: - // i.e. (1.0.0-BETA3 to 1.0.0) is okay, but (1.0.0 to 1.0.0-BETA3) is NOT. - // Also: (1.0.0-BETA3 to 1.0.0-BETA4) is okay, but (1.0.0-BETA4 to 1.0.0-BETA3) is NOT. - if(strlen($curVersionSuffix) && strlen($checkVersionSuffix) && $curVersionSuffix == $checkVersionSuffix) { - //matching suffixes. - } - elseif(strlen($curVersionSuffix) || strlen($checkVersionSuffix)) { - //we know the suffixes are there and DO match. - if(strlen($curVersionSuffix) && strlen($checkVersionSuffix)) { - //okay, here's where we do some crazy things... - $curVersionData = $this->parse_suffix($curVersionSuffix); - $checkVersionData = $this->parse_suffix($checkVersionSuffix); - - if($curVersionData['type'] == $checkVersionData['type']) { - //got the same suffix type (like "BETA"), check the number. - if($checkVersionData['number'] > $curVersionData['number']) { - //new version's suffix number higher than current... - $retval = TRUE; - } - elseif($checkVersionData['number'] == $curVersionData['number']) { - //new version's suffix number is EQUAL TO current... - $retval = FALSE; - } - else { - //new version's suffix number is LESS THAN current... - $retval = FALSE; - } - } - else { - //not the same suffix... see if the new one is higher. - $suffixValues = array_flip($this->suffixList); - if($suffixValues[$checkVersionData['type']] > $suffixValues[$curVersionData['type']]) { - $retval = TRUE; - } - else { - //current suffix type is higher... - } - } - - } - elseif(strlen($curVersionSuffix) && !strlen($checkVersionSuffix)) { - //i.e. "1.0.0-BETA1" to "1.0.0" --->>> OKAY! - $retval = TRUE; - } - elseif(!strlen($curVersionSuffix) && strlen($checkVersionSuffix)) { - //i.e. "1.0.0" to "1.0.0-BETA1" --->>> NOT ACCEPTABLE! - } - } - else { - //no suffix to care about - } - } - } - - return($retval); - - }//end is_higher_version() - //========================================================================= - - - - //========================================================================= - protected function parse_suffix($suffix) { - $retval = NULL; - if(strlen($suffix)) { - //determine what kind it is. - foreach($this->suffixList as $type) { - if(preg_match('/^'. $type .'/', $suffix)) { - $checkThis = preg_replace('/^'. $type .'/', '', $suffix); - if(strlen($checkThis) && is_numeric($checkThis)) { - //oooh... it's something like "BETA3" - $retval = array( - 'type' => $type, - 'number' => $checkThis - ); - } - else { - throw new exception(__METHOD__ .": invalid suffix (". $suffix .")"); - } - break; - } - } - } - else { - throw new exception(__METHOD__ .": invalid suffix (". $suffix .")"); - } - - return($retval); - }//end parse_suffix() - //========================================================================= - - -} -?> \ No newline at end of file Deleted: trunk/0.3/cs_webapplibs.abstract.class.php =================================================================== --- trunk/0.3/cs_webapplibs.abstract.class.php 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/cs_webapplibs.abstract.class.php 2009-08-20 16:21:45 UTC (rev 122) @@ -1,20 +0,0 @@ -<?php -/* - * Created on Aug 19, 2009 - * - * SVN INFORMATION::: - * ------------------- - * Last Author::::::::: $Author$ - * Current Revision:::: $Revision$ - * Repository Location: $HeadURL$ - * Last Updated:::::::: $Date$ - */ - -require_once(dirname(__FILE__) .'/cs_version.abstract.class.php'); - - -abstract class cs_webapplibsAbstract extends cs_versionAbstract { - -} - -?> Modified: trunk/0.3/cs_webdblogger.class.php =================================================================== --- trunk/0.3/cs_webdblogger.class.php 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/cs_webdblogger.class.php 2009-08-20 16:21:45 UTC (rev 122) @@ -27,7 +27,7 @@ //NOTE::: this class **REQUIRES** cs-content for its "cs_phpDB" class. -require_once(dirname(__FILE__) .'/cs_webapplibs.abstract.class.php'); +require_once(dirname(__FILE__) .'/abstract/cs_webapplibs.abstract.class.php'); require_once(dirname(__FILE__) .'/cs_webdbupgrade.class.php'); class cs_webdblogger extends cs_webapplibsAbstract { Modified: trunk/0.3/cs_webdbupgrade.class.php =================================================================== --- trunk/0.3/cs_webdbupgrade.class.php 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/cs_webdbupgrade.class.php 2009-08-20 16:21:45 UTC (rev 122) @@ -12,7 +12,7 @@ * */ -require_once(dirname(__FILE__) .'/cs_webapplibs.abstract.class.php'); +require_once(dirname(__FILE__) .'/abstract/cs_webapplibs.abstract.class.php'); require_once(dirname(__FILE__) .'/cs_webdblogger.class.php'); class cs_webdbupgrade extends cs_webapplibsAbstract { Deleted: trunk/0.3/tests/files/version1 =================================================================== --- trunk/0.3/tests/files/version1 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/tests/files/version1 2009-08-20 16:21:45 UTC (rev 122) @@ -1,3 +0,0 @@ - -PROJECT: test1 -VERSION: 0.1.2-ALPHA8754 \ No newline at end of file Deleted: trunk/0.3/tests/files/version2 =================================================================== --- trunk/0.3/tests/files/version2 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/tests/files/version2 2009-08-20 16:21:45 UTC (rev 122) @@ -1,3 +0,0 @@ - -PROJECT: test2 -VERSION: 5.4 \ No newline at end of file Deleted: trunk/0.3/tests/files/version3 =================================================================== --- trunk/0.3/tests/files/version3 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/tests/files/version3 2009-08-20 16:21:45 UTC (rev 122) @@ -1,3 +0,0 @@ - -PROJECT: test3 stuff -VERSION: 5.4.3-BETA5543 \ No newline at end of file Modified: trunk/0.3/tests/testOfCSWebAppLibs.php =================================================================== --- trunk/0.3/tests/testOfCSWebAppLibs.php 2009-08-20 15:52:11 UTC (rev 121) +++ trunk/0.3/tests/testOfCSWebAppLibs.php 2009-08-20 16:21:45 UTC (rev 122) @@ -11,7 +11,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) .'/../cs_version.abstract.class.php'); require_once(dirname(__FILE__) .'/../cs_authToken.class.php'); class testOfCSWebAppLibs extends UnitTestCase { @@ -24,108 +23,8 @@ //-------------------------------------------------------------------------- - //-------------------------------------------------------------------------- - function test_version_basics() { - - $tests = array( - 'files/version1' => array( - '0.1.2-ALPHA8754', - 'test1', - array( - 'version_major' => 0, - 'version_minor' => 1, - 'version_maintenance' => 2, - 'version_suffix' => 'ALPHA8754' - ) - ), - 'files/version2' => array( - '5.4.0', - 'test2', - array( - 'version_major' => 5, - 'version_minor' => 4, - 'version_maintenance' => 0, - 'version_suffix' => null - ) - ), - 'files/version3' => array( - '5.4.3-BETA5543', - 'test3 stuff', - array( - 'version_major' => 5, - 'version_minor' => 4, - 'version_maintenance' => 3, - 'version_suffix' => 'BETA5543' - ) - ) - ); - - foreach($tests as $fileName=>$expectedArr) { - $ver = new middleTestClass(); - $ver->set_version_file_location(dirname(__FILE__) .'/'. $fileName); - - $this->assertEqual($expectedArr[0], $ver->get_version(), "Failed to match string from file (". $fileName .")"); - $this->assertEqual($expectedArr[1], $ver->get_project(), "Failed to match project from file (". $fileName .")"); - - //now check that pulling the version as an array is the same... - $checkItArr = $ver->get_version(true); - $expectThis = $expectedArr[2]; - $expectThis['version_string'] = $expectedArr[0]; - } - }//end test_version_basics() - //-------------------------------------------------------------------------- - - //-------------------------------------------------------------------------- - function test_check_higher() { - - //NOTE: the first item should ALWAYS be higher. - $tests = array( - 'basic, no suffix' => array('1.0.1', '1.0.0'), - 'basic + suffix' => array('1.0.0-ALPHA1', '1.0.0-ALPHA0'), - 'basic w/o maint' => array('1.0.1', '1.0'), - 'suffix check' => array('1.0.0-BETA1', '1.0.0-ALPHA1'), - 'suffix check2' => array('1.0.0-ALPHA10', '1.0.0-ALPHA1'), - 'suffix check3' => array('1.0.1', '1.0.0-RC1') - ); - - foreach($tests as $name=>$checkData) { - $ver = new middleTestClass; - $this->assertTrue($ver->is_higher_version($checkData[1], $checkData[0])); - $this->assertFalse($ver->is_higher_version($checkData[0], $checkData[1])); - } - - //now check to ensure there's no problem with parsing equivalent versions. - $tests = array( - 'no suffix' => array('1.0', '1.0.0'), - 'no maint + suffix' => array('1.0-ALPHA1', '1.0.0-ALPHA1'), - 'no maint + BETA' => array('1.0-BETA5555', '1.0.0-BETA5555'), - 'no maint + RC' => array('1.0-RC33', '1.0.0-RC33'), - 'maint with space' => array('1.0-RC 33', '1.0.0-RC33'), - 'extra spaces' => array(' 1.0 ', '1.0.0') - ); - foreach($tests as $name=>$checkData) { - $ver = new middleTestClass; - - //rip apart & recreate first version to test against the expected... - $derivedFullVersion = $ver->build_full_version_string($ver->parse_version_string($checkData[0])); - $this->assertEqual($derivedFullVersion, $checkData[1], "TEST=(". $name ."): derived version " . - "(". $derivedFullVersion .") doesn't match expected (". $checkData[1] .")"); - - //now rip apart & recreate the expected version (second) and make sure it matches itself. - $derivedFullVersion = $ver->build_full_version_string($ver->parse_version_string($checkData[1])); - $this->assertEqual($derivedFullVersion, $checkData[1], "TEST=(". $name ."): derived version " . - "(". $derivedFullVersion .") doesn't match expected (". $checkData[1] .")"); - } - - - }//end test_check_higher() - //-------------------------------------------------------------------------- - - - - //-------------------------------------------------------------------------- private function create_dbconn() { $dbParams = array( 'host' => constant('DB_PG_HOST'), @@ -249,10 +148,6 @@ } -class middleTestClass extends cs_versionAbstract { - function __construct(){} -} - class authTokenTester extends cs_authToken { public $isTest=true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |