Reconsider versioning system, use major, minor and patch versions

namespaces
falcon 2012-12-04 22:26:20 +01:00
parent a3045646cb
commit 19665aba5a
1 changed files with 29 additions and 16 deletions

View File

@ -6,11 +6,11 @@ interface h5pFramework {
public function getUploadedH5pFolderPath(); public function getUploadedH5pFolderPath();
public function getH5pPath(); public function getH5pPath();
public function getUploadedH5pPath(); public function getUploadedH5pPath();
public function isStoredLibrary($machineName, $minimumVersion); public function isStoredLibrary($machineName, $majorVersion, $minorVersion);
public function storeLibraryData(&$libraryData); public function storeLibraryData(&$libraryData);
public function storeContentData($contentId, $contentJson, $mainJsonData); public function storeContentData($contentId, $contentJson, $mainJsonData);
public function saveLibraryUsage($contentId, $librariesInUse); public function saveLibraryUsage($contentId, $librariesInUse);
public function loadLibrary($machineName, $minimumVersion); public function loadLibrary($machineName, $majorVersion, $minorVersion);
} }
class h5pValidator { class h5pValidator {
@ -20,11 +20,11 @@ class h5pValidator {
// Schemas used to validate the h5p files // Schemas used to validate the h5p files
private $h5pRequired = array( private $h5pRequired = array(
'title' => '/^.{1,255}$/', 'title' => '/^.{1,255}$/',
'majorVersion' => '/^[0-9]{1,5}$/',
'language' => '/^[a-z]{1,5}$/', 'language' => '/^[a-z]{1,5}$/',
'preloadedDependencies' => array( 'preloadedDependencies' => array(
'machineName' => '/^[a-z0-9\-]{1,255}$/i', 'machineName' => '/^[a-z0-9\-]{1,255}$/i',
'minimumVersion' => '/^[0-9]{1,5}$/', 'majorVersion' => '/^[0-9]{1,5}$/',
'minorVersion' => '/^[0-9]{1,5}$/',
), ),
'init' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', 'init' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i',
'embedTypes' => array('iframe', 'div'), 'embedTypes' => array('iframe', 'div'),
@ -33,12 +33,12 @@ class h5pValidator {
private $h5pOptional = array( private $h5pOptional = array(
'contentType' => '/^.{1,255}$/', 'contentType' => '/^.{1,255}$/',
'description' => '/^.{1,}$/', 'description' => '/^.{1,}$/',
'minorVersion' => '/^[0-9]{1,5}$/',
'author' => '/^.{1,255}$/', 'author' => '/^.{1,255}$/',
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr)$/', 'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr)$/',
'dynamicDependencies' => array( 'dynamicDependencies' => array(
'machineName' => '/^[a-z0-9\-]{1,255}$/i', 'machineName' => '/^[a-z0-9\-]{1,255}$/i',
'minimumVersion' => '/^[0-9]{1,5}$/', 'majorVersion' => '/^[0-9]{1,5}$/',
'minorVersion' => '/^[0-9]{1,5}$/',
), ),
'w' => '/^[0-9]{1,4}$/', 'w' => '/^[0-9]{1,4}$/',
'h' => '/^[0-9]{1,4}$/', 'h' => '/^[0-9]{1,4}$/',
@ -50,22 +50,25 @@ class h5pValidator {
private $libraryRequired = array( private $libraryRequired = array(
'title' => '/^.{1,255}$/', 'title' => '/^.{1,255}$/',
'majorVersion' => '/^[0-9]{1,5}$/', 'majorVersion' => '/^[0-9]{1,5}$/',
'minorVersion' => '/^[0-9]{1,5}$/',
'patchVersion' => '/^[0-9]{1,5}$/',
'machineName' => '/^[a-z0-9\-]{1,255}$/i', 'machineName' => '/^[a-z0-9\-]{1,255}$/i',
); );
private $libraryOptional = array( private $libraryOptional = array(
'init' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i', 'init' => '/^[$a-z_][0-9a-z_\.$]{1,254}$/i',
'minorVersion' => '/^[0-9]{1,5}$/',
'author' => '/^.{1,255}$/', 'author' => '/^.{1,255}$/',
'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr)$/', 'license' => '/^(cc-by|cc-by-sa|cc-by-nd|cc-by-nc|cc-by-nc-sa|cc-by-nc-nd|pd|cr)$/',
'description' => '/^.{1,}$/', 'description' => '/^.{1,}$/',
'dynamicDependencies' => array( 'dynamicDependencies' => array(
'machineName' => '/^[a-z0-9\-]{1,255}$/i', 'machineName' => '/^[a-z0-9\-]{1,255}$/i',
'minimumVersion' => '/^[0-9]{1,5}$/', 'majorVersion' => '/^[0-9]{1,5}$/',
'minorVersion' => '/^[0-9]{1,5}$/',
), ),
'preloadedDependencies' => array( 'preloadedDependencies' => array(
'machineName' => '/^[a-z0-9\-]{1,255}$/i', 'machineName' => '/^[a-z0-9\-]{1,255}$/i',
'minimumVersion' => '/^[0-9]{1,5}$/', 'majorVersion' => '/^[0-9]{1,5}$/',
'patchVersion' => '/^[0-9]{1,5}$/',
), ),
'preloadedJs' => array( 'preloadedJs' => array(
'path' => '/^((\\\|\/)?[a-z_\-\s0-9]+)+\.js$/i', 'path' => '/^((\\\|\/)?[a-z_\-\s0-9]+)+\.js$/i',
@ -208,7 +211,7 @@ class h5pValidator {
$libraries['mainH5pData'][] = $mainH5pData; $libraries['mainH5pData'][] = $mainH5pData;
$missingLibraries = $this->getMissingLibraries($libraries); $missingLibraries = $this->getMissingLibraries($libraries);
foreach ($missingLibraries as $missing) { foreach ($missingLibraries as $missing) {
if ($this->h5pF->isStoredLibrary($missing['machineName'], $missing['minimumVersion'])) { if ($this->h5pF->isStoredLibrary($missing['machineName'], $missing['majorVersion'], $missing['minorVersion'])) {
unset($missingLibraries[$missing['machineName']]); unset($missingLibraries[$missing['machineName']]);
} }
} }
@ -227,7 +230,7 @@ class h5pValidator {
* A multidimensional array of libraries keyed with machineName first and majorVersion second * A multidimensional array of libraries keyed with machineName first and majorVersion second
* @return array * @return array
* A list of libraries that are missing keyed with machineName and holds objects with * A list of libraries that are missing keyed with machineName and holds objects with
* machineName and minimumVersion properties * machineName, majorVersion and minorVersion properties
*/ */
private function getMissingLibraries($libraries) { private function getMissingLibraries($libraries) {
$missing = array(); $missing = array();
@ -248,18 +251,18 @@ class h5pValidator {
* the provided list of libraries * the provided list of libraries
* *
* @param array $dependencies * @param array $dependencies
* A list of objects with machineName and minimumVersion properties * A list of objects with machineName, majorVersion and minorVersion properties
* @param array $libraries * @param array $libraries
* A multidimensional array of libraries keyed with machineName first and majorVersion second * A multidimensional array of libraries keyed with machineName first and majorVersion second
* @return * @return
* A list of libraries that are missing keyed with machineName and holds objects with * A list of libraries that are missing keyed with machineName and holds objects with
* machineName and minimumVersion properties * machineName, majorVersion and minorVersion properties
*/ */
private function getMissingDependencies($dependencies, $libraries) { private function getMissingDependencies($dependencies, $libraries) {
$missing = array(); $missing = array();
foreach ($dependencies as $dependency) { foreach ($dependencies as $dependency) {
if (isset($libraries[$dependency['machineName']])) { if (isset($libraries[$dependency['machineName']])) {
if ($libraries[$dependency['machineName']]['minimumVersion'] < $dependency['minimumVersion']) { if ($this->h5pC->isSameVersion($libraries[$dependency['machineName']], $dependency)) {
$missing[$dependency['machineName']] = $dependency; $missing[$dependency['machineName']] = $dependency;
} }
} }
@ -516,7 +519,7 @@ class h5pSaver {
public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE) { public function getLibraryUsage(&$librariesInUse, $jsonData, $dynamic = FALSE) {
if (isset($jsonData['preloadedDependencies'])) { if (isset($jsonData['preloadedDependencies'])) {
foreach ($jsonData['preloadedDependencies'] as $preloadedDependency) { foreach ($jsonData['preloadedDependencies'] as $preloadedDependency) {
$library = $this->h5pF->loadLibrary($preloadedDependency['machineName'], $preloadedDependency['minimumVersion']); $library = $this->h5pF->loadLibrary($preloadedDependency['machineName'], $preloadedDependency['majorVersion'], $preloadedDependency['minorVersion']);
$librariesInUse[$preloadedDependency['machineName']] = array( $librariesInUse[$preloadedDependency['machineName']] = array(
'library' => $library, 'library' => $library,
'preloaded' => $dynamic ? 0 : 1, 'preloaded' => $dynamic ? 0 : 1,
@ -527,7 +530,7 @@ class h5pSaver {
if (isset($jsonData['dynamicDependencies'])) { if (isset($jsonData['dynamicDependencies'])) {
foreach ($jsonData['dynamicDependencies'] as $dynamicDependency) { foreach ($jsonData['dynamicDependencies'] as $dynamicDependency) {
if (!isset($librariesInUse[$dynamicDependency['machineName']])) { if (!isset($librariesInUse[$dynamicDependency['machineName']])) {
$library = $this->h5pF->loadLibrary($dynamicDependency['machineName'], $dynamicDependency['minimumVersion']); $library = $this->h5pF->loadLibrary($dynamicDependency['machineName'], $dynamicDependency['majorVersion'], $dynamicDependency['minorVersion']);
$librariesInUse[$dynamicDependency['machineName']] = array( $librariesInUse[$dynamicDependency['machineName']] = array(
'library' => $library, 'library' => $library,
'preloaded' => 0, 'preloaded' => 0,
@ -554,5 +557,15 @@ class h5pCore {
public function __construct($h5pFramework) { public function __construct($h5pFramework) {
$this->h5pF = $h5pFramework; $this->h5pF = $h5pFramework;
} }
public function isSameVersion($library, $dependency) {
if ($library['majorVersion'] != $dependency['majorVersion']) {
return FALSE;
}
if ($library['minorVersion'] != $dependency['minorVersion']) {
return FALSE;
}
return TRUE;
}
} }
?> ?>