/** * Constructor * * @param Integer $arg The argument offset (from 0) that caused the error * @param String $label The name of the argument * @param String $message The error message * @param Integer $code The error code */ public function __construct($arg, $label = NULL, $message = NULL, $code = 0) { parent::__construct($message, $code); $this->arg = (int) $arg; if (!\r8\isVague($label)) { $this->addData("Arg Label", $label); } }
/** * Constructor... * * @param Integer|NULL $affected The number of rows affected by this query * @param Integer|NULL $insertID The ID of the row inserted by this query * @param String $query The query that produced this result */ public function __construct($affected, $insertID, $query) { if (!\r8\isVague($insertID)) { $insertID = (int) $insertID; $this->insertID = $insertID > 0 ? $insertID : NULL; } $this->affected = max((int) $affected, 0); parent::__construct($query); }
/** * Returns an e-mail address formatted as such: Name <*****@*****.**> * * @param String $email The e-mail address * @param String $name The name of the person associated with the address * @return String The well formatted address line */ public static function formatAddress($email, $name = NULL) { $email = r8(new \r8\Filter\Email())->filter($email); if (!\r8\isVague($name)) { $name = trim(\r8\str\stripNoPrint($name)); } if (\r8\isVague($name)) { return "<" . $email . ">"; } else { return '"' . addslashes($name) . '" <' . $email . '>'; } }
/** * Constructor... * * @param String $url The initial URL for this instance */ public function __construct($url = null) { if ($url instanceof self) { $this->copyURL($url); } else { if (!\r8\isVague($url)) { $this->setURL((string) $url); } } }
/** * Registers a set of quotes * * If the opening quote has already been registered, the closing quotes will * be replaced with the new set * * @param String $open The opening quote * @param Null|String|Array $close If left empty, this will assume the closing quote * is the same as the opening quote. If an array is given, it will be * flattened and compacted. * @return object Returns a self reference */ public function setQuote($open, $close = FALSE) { $open = (string) $open; if (\r8\isEmpty($open, ALLOW_SPACES)) { throw new \r8\Exception\Argument(0, "Open Quote", "Must not be empty"); } if (\r8\isVague($close, ALLOW_SPACES)) { $close = array($open); } else { $close = (array) $close; $close = \r8\ary\flatten($close); $close = \r8\ary\stringize($close); $close = \r8\ary\compact($close, \r8\ALLOW_SPACES); $close = \array_unique($close); } $this->quotes[$open] = $close; return $this; }
/** * Combines two strings and adds a separator between them. * * Detects if the separator already exists at the tail or head of either string * so that it isn't repeated. * * @param String $string1 The first part of the resulting string * @param String $string2 The last part of the resulting string * @param String $glue The glue to put between the two strings * @param Boolean $ignoreCase Whether the comparison should be case sensitive * @return String Returns the strings combined, with the glue in the middle */ function weld($string1, $string2, $glue, $ignoreCase = TRUE) { $string1 = (string) $string1; $string2 = (string) $string2; $glue = (string) $glue; if (\r8\isVague($glue, \r8\str\ALLOW_SPACES)) { return $string1 . $string2; } return \r8\str\stripTail($string1, $glue, $ignoreCase) . $glue . \r8\str\stripHead($string2, $glue, $ignoreCase); }
/** * Returns the name of a file that doesn't yet exist in this directory * * Without a prefix or extension, this will create a filename 15 characters * long. If you change the $moreEntropy flag to true, the result will be * 25 characters * * @param String $prefix A prefix to attach to the file name * @param String $extension The extension the file should have * @param Boolean $moreEntropy Increases the length of the generated filename * @return \r8\FileSys\File */ public function getUniqueFile($prefix = null, $extension = null, $moreEntropy = FALSE) { if (!$this->dirExists()) { throw new \r8\Exception\Variable("Dir", "No directory has been set for this instance"); } $file = new \r8\FileSys\File(); $file->setDir($this->getRawDir()); if (!\r8\isVague($extension)) { $file->setExt($extension); } $prefix = \r8\isVague($prefix) ? null : (string) $prefix; $moreEntropy = (bool) $moreEntropy; do { if ($moreEntropy) { $uniq = md5(uniqid(null, true)); } else { $uniq = substr(md5(uniqid()), 0, 15); } $file->setFileName($prefix . $uniq); } while ($file->exists()); return $file; }
/** * Adds an address this e-mail should be sent bcc * * @param String $email The actual email address * @param String $name The label for that e-mail address * @return \r8\Mail Returns a self reference */ public function addBCC($email, $name = FALSE) { $email = r8(new \r8\Filter\Email())->filter($email); r8(new \r8\Validator\Email())->ensure($email); if (!\r8\isVague($name)) { $name = trim(\r8\str\stripNoPrint($name)); $name = \r8\isEmpty($name) ? NULL : $name; } $bcc = array("email" => $email, "name" => $name); $this->bcc[$email] = $bcc; return $this; }
public function testIsVague() { $this->assertTrue(\r8\isVague(FALSE)); $this->assertTrue(\r8\isVague(TRUE)); $this->assertTrue(\r8\isVague("")); $this->assertTrue(\r8\isVague(0)); $this->assertTrue(\r8\isVague(NULL)); $this->assertTrue(\r8\isVague(array())); $this->assertTrue(\r8\isVague(" ")); $this->assertFalse(\r8\isVague("string")); $this->assertFalse(\r8\isVague(1)); $this->assertFalse(\r8\isVague("0")); $this->assertFalse(\r8\isVague("1")); $this->assertFalse(\r8\isVague(array(1))); }