diff --git a/composer.json b/composer.json index 091bfbc2..7d208653 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,14 @@ + { "name": "wildphp/wild-irc-bot", - "version": "2.0.2", + "version": "2.0.3", "description": "A modular IRC bot written in PHP", "type": "project", "require": { "php": ">=5.5.0", "myclabs/php-enum": "^1.4", - "react/react": "^0.4.2", - "guzzlehttp/guzzle": "^6.1", - "wildphp/module-channelmanager": "^2.1", - "wildphp/module-linksniffer": "^2.0" + "react/react": "^0.4", + "wildphp/api": "*" }, "require-dev": { diff --git a/lib/WildPHP/API/Remote.php b/lib/WildPHP/API/Remote.php deleted file mode 100644 index 5886524f..00000000 --- a/lib/WildPHP/API/Remote.php +++ /dev/null @@ -1,118 +0,0 @@ -. -*/ - -namespace WildPHP\API; - - -use GuzzleHttp\Client; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamInterface; -use WildPHP\Exceptions\InvalidUriException; - -class Remote -{ - /** - * @param string $uri - * @return ResponseInterface - */ - public static function getUriHeaders($uri) - { - if (!self::isValidLink($uri)) - throw new InvalidUriException($uri . ' is not a valid link'); - - $httpClient = new Client(); - $resource = $httpClient->head($uri, [ - 'allow_redirects' => true, - 'connect_timeout' => 2, - 'timeout' => 5 - ]); - unset($httpClient); - - return $resource; - } - - /** - * @param string $uri - * @return bool - */ - public static function isValidLink($uri) - { - return filter_var($uri, FILTER_VALIDATE_URL) == $uri; - } - - /** - * The purpose of this function is to provide a means to collect data in steps of 1 KB. - * This can greatly increase performance when big web pages have to be loaded. - * - * The callback function may return false to abort the operation. - * - * @param string $uri - * @param callback $callback - * @param int $maximumBytes - * @param int $steps - * - * @return void - */ - public static function getUriBodySplit($uri, $callback, $maximumBytes = 1024 * 1024 * 3, $steps = 1024) - { - if (!self::isValidLink($uri)) - throw new InvalidUriException($uri . ' is not a valid link'); - - if (!is_callable($callback)) - throw new \InvalidArgumentException('getUriBodySplit must have a valid callback parameter'); - - $body = self::getUriBody($uri); - - $readBytes = 0; - while (!$body->eof() && $readBytes < $maximumBytes) - { - $partial = $body->read($steps); - $result = call_user_func($callback, $partial); - - if ($result === false) - break; - } - $body->close(); - unset($body); - } - - /** - * @param string $uri - * @return StreamInterface - */ - public static function getUriBody($uri) - { - if (!self::isValidLink($uri)) - throw new InvalidUriException($uri . ' is not a valid link'); - - $httpClient = new Client(); - $resource = $httpClient->get($uri, [ - 'allow_redirects' => true, - 'connect_timeout' => 2, - 'timeout' => 5 - ]); - unset($httpClient); - - $contents = $resource->getBody(); - unset($resource); - - return $contents; - } -} \ No newline at end of file diff --git a/lib/WildPHP/API/ShortenUri.php b/lib/WildPHP/API/ShortenUri.php deleted file mode 100644 index a8fc62ef..00000000 --- a/lib/WildPHP/API/ShortenUri.php +++ /dev/null @@ -1,53 +0,0 @@ -. -*/ - -namespace WildPHP\API; - -use WildPHP\Exceptions\InvalidUriException; -use WildPHP\Exceptions\ShortUriCreationFailedException; - -class ShortenUri -{ - /** - * @param string $uri - * @return string - */ - public static function createShortLink($uri) - { - if (!Remote::isValidLink($uri)) - throw new InvalidUriException($uri . ' is not a valid link'); - - // Pieces... - $shortenerBaseUrl = 'http://is.gd/create.php?format=json&url=%s'; - $uri = urlencode($uri); - - // Add them together... - $shortenerUrl = sprintf($shortenerBaseUrl, $uri); - - // And fire a request. - $body = Remote::getUriBody($shortenerUrl); - $contents = $body->getContents(); - - if (!($decoded = json_decode($contents)) || empty($decoded->shorturl)) - throw new ShortUriCreationFailedException('Received an invalid result set'); - - return $decoded->shorturl; - } -} \ No newline at end of file diff --git a/lib/WildPHP/Exceptions/InvalidUriException.php b/lib/WildPHP/Exceptions/InvalidUriException.php deleted file mode 100644 index a10a1306..00000000 --- a/lib/WildPHP/Exceptions/InvalidUriException.php +++ /dev/null @@ -1,27 +0,0 @@ -. -*/ - -namespace WildPHP\Exceptions; - - -class InvalidUriException extends \RuntimeException -{ - -} \ No newline at end of file diff --git a/lib/WildPHP/Exceptions/ShortUriCreationFailedException.php b/lib/WildPHP/Exceptions/ShortUriCreationFailedException.php deleted file mode 100644 index 60c1c65d..00000000 --- a/lib/WildPHP/Exceptions/ShortUriCreationFailedException.php +++ /dev/null @@ -1,27 +0,0 @@ -. -*/ - -namespace WildPHP\Exceptions; - - -class ShortUriCreationFailedException extends \RuntimeException -{ - -} \ No newline at end of file diff --git a/lib/WildPHP/Validation.php b/lib/WildPHP/Validation.php index 1323b1b5..55b598d9 100755 --- a/lib/WildPHP/Validation.php +++ b/lib/WildPHP/Validation.php @@ -19,35 +19,20 @@ */ namespace WildPHP; +use WildPHP\API\Validation as NewValidationClass; /** - * Validation class, with shortcuts for validating items. + * Wrapper for new validation class. */ class Validation { - /** - * Checks if a channel name conforms to RFC2812's grammar rules. - * - * @param string $chan The channel name to check. - * @return bool - */ public static function isChannel($chan) { - $pmatch = preg_match('/^(?:\&|\#|\+|\!)[^,\cG ]+$/', $chan); - - return $pmatch !== 0 && $pmatch !== false; + return NewValidationClass::isChannel($chan); } - /** - * Checks if a nickname conforms to RFC2812's grammar rules. - * - * @param string $nick The nickname to check. - * @return bool - */ public static function isNickname($nick) { - $pmatch = preg_match("/^[^@\n\r ]+$/", $nick); - - return $pmatch !== 0 && $pmatch !== false; + return NewValidationClass::isNickname($nick); } } \ No newline at end of file