/** * Parses a string into a SQL expression and it's alias * * @param String $name The SQL string to parse * @return array Returns an array where the first element is the * SQL expression and the second is the alias */ public static function parseSQLAlias($string) { $string = (string) $string; // If there is no obvious alias, take an easy out if (!\r8\str\contains(" AS ", $string)) { $alias = null; } else { if (!\r8\str\contains("`", $string)) { list($string, $alias) = explode(" AS ", $string, 2); $alias = trim($alias); } else { $parser = new \r8\Quoter(); list($string, $alias) = $parser->clearQuotes()->setQuote("`")->parse($string)->setIncludeQuoted(FALSE)->explode(" AS "); $alias = trim($alias); } } $string = trim($string); if (\r8\IsEmpty($string)) { $string = null; } $alias = \r8\str\stripW($alias); if (\r8\IsEmpty($alias)) { $alias = null; } return array($string, $alias); }
/** * Converts the given value to boolean * * @param Mixed $value The value to filter * @return Boolean */ public function filter($value) { if (is_bool($value)) { return $value; } else { if (is_int($value) || is_float($value)) { return $value == 0 ? FALSE : TRUE; } else { if (is_null($value)) { return FALSE; } else { if (is_string($value)) { $value = strtolower(\r8\str\stripW($value)); if ($value == "f" || $value == "false" || $value == "n" || $value == "no" || $value == "off" || \r8\isEmpty($value)) { return FALSE; } else { return TRUE; } } else { if (is_array($value)) { return count($value) == 0 ? FALSE : TRUE; } else { return $value ? TRUE : FALSE; } } } } } }
public function testStripW() { $this->assertSame("", \r8\str\stripW("")); $this->assertEquals("123abc", \r8\str\stripW(" !@#^1^%_ 2\n3\t <>?a )))b\rc")); $this->assertEquals(" 1 23 a bc", \r8\str\stripW(" !@#^1^%_ 2\n3\t <>?a )))b\rc", " ")); $this->assertEquals(" 1_ 23 a bc", \r8\str\stripW(" !@#^1^%_ 2\n3\t <>?a )))b\rc", " _")); $this->assertEquals("12\n3ab\rc", \r8\str\stripW(" !@#^1^%_ 2\n3\t <>?a )))b\rc", "\n\r")); }
/** * Returns the HTML ID that will be used to identify each radio button * * The fields need to have an ID so that the label tags are correctly * associated with the radio tags * * @return String */ public function getRadioOptionID($value) { $value = \r8\indexVal($value); if (!$this->hasOption($value)) { throw new \r8\Exception\Index($value, "Option Value", "Option does not exist in field"); } return "radio_" . \r8\str\stripW($this->getName()) . "_" . substr(sha1($value), 0, 10); }
/** * Sets the value of the condition in this instance * * @param String $condition The condition this instance represents * @return \r8\HTML\Conditional Returns a self reference */ public function setCondition($condition) { $condition = trim(\r8\str\stripW($condition, " ")); if (\r8\isEmpty($condition)) { throw new \r8\Exception\Argument(0, "Condition", "Must not be empty"); } $this->condition = $condition; return $this; }
/** * Constructor... * * @param String $message * @param String $level * @param String $code * @param Array $data */ public function __construct($message, $level, $code, array $data = array()) { $code = \r8\str\stripW($code, "_"); if (\r8\isEmpty($code)) { throw new \r8\Exception\Argument(2, 'Code', 'Can only contain Numbers, Strings and Underscores'); } $this->message = (string) $message; $this->level = \r8\Log\Level::resolveValue($level); $this->code = (string) $code; $this->data = $data; $this->time = \microtime(TRUE); }
/** * Constructor... * * @param String $func The function name * @param \r8\iface\Query\Atom $args... Any arguments to pass to the function */ public function __construct($func) { $func = \r8\str\stripW($func, "_"); $func = strtoupper($func); if (empty($func)) { throw new \r8\Exception\Argument(0, "Function Name", "Must not be empty"); } $this->func = $func; if (func_num_args() > 1) { $this->setArgs(func_get_args()); } }
/** * Cleans and normalizes a flag * * @param String $flag * @param Boolean $require Whether to throw an exception if * this flag is empty * @return String */ public static function normalizeFlag($flag, $require = TRUE) { $flag = trim(str_replace(" ", "-", (string) $flag), "-"); $flag = \r8\str\stripW($flag, "-"); if ($require && \r8\isEmpty($flag)) { throw new \r8\Exception\Argument(0, "Flag", "Must not be empty"); } else { if (strlen($flag) > 1) { $flag = strtolower($flag); } } return $flag; }
/** * Sets the value of the tag in this instance * * @param String $tag The tag this instance represents * @return \r8\HTML\Tag Returns a self reference */ public function setTag($tag) { $tag = strtolower(\r8\str\stripW($tag)); if (\r8\isEmpty($tag)) { throw new \r8\Exception\Argument(0, "Tag", "Must not be empty"); } $this->tag = $tag; return $this; }
/** * Sets the Database name * * @param String $database * @return \r8\Query\Atom\Field Returns a self reference */ public function setDatabase($database) { $database = \r8\str\stripW($database); $this->database = $database ? $database : null; return $this; }
/** * Sets the order in which this atom should be sorted * * @param String $order The order of the atom * @return \r8\Query\Expr\Ordered Returns a self reference */ public function setOrder($order) { if (\is_null($order)) { $this->order = null; } else { if (\is_bool($order) || \is_int($order) || \is_float($order)) { $this->order = $order ? "ASC" : "DESC"; } else { $order = strtoupper(\r8\str\stripW($order)); if ($order == "ASC" || $order == "DESC") { $this->order = $order; } else { $this->order = null; } } } return $this; }
/** * Sets the scheme for this instance * * @param String $scheme * @return \r8\URL Returns a self reference */ public function setScheme($scheme) { $scheme = strtolower(\r8\str\stripW($scheme)); $this->scheme = empty($scheme) ? null : $scheme; return $this; }
/** * Sets the alias of this field * * @param String $alias The field name alias * @return \r8\Query\Expr\Select Returns a self reference */ public function setAlias($alias) { $alias = \r8\str\stripW($alias, "_"); $this->alias = empty($alias) ? NULL : $alias; return $this; }
/** * Sets the character encoding that the output string will be encoded with. * * If a value has not been explicitly set, this value will be pulled from * the iconv.internal_encoding php.ini setting. * * @param String $charset The name of the output character set * @return Object Returns a self reference */ public function setOutputEncoding($charset) { $charset = \r8\str\stripW($charset, "-"); if (\r8\isEmpty($charset)) { throw new \r8\Exception\Argument(0, "Character Set", "Must not be empty"); } $this->outEncoding = $charset; return $this; }
/** * Sets the Alias * * @param String $alias The alias of this field * @return \r8\Query\From\Table Returns a self reference */ public function setAlias($alias) { $alias = \r8\str\stripW($alias); $this->alias = $alias ? $alias : null; return $this; }
/** * Sets the method this for should submit using * * @param String $method * @return Object Returns a self reference */ public function setMethod($method) { $method = \r8\str\stripW($method); if (\r8\isEmpty($method)) { throw new \r8\Exception\Argument(0, "Submit Method", "Must not be empty"); } $this->method = $method; return $this; }
/** * Imports the settings in this instance from an array * * @param array $array The array of settings to import * @return \r8\DB\Config Returns a self reference */ public function fromArray(array $array) { foreach ($array as $key => $value) { $key = "set" . strtolower(\r8\str\stripW($key)); $value = (string) $value; if (method_exists($this, $key)) { $this->{$key}($value); } } return $this; }