/** * Constructor... * * @param Array $args The argument list being parsed */ public function __construct(array $argv) { $doubleDash = FALSE; foreach ($argv as $arg) { if ($doubleDash) { $this->args[] = array(self::TYPE_ARG, $arg); } else { if ($arg == "--") { $doubleDash = TRUE; } elseif (\r8\str\startsWith($arg, "--")) { $this->parseSwitch($arg); } else { if (\r8\str\startsWith($arg, "-")) { $this->parseFlag($arg); } else { if (!isset($this->script)) { $this->script = $arg; } else { $this->args[] = array(self::TYPE_ARG, $arg); } } } } } }
/** * @see \r8\iface\Log\Matcher::matches */ public function matches(\r8\Log\Message $message) { $message = $message->getCode(); foreach ($this->codes as $code) { if (\r8\str\startsWith($message, $code)) { return TRUE; } } return FALSE; }
/** * Validates an e-mail address * * @param mixed $value The value to validate * @return String|NULL Any errors encountered */ protected function process($value) { $value = (string) $value; if (\r8\isEmpty($value)) { return "Email Address must not be empty"; } $atCount = substr_count($value, "@"); if ($atCount == 0) { return "Email Address must contain an 'at' (@) symbol"; } if ($atCount > 1) { return "Email Address must only contain one 'at' (@) symbol"; } if (\r8\str\contains(" ", $value)) { return "Email Address must not contain spaces"; } if (\r8\str\contains("\n", $value) || \r8\str\contains("\r", $value)) { return "Email Address must not contain line breaks"; } if (\r8\str\contains("\t", $value)) { return "Email Address must not contain tabs"; } if (preg_match('/\\.\\.+/', $value)) { return "Email Address must not contain repeated periods"; } if (preg_match('/[^a-z0-9' . preg_quote('!#$%&\'*+-/=?^_`{|}~@.[]', '/') . ']/i', $value)) { return "Email Address contains invalid characters"; } if (\r8\str\endsWith($value, ".")) { return "Email Address must not end with a period"; } list($local, $domain) = explode("@", $value); if (\r8\str\startsWith($local, ".")) { return "Email Address must not start with a period"; } // This is hard to describe to a user, so just give them a vague description if (\r8\str\endsWith($local, ".")) { return "Email Address is not valid"; } if (strlen($local) > 64 || strlen($domain) > 255) { return "Email Address is too long"; } $regex = '/' . '^' . '[\\w!#$%&\'*+\\/=?^`{|}~.-]+' . '@' . '(?:[a-z\\d][a-z\\d-]*(?:\\.[a-z\\d][a-z\\d-]*)?)+' . '\\.(?:[a-z][a-z\\d-]+)' . '$' . '/iD'; // Do a final regex to match the basic form if (!preg_match($regex, $value)) { return "Email Address is not valid"; } }
/** * Sets the basename for this file * * This sets the extension and filename at once * * @param String $basename The new basename * @return \r8\FileSys\File Returns a self reference */ public function setBasename($basename) { $basename = trim((string) $basename); $basename = pathinfo($basename); // Handle filenames that start with a dot, like ".htaccess" if (\r8\str\startsWith($basename['basename'], ".")) { $basename = pathinfo(substr($basename['basename'], 1)); $basename['filename'] = "." . $basename['filename']; } if (isset($basename['filename'])) { $this->setFilename($basename['filename']); } else { $this->clearFilename(); } if (isset($basename['extension'])) { $this->setExt($basename['extension']); } else { $this->clearExt(); } return $this; }
public function testStartsWith() { $this->assertTrue(\r8\str\startsWith('string with content', 'string')); $this->assertTrue(\r8\str\startsWith('string with content', 'String')); $this->assertTrue(\r8\str\startsWith('string with content', 'string', TRUE)); $this->assertTrue(\r8\str\startsWith('string with content', 'String', TRUE)); $this->assertTrue(\r8\str\startsWith('string with content', 'string', FALSE)); $this->assertFalse(\r8\str\startsWith('string with content', 'String', FALSE)); $this->assertFalse(\r8\str\startsWith('string with content', 'strn', FALSE)); }
/** * Removes a head from a string if it exists * * @param String $string The base string * @param String $head The string to remove from the beginning of the base string, if it is there * @param Boolean $ignoreCase Whether the comparison should be case sensitive * @return String Returns the decapitated string */ function stripHead($string, $head, $ignoreCase = TRUE) { $string = (string) $string; $head = (string) $head; if (!\r8\str\startsWith($string, $head, $ignoreCase)) { return $string; } return substr($string, strlen($head)) ?: ""; }
/** * Attempts to find a file given a relative path * * @param \r8\Finder\Tracker $tracker $file The tracker to use when determining * if a base/path combination is valid * @param String $base The base directory to look for the path in * @param String $path The path being looked for * @return \r8\Finder\Result|NULL Returns a result, or NULL if the file couldn't be found */ public function find(\r8\Finder\Tracker $tracker, $base, $path) { $origPath = $path; $path = trim((string) $path, "/"); $path = \r8\FileSys::resolvePath($path); // Iterate over each possible mutation and determine if it should be applied foreach ($this->mutations as $mutate) { $result = NULL; // Check for a partial match if (\r8\str\startsWith($path, $mutate["from"] . "/")) { $result = $this->wrapped->find($tracker, $base, $mutate["to"] . "/" . ltrim(substr($path, strlen($mutate["from"])), "/")); } else { if (strcasecmp($path, $mutate["from"]) == 0) { $result = $this->wrapped->find($tracker, $base, $mutate["to"]); } } if ($result instanceof \r8\Finder\Result) { return $result; } } return $this->wrapped->find($tracker, $base, $origPath); }