Skip to content

Commit

Permalink
Update Codes.php
Browse files Browse the repository at this point in the history
  • Loading branch information
nimasdj committed Dec 15, 2015
1 parent bd1ffb6 commit ff22dc1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ public static function isValid($code)
{
return isset(static::$countries[strtoupper($code)]);
}


// kept for backward compatibility. Use countrySelector() method for better naming.
public static function select($class = '', $name = 'country', $selected = null)
{
return sprintf('<select class="%s" name="%s">', $class, $name)
Expand All @@ -555,4 +556,17 @@ public static function select($class = '', $name = 'country', $selected = null)
}, static::$countries, array_keys(static::$countries)))
. '</select>';
}

// same as select() method but better naming.
public static function countrySelector($class = '', $name = 'country', $selected = null)
{
return sprintf('<select class="%s" name="%s">', $class, $name)
. implode(array_map(function($country, $code) use($selected) {
return ($code == $selected)
? sprintf('<option value="%s" selected>%s</option>', $code, $country)
: sprintf('<option value="%s">%s</option>', $code, $country);
}, static::$countries, array_keys(static::$countries)))
. '</select>';
}

}

0 comments on commit ff22dc1

Please sign in to comment.