Skip to content

Commit

Permalink
add is function to test against particular type
Browse files Browse the repository at this point in the history
  • Loading branch information
netcode committed Nov 26, 2016
1 parent 6e71747 commit 984f509
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ $type = (new \Shieldfy\Sniffer\Sniffer)->sniff(serialize(['hello'=>1,'world'=>'!
//you can add more than value as array
$type = (new \Shieldfy\Sniffer\Sniffer)->sniff(['555','abc']);

//test against particular type
$result = (new \Shieldfy\Sniffer\Sniffer)->sniff('123456789','number'); //true

//you can register your own sniffer on the runtime
$type = (new \Shieldfy\Sniffer\Sniffer)->register('hello',function($input){
if(strstr($input,'hello'))
Expand Down
15 changes: 15 additions & 0 deletions src/Sniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ public function sniff($input)
return $this->run($input);
}

/**
* test against particular type
*
* @param mixed $input
*
* @return boolean
*/
public function is($input,$type)
{
if(!isset($this->types[$type]))
throw new \Exception("Type Not found use one of supported types ( ".implode(' , ',array_keys($this->types))." )");
$typeClass = $this->types[$type];
return (new $typeClass())->sniff($input);
}

/**
* Start Sniffing array.
*
Expand Down

0 comments on commit 984f509

Please sign in to comment.