Webiny\Component\StdLib\StdObject\StdObjectWrapper::toBool PHP 메소드

toBool() 공개 정적인 메소드

Returns a bool value based on whatever value passed in.
These values are considered TRUE: '1', 'true', 'on', 'yes', 'y'
public static toBool ( mixed $var ) : boolean
$var mixed
리턴 boolean
    public static function toBool($var)
    {
        if (!self::isString($var)) {
            return (bool) $var;
        }
        switch (strtolower($var)) {
            case '1':
            case 'true':
            case 'on':
            case 'yes':
            case 'y':
                return true;
            default:
                return false;
        }
    }

Usage Example

예제 #1
0
 public function __construct($entityClass, $entityCollection, $conditions, $order, $limit, $offset)
 {
     // Convert boolean strings to boolean
     foreach ($conditions as &$condition) {
         if (is_scalar($condition) && (strtolower($condition) === 'true' || strtolower($condition) === 'false')) {
             $condition = StdObjectWrapper::toBool($condition);
         }
     }
     $this->entityClass = $entityClass;
     $this->collectionName = $entityCollection;
     $this->conditions = $conditions;
     $this->limit = $limit;
     $this->offset = $offset;
     $this->data = Entity::getInstance()->getDatabase()->find($entityCollection, $conditions, $order, $limit, $offset);
 }
All Usage Examples Of Webiny\Component\StdLib\StdObject\StdObjectWrapper::toBool