toBool() public static method

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
return boolean
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);
 }
Example #2
0
 /**
  * Execute callback from MatchedRoute and return result.<br>
  * Required callback structure is:
  * <code>
  * Callback:
  *     Class: \Your\Class
  *     Method: handle
  *     Static: true // (Optional, "false" by default)
  *
  *</code>
  * @param MatchedRoute $route
  *
  * @return mixed
  *
  * @throws RouterException
  */
 public function execute(MatchedRoute $route)
 {
     $callback = $route->getCallback();
     if ($this->isString($callback)) {
         throw new RouterException(RouterException::STRING_CALLBACK_NOT_PARSABLE);
     }
     $callback = $this->arr($callback);
     $handlerClass = $callback->key('Class', false, true);
     $handlerMethod = $callback->key('Method', false, true);
     $staticMethod = StdObjectWrapper::toBool($callback->key('Static', false, true));
     if (!class_exists($handlerClass)) {
         throw new RouterException(RouterException::CALLBACK_CLASS_NOT_FOUND, [$handlerClass]);
     }
     if (!method_exists($handlerClass, $handlerMethod)) {
         throw new RouterException(RouterException::CALLBACK_CLASS_METHOD_NOT_FOUND, [$handlerMethod, $handlerClass]);
     }
     if ($staticMethod) {
         return forward_static_call_array([$handlerClass, $handlerMethod], $route->getParams());
     }
     return call_user_func_array([new $handlerClass(), $handlerMethod], $route->getParams());
 }
Example #3
0
 public function getToArrayValue()
 {
     return StdObjectWrapper::toBool(parent::getToArrayValue());
 }
Example #4
0
 public function toArray($params = [])
 {
     return $this->processToArrayValue(StdObjectWrapper::toBool(parent::toArray($params)));
 }