Webfan

- Application Composer

create websites, developing projects,
compose applications

View the Project on GitHub frdl/webfan

Documentation/Components/webdof\valFormats

<?php
/**
 *   example.php
 */
highlight_file(__FILE__);
require 
'valFormats.php';
webdof\valFormats::create() 
      -> 
test()
 ;      
 
 
/**
  * ...outputs...
  */

Testing webdof\valFormats

The following example code
- adds rules dynamically (NOTE: The added rule overwrites the built in method if exists),
- and validate some tests:
    
1
2
3
4
5
6
7
8
9
10
11
<?php
$TEST 
= \webdof\valFormats::create(true,true)
 ->
addRule('url.API-D''(http|https)\:\/\/interface\.api\.webfan\.de\/v([0-9]+)\/(public|i[0-9]+)\/software\/class\/frdl\/([\w\.]+)\/source\.php')
 ->
addRule('me'"Jon Doe"true)
 ->
addRule('me.mention'"/Jon Doe/i"false)
 ->
addRule('url.www.phpclasses.org', function($in){
              
$r = \webdof\valFormats::is($in,'url'); return (false !== $r && isset($r['host']) && $r['host'] === 'www.phpclasses.org') ? true false;
    });    

echo 
print_r($TEST->is('A string with JON doe' 'me'), true)."\r\n";             //false
echo print_r($TEST->is('A string with JON doe' 'me.mention'), true)."\r\n";     //true
echo print_r($TEST->is('Jon Doe' 'me'), true);                                   //true
Outputs: 1 1 VALIDATE METHODS (summary): Array ( [address] => built in [base64] => built in [byte] => Dynamically added [byte.unsigned] => Dynamically added [csscolor] => built in [cssposition] => built in [csspositionlength] => built in [csspositionlengthcolor] => built in [csstextalign] => built in [cssverticalalign] => built in [double] => Dynamically added [double.unsigned] => Dynamically added [endingwiths] => built in [even] => Dynamically added [filename] => built in [float] => Dynamically added [fullname] => built in [gerade] => Dynamically added [impolite] => Dynamically added [int] => built in [integer.int16_t] => Dynamically added [integer.int32_t] => Dynamically added [integer.int64_t] => Dynamically added [integer.int8_t] => Dynamically added [integer.uint16_t] => Dynamically added [integer.uint32_t] => Dynamically added [integer.uint64_t] => Dynamically added [integer.uint8_t] => Dynamically added [ip] => built in [long] => Dynamically added [long.unsigned] => Dynamically added [mail] => built in [md5] => built in [me] => Dynamically added [me.mention] => Dynamically added [name] => built in [odd] => Dynamically added [oid] => built in [oid.pen] => Dynamically added [oid.weid] => Dynamically added [prime] => Dynamically added [primzahl] => Dynamically added [sha1] => built in [ungerade] => Dynamically added [url] => built in [url.API-D] => Dynamically added [url.www.phpclasses.org] => Dynamically added [uuid] => built in [uuid.DCE] => Dynamically added [uuid.namebased.md5] => Dynamically added [uuid.namebased.sha1] => Dynamically added [uuid.random] => Dynamically added [uuid.timebased] => Dynamically added [uuidversion] => built in [word] => Dynamically added [word.unsigned] => Dynamically added ) FORMATTING METHODS: webdof\valFormats::from2to From To Method camelcase whitespace _camelcase2whitespace string camelcase _string2camelcase ip long _ip2long ip long_v4 _ip2long_v4 ip long_v6 _ip2long_v6 long ip_v6 _long2ip_v6 TESTING SOME STRINGS: Test STRICT: $TEST->is('Any U&$tring% with $ome noise: *+~#'"hello world"'); - not validated successfully Try NONE-STRICT: $TEST->is('Any U&$tring% with $ome noise: *+~#'"hello world"', null, false); - not validated successfully Test STRICT: $TEST->is('http://www.phpclasses.org/package/8412-PHP-Validate-string-values-in-different-formats.html'); Array ( [url.www.phpclasses.org] => OK [url] => Array ( [scheme] => http [host] => www.phpclasses.org [path] => /package/8412-PHP-Validate-string-values-in-different-formats.html ) ) Test STRICT: $TEST->is('http://interface.api.webfan.de/v1/public/software/class/frdl/webdof.valFormats/source.php'); Array ( [url.API-D] => OK [url] => Array ( [scheme] => http [host] => interface.api.webfan.de [path] => /v1/public/software/class/frdl/webdof.valFormats/source.php ) ) Test STRICT: $TEST->is('php.support@webfan.de'); Array ( [mail] => OK ) Test STRICT: $TEST->is('Till Wehowski'); Array ( [fullname] => OK [name] => OK ) Test STRICT: $TEST->is('Herr Dr. Otto Mueller (MdB)'); Array ( [fullname] => OK [name] => OK ) Test STRICT: $TEST->is('Dr. Otto Mueller, jr.'); Array ( [fullname] => OK [name] => OK ) Test STRICT: $TEST->is('Frau Emma Meyer'); Array ( [fullname] => OK [name] => OK ) Test STRICT: $TEST->is('Wattenscheiderstraße 59'); Array ( [address] => OK ) Test STRICT: $TEST->is('1.3.6.1.4.1.0'); Array ( [oid.pen] => OK [oid] => OK ) Test STRICT: $TEST->is('1.3.6.1.4.1.37553.8.1.8.8'); Array ( [oid.pen] => OK [oid.weid] => OK [oid] => OK ) Test STRICT: $TEST->is('8e1441db-9bbd-4d29-ba06-3d797b63b5b6'); Array ( [uuid.random] => OK [uuid] => OK [uuidversion] => 4 ) Test STRICT: $TEST->is('ffffff9a-1e7d-5547-8ede-5aee3c939a37'); Array ( [uuid.namebased.sha1] => OK [uuid] => OK [uuidversion] => 5 ) Test STRICT: $TEST->is('ffffff9a-1e7d-9547-8ede-5aee3c939a37'); - not validated successfully Try NONE-STRICT: $TEST->is('ffffff9a-1e7d-9547-8ede-5aee3c939a37', null, false); Array ( [uuidversion] => 9 ) Test STRICT: $TEST->is('d41d8cd98f00b204e9800998ecf8427e'); Array ( [base64] => OK [md5] => OK ) Test STRICT: $TEST->is('da39a3ee5e6b4b0d3255bfef95601890afd80709'); Array ( [base64] => OK [sha1] => OK ) Test STRICT: $TEST->is('16px'); Array ( [base64] => OK [csspositionlength] => OK ) Test STRICT: $TEST->is('9em'); Array ( [csspositionlength] => OK ) Test STRICT: $TEST->is('blue'); Array ( [base64] => OK [csspositionlengthcolor] => OK [csscolor] => OK ) Test STRICT: $TEST->is('center'); Array ( [csstextalign] => OK ) Test STRICT: $TEST->is('middle'); Array ( [cssverticalalign] => OK ) Test STRICT: $TEST->is('fixed'); Array ( [cssposition] => OK ) Test STRICT: $TEST->is('127.0.0.1'); Array ( [oid] => OK [ip] => ipv4 ) Test STRICT: $TEST->is('93.184.216.34'); Array ( [oid] => OK [ip] => ipv4 ) Test STRICT: $TEST->is('2001:0db8:0000:08d3:0000:8a2e:0070:7344'); Array ( [ip] => ipv6 ) Test STRICT: $TEST->is('OTAwMTZ0ZXN0LmZyZWl6ZWl0dHJlZmZlbi5kZXRlc3QxMjMweDAw'); Array ( [base64] => OK ) Test STRICT: $TEST->is('TXkgU3RyaW5nIDEyMzQ1Njc4OTA='); Array ( [base64] => OK ) Test STRICT: $TEST->is('~test1-123.zip'); Array ( [filename] => OK ) Test STRICT: $TEST->is('97'); Array ( [integer.int8_t] => OK [byte] => OK [integer.uint8_t] => OK [byte.unsigned] => OK [integer.int16_t] => OK [word] => OK [integer.uint16_t] => OK [word.unsigned] => OK [integer.int32_t] => OK [double] => OK [integer.uint32_t] => OK [double.unsigned] => OK [integer.int64_t] => OK [long] => OK [integer.uint64_t] => OK [long.unsigned] => OK [odd] => OK [prime] => OK [ungerade] => OK [primzahl] => OK [int] => OK [oid] => OK ) Test STRICT: $TEST->is('3.5'); Array ( [float] => OK [oid] => OK ) Test STRICT: $TEST->is('65535'); Array ( [integer.uint16_t] => OK [word.unsigned] => OK [integer.int32_t] => OK [double] => OK [integer.uint32_t] => OK [double.unsigned] => OK [integer.int64_t] => OK [long] => OK [integer.uint64_t] => OK [long.unsigned] => OK [odd] => OK [ungerade] => OK [int] => OK [oid] => OK ) Test STRICT: $TEST->is('-2147483648'); Array ( [integer.int32_t] => OK [double] => OK [integer.int64_t] => OK [long] => OK [even] => OK [gerade] => OK [int] => OK ) Test STRICT: $TEST->is('-129'); Array ( [integer.int16_t] => OK [word] => OK [integer.int32_t] => OK [double] => OK [integer.int64_t] => OK [long] => OK [odd] => OK [ungerade] => OK [int] => OK ) Test STRICT: $TEST->is('-128'); Array ( [integer.int8_t] => OK [byte] => OK [integer.int16_t] => OK [word] => OK [integer.int32_t] => OK [double] => OK [integer.int64_t] => OK [long] => OK [even] => OK [gerade] => OK [int] => OK ) Test STRICT: $TEST->is('10000000097'); Array ( [integer.int64_t] => OK [long] => OK [integer.uint64_t] => OK [long.unsigned] => OK [odd] => OK [prime] => OK [ungerade] => OK [primzahl] => OK [int] => OK [oid] => OK ) Test STRICT: $TEST->is('10000000098'); Array ( [integer.int64_t] => OK [long] => OK [integer.uint64_t] => OK [long.unsigned] => OK [even] => OK [gerade] => OK [int] => OK [oid] => OK ) Test STRICT: $TEST->is('A sexy sentence by a porn spammer asshole...'); Array ( [impolite] => OK [name] => OK [filename] => OK ) Test STRICT: $TEST->is('Otto Müller'); Array ( [fullname] => OK [name] => OK ) Test STRICT: $TEST->is('dölfkltgß5 ö4ü359'); - not validated successfully Try NONE-STRICT: $TEST->is('dölfkltgß5 ö4ü359', null, false); - not validated successfully Test STRICT: $TEST->is('Müller, Otto'); Array ( [fullname] => OK [name] => OK ) Test STRICT: $TEST->is('z435 j4894 rk ftz'); - not validated successfully Try NONE-STRICT: $TEST->is('z435 j4894 rk ftz', null, false); - not validated successfully Test STRICT: $TEST->is('1234 Müller'); - not validated successfully Try NONE-STRICT: $TEST->is('1234 Müller', null, false); - not validated successfully TESTING MISC.:
1
2
3
4
5
6
7
<?php
echo print_r($TEST->is('8e1441db-9bbd-4d29-ba06-3d797b63b5b6','uuidversion',true), true)."
"
;
 echo 
print_r($TEST->is('8e1441db-9bbd-zd29-ba06-3d797b63b5b6','uuidversion',true), true)."
"
;
 echo 
print_r($TEST->is('8e1441db-9bbd-zd29-ba06-3d797b63b5b6','uuidversion',false), true)."
"
;
Outputs: 4 z
1
2
3
4
5
<?php
echo print_r($TEST->ip2long('fe80:0:0:0:202:b3ff:fe1e:8329'), true);
 echo 
"
"
;     
 echo 
print_r($TEST->ip2long('93.184.216.34'), true);
Outputs: Array ( [version] => ipv6 [int] => 338288524927261089654163772891438416681 ) Array ( [version] => ipv4 [int] => 1572395042 )
1
2
<?php
echo print_r($TEST->long2ip_v6('338288524927261089654163772891438416681'), true);
Outputs:
1
2
3
4
5
6
<?php
$teststring 
'MyCamelCasedString';
 echo 
$TEST->camelcase2whitespace($teststring);
 echo 
"
"
;     
 echo 
$TEST->camelcase2whitespace($teststring"_");
Outputs: My Camel Cased String My_Camel_Cased_String
1
2
3
4
5
<?php
$teststring 
'My Camel-Cased Test_string';
 echo 
$TEST->str2CamelCase($teststring)."
"
;
 echo 
$TEST->string2CamelCase('font-size');
Outputs: MyCamelCasedTestString fontSize