Skip to content

Commit

Permalink
Merge pull request #28 from sameer-shelavale/case-insensitive-constru…
Browse files Browse the repository at this point in the history
…ctor-params

allow case insensitive params in constructor params array
  • Loading branch information
sameer-shelavale committed Aug 3, 2015
2 parents 27008d9 + a2a85e0 commit d23cb63
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/BaseCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ public function generate(){


public function setParams( $options = array() ){

//get all properties of the class and
//make an array with property name as key and lowercase name as value
$properties = [];
foreach( get_class_vars( get_class( $this) ) as $key => $value ){
$properties[ $key ] = strtolower( $key );
}
//check if lowercase of key exists in lowercase properties
foreach( $options as $key => $value ){
if( property_exists( $this, $key ) ){
$this->$key = $value;
if( $prop = array_search( strtolower( $key), $properties ) ){
$this->$prop = $value;
}
}
}
Expand Down

0 comments on commit d23cb63

Please sign in to comment.