Skip to content

Commit

Permalink
Validate coverage
Browse files Browse the repository at this point in the history
Creates a Validator class to help validate various elements. Currently just a static class that better validates WKT geometry types

references #314 and #288
  • Loading branch information
Wayne Graham committed Jun 18, 2014
1 parent cccdb8d commit 1084eca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion helpers/Coverage.php
Expand Up @@ -19,7 +19,9 @@ function nl_extractWkt($coverage) {
$wkt = null;

// Get coverage format.
$format = geoPHP::detectFormat($coverage);
if (Validator::isValidWkt($coverage)) {
$format = geoPHP::detectFormat($coverage);
}

// Convert / reduce to WKT.
if (in_array($format, array('wkt', 'kml'))) {
Expand Down
29 changes: 29 additions & 0 deletions helpers/Validators.php
@@ -0,0 +1,29 @@
<?php

/**
* Helper classes for validations
*
* @category Utilities
* @package Omeka
* @subpackage Neatline
* @author Scholars' Lab <scholarslab@virginia.edu>
* @copyright 2014 Rector and Board of Visitors, University of Virginia
* @license http://www.apache.org/licenses/LICENSE-2.0.html Apache 2
*/
class Validator
{
/**
* Tests if a given string contains valid WKT
*
* @param string $coverage Coverage string to test
*
* @return boolean if the string is found
*/
static function isValidWkt($coverage)
{
return (bool) preg_match(
'#(point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection)#',
strtolower($coverage)
);
}
}
1 change: 1 addition & 0 deletions plugin.php
Expand Up @@ -43,6 +43,7 @@
require_once NL_DIR.'/helpers/Schemas.php';
require_once NL_DIR.'/helpers/Strings.php';
require_once NL_DIR.'/helpers/Styles.php';
require_once NL_DIR.'/helpers/Validators.php';
require_once NL_DIR.'/helpers/Views.php';

// Vendor:
Expand Down

0 comments on commit 1084eca

Please sign in to comment.