Permalink
Browse files

always set str to lower case on prefix (and coding standard)

  • Loading branch information...
1 parent e3264fb commit 8ca896336ac18bb24588e2264ce9d8dfbc8c837c @white-gecko white-gecko committed Jan 17, 2013
Showing with 7 additions and 6 deletions.
  1. +7 −6 library/Erfurt/Namespaces.php
@@ -2,7 +2,7 @@
/**
* This file is part of the {@link http://erfurt-framework.org Erfurt} project.
*
- * @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
+ * @copyright Copyright (c) 2013, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
@@ -157,8 +157,8 @@ public function deleteNamespacePrefix($graph, $prefix)
{
$graphPrefixes = $this->getNamespacesForGraph($graph);
- if (array_key_exists($prefix, $graphPrefixes)) {
- unset($graphPrefixes[$prefix]);
+ if (array_key_exists(strtolower($prefix), $graphPrefixes)) {
+ unset($graphPrefixes[strtolower($prefix)]);
}
$this->setNamespacesForGraph($graph, $graphPrefixes);
@@ -298,7 +298,8 @@ public function setNamespacesForGraph($graph, $namespaces = null)
} catch (Erfurt_Exception $e) {
require_once 'Erfurt/Namespaces/Exception.php';
throw new Erfurt_Namespaces_Exception(
- "Insufficient privileges to edit namespace prefixes for graph '$graph'.");
+ 'Insufficient privileges to edit namespace prefixes for graph "' . $graph . '".'
+ );
}
}
@@ -312,7 +313,7 @@ public function hasNamespaceByPrefix($graph, $prefix)
{
$graphPrefixes = $this->getNamespacesForGraph($graph);
- if (array_key_exists($prefix, $graphPrefixes)) {
+ if (array_key_exists(strtolower($prefix), $graphPrefixes)) {
return true;
} else {
return false;
@@ -331,7 +332,7 @@ public function getNamespaceByPrefix($graph, $prefix)
throw new Erfurt_Namespaces_Exception('The given namespace prefix is not registered.');
} else {
$graphPrefixes = $this->getNamespacesForGraph($graph);
- return $graphPrefixes[$prefix];
+ return $graphPrefixes[strtolower($prefix)];
}
}
}

2 comments on commit 8ca8963

@seebi
Member
seebi commented on 8ca8963 Jan 22, 2013

Hi nate, do you have any reason for this change?

@white-gecko
Member

Yes, because I imported some namespace prefixes wit the following code:

if (!$model->hasNamespaceByPrefix($prefix)) {
    $model->addNamespacePrefix($prefix, $namespace);
}

But my prefixes sometimes had upper letters (e.g. "aairAtom") and hasNamespaceByPrefix answered me that the prefix doesn't exist, while addNamespacePrefix threw me an Exception "Prefix '$prefix' already exists.".

Because addNamespacePrefix does:

//lowercase prefix always (for best compatibility)
$prefix = strtolower($prefix);

while all the other methods just took the prefix as it came.

Please sign in to comment.