[pLog-svn] r5808 - in plog/trunk/class: data/validator test/tests/data/validator
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Aug 8 16:36:29 EDT 2007
Author: oscar
Date: 2007-08-08 16:36:29 -0400 (Wed, 08 Aug 2007)
New Revision: 5808
Added:
plog/trunk/class/data/validator/filenamematchvalidator.class.php
plog/trunk/class/test/tests/data/validator/filenamematchvalidator_test.class.php
Log:
Validator class that returns true if the given file name matches with one of the given patterns.
Added: plog/trunk/class/data/validator/filenamematchvalidator.class.php
===================================================================
--- plog/trunk/class/data/validator/filenamematchvalidator.class.php (rev 0)
+++ plog/trunk/class/data/validator/filenamematchvalidator.class.php 2007-08-08 20:36:29 UTC (rev 5808)
@@ -0,0 +1,35 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/data/validator/validator.class.php" );
+
+ /**
+ * \ingroup Validator
+ *
+ * Validator class that returns true if the given file name
+ * matches with one of the given patterns
+ */
+ class FileNameMatchValidator extends Validator
+ {
+ private $_patterns;
+
+ function FileNameMatchValidator( $filePatterns = Array())
+ {
+ $this->Validator();
+
+ if( is_string( $filePatterns ))
+ $this->_patterns = explode( ' ', $filePatterns );
+ else
+ $this->_patterns = $filePatterns;
+ }
+
+ function validate( $file )
+ {
+ foreach( $this->_patterns as $pattern ) {
+ if( Glob::fnmatch( $pattern, $file ))
+ return( true );
+ }
+
+ return( false );
+ }
+ }
+?>
\ No newline at end of file
Added: plog/trunk/class/test/tests/data/validator/filenamematchvalidator_test.class.php
===================================================================
--- plog/trunk/class/test/tests/data/validator/filenamematchvalidator_test.class.php (rev 0)
+++ plog/trunk/class/test/tests/data/validator/filenamematchvalidator_test.class.php 2007-08-08 20:36:29 UTC (rev 5808)
@@ -0,0 +1,34 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/validator/filenamematchvalidator.class.php" );
+
+ /**
+ * \ingroup Test
+ *
+ * Test case for the FileNameValidator class
+ */
+ class FileNameMatchValidator_Test extends LifeTypeTestCase
+ {
+ /**
+ * Empty list of patterns, everything should go through
+ */
+ function testEmpty()
+ {
+ $v = new FileNameMatchValidator();
+ $this->assertFalse( $v->validate( "whatever" ));
+ $this->assertFalse( $v->validate( "whatever-goes-through.php" ));
+ }
+
+ function testValidate()
+ {
+ $v = new FileNameMatchValidator( "*.template *.js *.css" );
+ $this->assertFalse( $v->validate( "test.txt" ));
+ $this->assertFalse( $v->validate( "test.phpa" ));
+ $this->assertTrue( $v->validate( "test.js" ));
+ $this->assertTrue( $v->validate( "test.template" ));
+ $this->assertTrue( $v->validate( "test.css" ));
+ $this->assertTrue( $v->validate( "test.js" ));
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list