FOF30\Utils\StringHelper::toBool PHP Method

toBool() public static method

Convert a string to a boolean.
public static toBool ( string $string ) : boolean
$string string The string.
return boolean The converted string
    public static function toBool($string)
    {
        $string = trim((string) $string);
        $string = strtolower($string);
        if (in_array($string, array(1, 'true', 'yes', 'on', 'enabled'), true)) {
            return true;
        }
        if (in_array($string, array(0, 'false', 'no', 'off', 'disabled'), true)) {
            return false;
        }
        return (bool) $string;
    }

Usage Example

Beispiel #1
0
 /**
  * Get the field configuration
  *
  * @return  array
  */
 protected function getConfig()
 {
     // If no custom options were defined let's figure out which ones of the
     // defaults we shall use...
     $config = array('published' => 1, 'unpublished' => 1, 'archived' => 0, 'trash' => 0, 'all' => 0);
     if (isset($this->element['show_published'])) {
         $config['published'] = StringHelper::toBool($this->element['show_published']);
     }
     if (isset($this->element['show_unpublished'])) {
         $config['unpublished'] = StringHelper::toBool($this->element['show_unpublished']);
     }
     if (isset($this->element['show_archived'])) {
         $config['archived'] = StringHelper::toBool($this->element['show_archived']);
     }
     if (isset($this->element['show_trash'])) {
         $config['trash'] = StringHelper::toBool($this->element['show_trash']);
     }
     if (isset($this->element['show_all'])) {
         $config['all'] = StringHelper::toBool($this->element['show_all']);
     }
     return $config;
 }
All Usage Examples Of FOF30\Utils\StringHelper::toBool