/goutte.phar
Unknown | 292 lines | 259 code | 33 blank | 0 comment | 0 complexity | 6ff143d60302095e9d0f35485f3829bb MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- $web = '_web_stub.php';
- if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
- Phar::interceptFileFuncs();
- set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
- Phar::webPhar(null, $web);
- include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
- return;
- }
- if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
- Extract_Phar::go(true);
- $mimes = array(
- 'phps' => 2,
- 'c' => 'text/plain',
- 'cc' => 'text/plain',
- 'cpp' => 'text/plain',
- 'c++' => 'text/plain',
- 'dtd' => 'text/plain',
- 'h' => 'text/plain',
- 'log' => 'text/plain',
- 'rng' => 'text/plain',
- 'txt' => 'text/plain',
- 'xsd' => 'text/plain',
- 'php' => 1,
- 'inc' => 1,
- 'avi' => 'video/avi',
- 'bmp' => 'image/bmp',
- 'css' => 'text/css',
- 'gif' => 'image/gif',
- 'htm' => 'text/html',
- 'html' => 'text/html',
- 'htmls' => 'text/html',
- 'ico' => 'image/x-ico',
- 'jpe' => 'image/jpeg',
- 'jpg' => 'image/jpeg',
- 'jpeg' => 'image/jpeg',
- 'js' => 'application/x-javascript',
- 'midi' => 'audio/midi',
- 'mid' => 'audio/midi',
- 'mod' => 'audio/mod',
- 'mov' => 'movie/quicktime',
- 'mp3' => 'audio/mp3',
- 'mpg' => 'video/mpeg',
- 'mpeg' => 'video/mpeg',
- 'pdf' => 'application/pdf',
- 'png' => 'image/png',
- 'swf' => 'application/shockwave-flash',
- 'tif' => 'image/tiff',
- 'tiff' => 'image/tiff',
- 'wav' => 'audio/wav',
- 'xbm' => 'image/xbm',
- 'xml' => 'text/xml',
- );
- header("Cache-Control: no-cache, must-revalidate");
- header("Pragma: no-cache");
- $basename = basename(__FILE__);
- if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
- chdir(Extract_Phar::$temp);
- include $web;
- return;
- }
- $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
- if (!$pt || $pt == '/') {
- $pt = $web;
- header('HTTP/1.1 301 Moved Permanently');
- header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
- exit;
- }
- $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
- if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
- header('HTTP/1.0 404 Not Found');
- echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
- exit;
- }
- $b = pathinfo($a);
- if (!isset($b['extension'])) {
- header('Content-Type: text/plain');
- header('Content-Length: ' . filesize($a));
- readfile($a);
- exit;
- }
- if (isset($mimes[$b['extension']])) {
- if ($mimes[$b['extension']] === 1) {
- include $a;
- exit;
- }
- if ($mimes[$b['extension']] === 2) {
- highlight_file($a);
- exit;
- }
- header('Content-Type: ' .$mimes[$b['extension']]);
- header('Content-Length: ' . filesize($a));
- readfile($a);
- exit;
- }
- }
- class Extract_Phar
- {
- static $temp;
- static $origdir;
- const GZ = 0x1000;
- const BZ2 = 0x2000;
- const MASK = 0x3000;
- const START = '_cli_stub.php';
- const LEN = 6693;
- static function go($return = false)
- {
- $fp = fopen(__FILE__, 'rb');
- fseek($fp, self::LEN);
- $L = unpack('V', $a = (binary)fread($fp, 4));
- $m = (binary)'';
- do {
- $read = 8192;
- if ($L[1] - strlen($m) < 8192) {
- $read = $L[1] - strlen($m);
- }
- $last = (binary)fread($fp, $read);
- $m .= $last;
- } while (strlen($last) && strlen($m) < $L[1]);
- if (strlen($m) < $L[1]) {
- die('ERROR: manifest length read was "' .
- strlen($m) .'" should be "' .
- $L[1] . '"');
- }
- $info = self::_unpack($m);
- $f = $info['c'];
- if ($f & self::GZ) {
- if (!function_exists('gzinflate')) {
- die('Error: zlib extension is not enabled -' .
- ' gzinflate() function needed for zlib-compressed .phars');
- }
- }
- if ($f & self::BZ2) {
- if (!function_exists('bzdecompress')) {
- die('Error: bzip2 extension is not enabled -' .
- ' bzdecompress() function needed for bz2-compressed .phars');
- }
- }
- $temp = self::tmpdir();
- if (!$temp || !is_writable($temp)) {
- $sessionpath = session_save_path();
- if (strpos ($sessionpath, ";") !== false)
- $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
- if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
- die('Could not locate temporary directory to extract phar');
- }
- $temp = $sessionpath;
- }
- $temp .= '/pharextract/'.basename(__FILE__, '.phar');
- self::$temp = $temp;
- self::$origdir = getcwd();
- @mkdir($temp, 0777, true);
- $temp = realpath($temp);
- if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
- self::_removeTmpFiles($temp, getcwd());
- @mkdir($temp, 0777, true);
- @file_put_contents($temp . '/' . md5_file(__FILE__), '');
- foreach ($info['m'] as $path => $file) {
- $a = !file_exists(dirname($temp . '/' . $path));
- @mkdir(dirname($temp . '/' . $path), 0777, true);
- clearstatcache();
- if ($path[strlen($path) - 1] == '/') {
- @mkdir($temp . '/' . $path, 0777);
- } else {
- file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
- @chmod($temp . '/' . $path, 0666);
- }
- }
- }
- chdir($temp);
- if (!$return) {
- include self::START;
- }
- }
- static function tmpdir()
- {
- if (strpos(PHP_OS, 'WIN') !== false) {
- if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
- return $var;
- }
- if (is_dir('/temp') || mkdir('/temp')) {
- return realpath('/temp');
- }
- return false;
- }
- if ($var = getenv('TMPDIR')) {
- return $var;
- }
- return realpath('/tmp');
- }
- static function _unpack($m)
- {
- $info = unpack('V', substr($m, 0, 4));
- $l = unpack('V', substr($m, 10, 4));
- $m = substr($m, 14 + $l[1]);
- $s = unpack('V', substr($m, 0, 4));
- $o = 0;
- $start = 4 + $s[1];
- $ret['c'] = 0;
- for ($i = 0; $i < $info[1]; $i++) {
- $len = unpack('V', substr($m, $start, 4));
- $start += 4;
- $savepath = substr($m, $start, $len[1]);
- $start += $len[1];
- $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
- $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
- & 0xffffffff);
- $ret['m'][$savepath][7] = $o;
- $o += $ret['m'][$savepath][2];
- $start += 24 + $ret['m'][$savepath][5];
- $ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
- }
- return $ret;
- }
- static function extractFile($path, $entry, $fp)
- {
- $data = '';
- $c = $entry[2];
- while ($c) {
- if ($c < 8192) {
- $data .= @fread($fp, $c);
- $c = 0;
- } else {
- $c -= 8192;
- $data .= @fread($fp, 8192);
- }
- }
- if ($entry[4] & self::GZ) {
- $data = gzinflate($data);
- } elseif ($entry[4] & self::BZ2) {
- $data = bzdecompress($data);
- }
- if (strlen($data) != $entry[0]) {
- die("Invalid internal .phar file (size error " . strlen($data) . " != " .
- $stat[7] . ")");
- }
- if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
- die("Invalid internal .phar file (checksum error)");
- }
- return $data;
- }
- static function _removeTmpFiles($temp, $origdir)
- {
- chdir($temp);
- foreach (glob('*') as $f) {
- if (file_exists($f)) {
- is_dir($f) ? @rmdir($f) : @unlink($f);
- if (file_exists($f) && is_dir($f)) {
- self::_removeTmpFiles($f, getcwd());
- }
- }
- }
- @rmdir($temp);
- clearstatcache();
- chdir($origdir);
- }
- }
- Extract_Phar::go();
- __HALT_COMPILER(); ?>
- ç��?����������Goutte�������LICENSE!��^˝sL!��Xň3Ůś���������src/autoload.phpf��^˝sLf��uö"rś������A���src/vendor/symfony/src/Symfony/Framework/UniversalClassLoader.php��^˝sL��F˝4ś������*���src/vendor/zend/library/Zend/Exception.php=���^˝sL=���Ürś������(���src/vendor/zend/library/Zend/Uri/Uri.phpu���^˝sLu���ÜČŞś������4���src/vendor/zend/library/Zend/Validator/Validator.php���^˝sL���˘Ţś������<���src/vendor/zend/library/Zend/Validator/AbstractValidator.phpÄ��^˝sLÄ��.Pîś������3���src/vendor/zend/library/Zend/Validator/Hostname.php{[��^˝sL{[��糌üś������-���src/vendor/zend/library/Zend/Validator/Ip.php��^˝sL��+Ěiś������7���src/vendor/zend/library/Zend/Validator/Hostname/Com.php1��^˝sL1��AQĺ2ś������6���src/vendor/zend/library/Zend/Validator/Hostname/Jp.phpŰđ��^˝sLŰđ��ÁeRś���������src/Goutte/Client.php��^˝sL��r*G ś���������src/Goutte/Compiler.phpT
- ��^˝sLT
- ��^Áŕś������>���src/vendor/symfony/src/Symfony/Component/BrowserKit/Client.php��^˝sL��WÓ^ś������>���src/vendor/symfony/src/Symfony/Component/BrowserKit/Cookie.php��^˝sL��ÖćŻvś������A���src/vendor/symfony/src/Symfony/Component/BrowserKit/CookieJar.php��^˝sL��L>5Aś������?���src/vendor/symfony/src/Symfony/Component/BrowserKit/History.phpĄ��^˝sLĄ��;çÖś������?���src/vendor/symfony/src/Symfony/Component/BrowserKit/Request.phpź��^˝sLź��TłÎś������@���src/vendor/symfony/src/Symfony/Component/BrowserKit/Response.phpż��^˝sLż��-2Yś������?���src/vendor/symfony/src/Symfony/Component/DomCrawler/Crawler.php<%��^˝sL<%��ťĺś������M���src/vendor/symfony/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.phpV��^˝sLV��9vŃś������K���src/vendor/symfony/src/Symfony/Component/DomCrawler/Field/FileFormField.php��^˝sL��°Íל������G���src/vendor/symfony/src/Symfony/Component/DomCrawler/Field/FormField.phpĎ��^˝sLĎ��/>ŐÓś������L���src/vendor/symfony/src/Symfony/Component/DomCrawler/Field/InputFormField.phpš��^˝sLš��{Y'ś������O���src/vendor/symfony/src/Symfony/Component/DomCrawler/Field/TextareaFormField.phpâ��^˝sLâ��é¤mś������<���src/vendor/symfony/src/Symfony/Component/DomCrawler/Form.php��^˝sL��ëyś������<���src/vendor/symfony/src/Symfony/Component/DomCrawler/Link.php��^˝sL��aP}ś������H���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/AttribNode.php��^˝sL��Ő )\ś������G���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/ClassNode.phpÄ��^˝sLÄ��ÄWś������R���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/CombinedSelectorNode.php;��^˝sL;��1ăşpś������I���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/ElementNode.phpj��^˝sLj��*ŤŻś������J���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/FunctionNode.php÷��^˝sL÷��^&ŢXś������F���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/HashNode.phpV��^˝sLV��|0ś������K���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/NodeInterface.php���^˝sL���˝Đś������D���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/OrNode.php��^˝sL��"Żś'ś������H���src/vendor/symfony/src/Symfony/Component/CssSelector/Node/PseudoNode.php��^˝sL��đ'>ś������?���src/vendor/symfony/src/Symfony/Component/CssSelector/Parser.php��^˝sL��ŢĄś������D���src/vendor/symfony/src/Symfony/Component/CssSelector/SyntaxError.php]���^˝sL]���iR*ś������>���src/vendor/symfony/src/Symfony/Component/CssSelector/Token.phpţ��^˝sLţ��Ł5ś������B���src/vendor/symfony/src/Symfony/Component/CssSelector/Tokenizer.phpú��^˝sLú��něś������D���src/vendor/symfony/src/Symfony/Component/CssSelector/TokenStream.php#��^˝sL#��'łSüś������B���src/vendor/symfony/src/Symfony/Component/CssSelector/XPathExpr.php\��^˝sL\��÷1Ärś������D���src/vendor/symfony/src/Symfony/Component/CssSelector/XPathExprOr.php˛��^˝sL˛��Ě{zˇś������?���src/vendor/symfony/src/Symfony/Component/Process/PhpProcess.phpĚ��^˝sLĚ��Ň7[/ś������<���src/vendor/symfony/src/Symfony/Component/Process/Process.php��^˝sL��W
úś������.���src/vendor/zend/library/Zend/Uri/Exception.phpF���^˝sLF���U^˛ś������(���src/vendor/zend/library/Zend/Uri/Url.php¤,��^˝sL¤,��7ECś������9���src/vendor/zend/library/Zend/Http/Client/Adapter/Curl.phpŇ&��^˝sLŇ&��rů'Lś������>���src/vendor/zend/library/Zend/Http/Client/Adapter/Exception.php���^˝sL���¸GŇś������:���src/vendor/zend/library/Zend/Http/Client/Adapter/Proxy.phpS��^˝sLS��ń×Ôś������;���src/vendor/zend/library/Zend/Http/Client/Adapter/Socket.phpf*��^˝sLf*��5ň=ś������;���src/vendor/zend/library/Zend/Http/Client/Adapter/Stream.phpf���^˝sLf���*Śuś������9���src/vendor/zend/library/Zend/Http/Client/Adapter/Test.phpT
- ��^˝sLT
- ��Ő>ąś������4���src/vendor/zend/library/Zend/Http/Client/Adapter.phpA��^˝sLA��Ňvěťś������6���src/vendor/zend/library/Zend/Http/Client/Exception.phpR���^˝sLR���J-îś������,���src/vendor/zend/library/Zend/Http/Client.php:^��^˝sL:^��xŹćś������,���src/vendor/zend/library/Zend/Http/Cookie.phpň��^˝sLň��_)VÂś������/���src/vendor/zend/library/Zend/Http/CookieJar.php^��^˝sL^��ĺ
Nś������/���src/vendor/zend/library/Zend/Http/Exception.phpF���^˝sLF���şY6ś������5���src/vendor/zend/library/Zend/Http/Response/Stream.php��^˝sL��[9Ľś������.���src/vendor/zend/library/Zend/Http/Response.php%��^˝sL%��:e7ś������
���_cli_stub.phpK��^˝sLK��˘hYś������
���_web_stub.phpd���^˝sLd���á�ĎUś������Copyright (c) 2010 Fabien Potencier
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is furnished
- to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- <?php
- require_once __DIR__.'/vendor/symfony/src/Symfony/Framework/UniversalClassLoader.php';
- use Symfony\Framework\UniversalClassLoader;
- $loader = new UniversalClassLoader();
- $loader->registerNamespaces(array(
- 'Symfony' => __DIR__.'/vendor/symfony/src',
- 'Zend' => __DIR__.'/vendor/zend/library',
- 'Goutte' => __DIR__,
- ));
- $loader->register();
- <?php
- namespace Symfony\Framework;
- class UniversalClassLoader {
- protected $namespaces = array();
- protected $prefixes = array();
- public function getNamespaces() {
- return $this->namespaces; }
- public function getPrefixes() {
- return $this->prefixes; }
- public function registerNamespaces(array $namespaces) {
- $this->namespaces = array_merge($this->namespaces, $namespaces); }
- public function registerNamespace($namespace, $path) {
- $this->namespaces[$namespace] = $path; }
- public function registerPrefixes(array $classes) {
- $this->prefixes = array_merge($this->prefixes, $classes); }
- public function registerPrefix($prefix, $path) {
- $this->prefixes[$prefix] = $path; }
- public function register() {
- spl_autoload_register(array($this, 'loadClass')); }
- public function loadClass($class) {
- if (false !== ($pos = strripos($class, '\\'))) {
- $namespace = substr($class, 0, $pos);
- foreach ($this->namespaces as $ns => $dir) {
- if (0 === strpos($namespace, $ns)) {
- $class = substr($class, $pos + 1);
- $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
- if (file_exists($file)) {
- require $file; }
- return; } } } else {
- foreach ($this->prefixes as $prefix => $dir) {
- if (0 === strpos($class, $prefix)) {
- $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
- if (file_exists($file)) {
- require $file; }
- return; } } } } }
- <?php
- namespace Zend;
- class Exception extends \Exception { }
- <?php
- namespace Zend\Uri;
- interface Uri {
- public function getScheme();
- public function setScheme($scheme); }
- <?php
- namespace Zend\Validator;
- interface Validator {
- public function isValid($value);
- public function getMessages(); }
- <?php
- namespace Zend\Validator;
- use Zend\Translator;
- abstract class AbstractValidator implements Validator {
- protected $_value;
- protected $_messageVariables = array();
- protected $_messageTemplates = array();
- protected $_messages = array();
- protected $_obscureValue = false;
- protected $_errors = array();
- protected $_translator;
- protected static $_defaultTranslator;
- protected $_translatorDisabled = false;
- protected static $_messageLength = -1;
- public function getMessages() {
- return $this->_messages; }
- public function __invoke($value) {
- return $this->isValid($value); }
- public function getMessageVariables() {
- return array_keys($this->_messageVariables); }
- public function getMessageTemplates() {
- return $this->_messageTemplates; }
- public function setMessage($messageString, $messageKey = null) {
- if ($messageKey === null) {
- $keys = array_keys($this->_messageTemplates);
- foreach($keys as $key) {
- $this->setMessage($messageString, $key); }
- return $this; }
- if (!isset($this->_messageTemplates[$messageKey])) {
- throw new Exception("No message template exists for key '$messageKey'"); }
- $this->_messageTemplates[$messageKey] = $messageString;
- return $this; }
- public function setMessages(array $messages) {
- foreach ($messages as $key => $message) {
- $this->setMessage($message, $key); }
- return $this; }
- public function __get($property) {
- if ($property == 'value') {
- return $this->_value; }
- if (array_key_exists($property, $this->_messageVariables)) {
- return $this->{$this->_messageVariables[$property]}; }
- throw new Exception("No property exists by the name '$property'"); }
- protected function _createMessage($messageKey, $value) {
- if (!isset($this->_messageTemplates[$messageKey])) {
- return null; }
- $message = $this->_messageTemplates[$messageKey];
- if (null !== ($translator = $this->getTranslator())) {
- if ($translator->isTranslated($messageKey)) {
- $message = $translator->translate($messageKey); } else {
- $message = $translator->translate($message); } }
- if (is_object($value)) {
- if (!in_array('__toString', get_class_methods($value))) {
- $value = get_class($value) . ' object'; } else {
- $value = $value->__toString(); } } else {
- $value = (string)$value; }
- if ($this->getObscureValue()) {
- $value = str_repeat('*', strlen($value)); }
- $message = str_replace('%value%', (string) $value, $message);
- foreach ($this->_messageVariables as $ident => $property) {
- $message = str_replace("%$ident%", (string) $this->$property, $message); }
- $length = self::getMessageLength();
- if (($length > -1) && (strlen($message) > $length)) {
- $message = substr($message, 0, (self::getMessageLength() - 3)) . '...'; }
- return $message; }
- protected function _error($messageKey, $value = null) {
- if ($messageKey === null) {
- $keys = array_keys($this->_messageTemplates);
- $messageKey = current($keys); }
- if ($value === null) {
- $value = $this->_value; }
- $this->_errors[] = $messageKey;
- $this->_messages[$messageKey] = $this->_createMessage($messageKey, $value); }
- protected function _setValue($value) {
- $this->_value = $value;
- $this->_messages = array();
- $this->_errors = array(); }
- public function getErrors() {
- return $this->_errors; }
- public function setObscureValue($flag) {
- $this->_obscureValue = (bool) $flag;
- return $this; }
- public function getObscureValue() {
- return $this->_obscureValue; }
- public function setTranslator($translator = null) {
- if ((null === $translator) || ($translator instanceof Translator\Adapter)) {
- $this->_translator = $translator; } elseif ($translator instanceof Translator\Translator) {
- $this->_translator = $translator->getAdapter(); } else {
- throw new Exception('Invalid translator specified'); }
- return $this; }
- public function getTranslator() {
- if ($this->translatorIsDisabled()) {
- return null; }
- if (null === $this->_translator) {
- return self::getDefaultTranslator(); }
- return $this->_translator; }
- public function hasTranslator() {
- return (bool)$this->_translator; }
- public static function setDefaultTranslator($translator = null) {
- if ((null === $translator) || ($translator instanceof Translator\Adapter)) {
- self::$_defaultTranslator = $translator; } elseif ($translator instanceof Translator\Translator) {
- self::$_defaultTranslator = $translator->getAdapter(); } else {
- throw new Exception('Invalid translator specified'); } }
- public static function getDefaultTranslator() {
- if (null === self::$_defaultTranslator) {
- if (\Zend\Registry::isRegistered('Zend_Translate')) {
- $translator = \Zend\Registry::get('Zend_Translate');
- if ($translator instanceof Translator\Adapter) {
- return $translator; } elseif ($translator instanceof Translator\Translator) {
- return $translator->getAdapter(); } } }
- return self::$_defaultTranslator; }
- public static function hasDefaultTranslator() {
- return (bool)self::$_defaultTranslator; }
- public function setDisableTranslator($flag) {
- $this->_translatorDisabled = (bool) $flag;
- return $this; }
- public function translatorIsDisabled() {
- return $this->_translatorDisabled; }
- public static function getMessageLength() {
- return self::$_messageLength; }
- public static function setMessageLength($length = -1) {
- self::$_messageLength = $length; } }
- <?php
- namespace Zend\Validator;
- class Hostname extends AbstractValidator {
- const INVALID = 'hostnameInvalid';
- const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed';
- const UNKNOWN_TLD = 'hostnameUnknownTld';
- const INVALID_DASH = 'hostnameDashCharacter';
- const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema';
- const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld';
- const INVALID_HOSTNAME = 'hostnameInvalidHostname';
- const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName';
- const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed';
- const CANNOT_DECODE_PUNYCODE = 'hostnameCannotDecodePunycode';
- protected $_messageTemplates = array(
- self::INVALID => "Invalid type given. String expected",
- self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed",
- self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list",
- self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash in an invalid position",
- self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'",
- self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part",
- self::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname",
- self::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name",
- self::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed",
- self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded",
- );
- protected $_messageVariables = array(
- 'tld' => '_tld'
- );
- const ALLOW_DNS = 1;
- const ALLOW_IP = 2;
- const ALLOW_LOCAL = 4;
- const ALLOW_ALL = 7;
- protected $_validTlds = array(
- 'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa',
- 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi',
- 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc',
- 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu',
- 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er',
- 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg',
- 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk',
- 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq',
- 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp',
- 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly',
- 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp',
- 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc',
- 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe',
- 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're',
- 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl',
- 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th',
- 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua',
- 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws',
- 'ye', 'yt', 'yu', 'za', 'zm', 'zw'
- );
- protected $_tld;
- protected $_validIdns = array(
- 'AC' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄÄ
ÄÄÄÄÄÄÄÄÄÄÄĥģļħčįľġĺğĞĹĹĹĹĹĹĹĹĹĹĹĹĹĹťţżŧōĹůŹųžšźşŞ]{1,63}$/iu'),
- 'AR' => array(1 => '/^[\x{002d}0-9a-zĂ -ãç-ĂŞĂŹĂĂą-þß]{1,63}$/iu'),
- 'AS' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄÄ
ÄÄÄÄÄÄÄÄÄÄÄÄÄĥģļħĊčÄįĹľġĸĺğĞĹĹĹĹĹĹĹĹĹĹĹĹĹĹĹťţżŧŊōĹůŹųžšźş]{1,63}$/iu'),
- 'AT' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżĹĹĄĹž]{1,63}$/iu'),
- 'BIZ' => 'Hostname/Biz.php',
- 'BR' => array(1 => '/^[\x{002d}0-9a-zĂ -ãçÊĂĂł-þúß]{1,63}$/iu'),
- 'BV' => array(1 => '/^[\x{002d}0-9a-zà åä-ĂŠĂŞĂą-ôÜøßÄÄĹĹťŧŞ]{1,63}$/iu'),
- 'CAT' => array(1 => '/^[\x{002d}0-9a-z¡à ç-ĂŠĂïòóúß]{1,63}$/iu'),
- 'CH' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżĹ]{1,63}$/iu'),
- 'CL' => array(1 => '/^[\x{002d}0-9a-zĂĄĂŠĂùóúß]{1,63}$/iu'),
- 'CN' => 'Hostname/Cn.php',
- 'COM' => 'Zend/Validator/Hostname/Com.php',
- 'DE' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄ
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄĥģļħÄĊįčĹľġĺĞğĹĹĹĹĹĹĹĹĹĸĹĹĹĹĹĹĄĹżţŧĹůŹŊųōžšźŞş]{1,63}$/iu'),
- 'DK' => array(1 => '/^[\x{002d}0-9a-zäÊÜß]{1,63}$/iu'),
- 'ES' => array(1 => '/^[\x{002d}0-9a-zà åçèÊĂïùòóúß¡]{1,63}$/iu'),
- 'EU' => array(1 => '/^[\x{002d}0-9a-zà -Üø-ÿ]{1,63}$/iu',
- 2 => '/^[\x{002d}0-9a-zÄÄÄ
ÄÄÄÄÄÄÄÄÄÄÄÄÄĥģļħĊčÄįĹľġĺğĞĹĹĹĹĹĹĹĹĹĹĹĹĹĹĹĹťżŧŊōĹůŹųžšźşŞ]{1,63}$/iu',
- 3 => '/^[\x{002d}0-9a-zČČ]{1,63}$/iu',
- 4 => '/^[\x{002d}0-9a-zÎÎŹÎΎίΰιβγδξΜΡθΚκΝΟνΞοĎĎĎĎĎĎ
ĎĎĎĎĎĎĎĎĎ]{1,63}$/iu',
- 5 => '/^[\x{002d}0-9a-zайвгдоМСиКкНПнОпŃŃŃŃŃŃ
ŃŃŃŃŃŃŃŃŃŃ]{1,63}$/iu',
- 6 => '/^[\x{002d}0-9a-záź-áźáź-áźáź -៧៰-១á˝-á˝
á˝-á˝á˝ -ὧὰ-Ďáž-ážáž-ážáž -ឧឰ-឴វឡáżáżáżáżáżáż-Îáżáżáż -ῧῲῳῴ῜ῡ]{1,63}$/iu'),
- 'FI' => array(1 => '/^[\x{002d}0-9a-zäüÜ]{1,63}$/iu'),
- 'GR' => array(1 => '/^[\x{002d}0-9a-zÎÎÎÎÎÎ-ÎĄÎŁ-Ďáź-áźáź-áźáź -á˝
á˝-á˝á˝-á˝á˝á˝á˝á˝-á˝˝áž-áž´ážś-ážźáżáżáżáż-áżáż-áżáż-áżáż -῏ῲῳῴ῜-áżź]{1,63}$/iu'),
- 'HK' => 'Zend/Validator/Hostname/Cn.php',
- 'HU' => array(1 => '/^[\x{002d}0-9a-zĂĄĂŠĂóÜúßĹĹą]{1,63}$/iu'),
- 'INFO'=> array(1 => '/^[\x{002d}0-9a-zäüÌÊÜøß]{1,63}$/iu',
- 2 => '/^[\x{002d}0-9a-zĂĄĂŠĂóÜúßĹĹą]{1,63}$/iu',
- 3 => '/^[\x{002d}0-9a-zĂĄĂŚĂŠĂðóÜúýÞ]{1,63}$/iu',
- 4 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu',
- 5 => '/^[\x{002d}0-9a-zÄÄÄģčġğĹĹĹĹĄĹŤĹž]{1,63}$/iu',
- 6 => '/^[\x{002d}0-9a-zÄ
ÄÄÄįťōųŞ]{1,63}$/iu',
- 7 => '/^[\x{002d}0-9a-zĂłÄ
ÄÄĹĹĹźş]{1,63}$/iu',
- 8 => '/^[\x{002d}0-9a-zĂĄĂŠĂùóúß]{1,63}$/iu'),
- 'IO' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄ
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄĥģļħÄĊįčĹľġĺĞğĹĹĹĹĹĹĹĹĹĸĹĹĹĹĹĹĄĹżţŧĹůŹŊųōžšźŞş]{1,63}$/iu'),
- 'IS' => array(1 => '/^[\x{002d}0-9a-zåÊýúĂóÞÌÜð]{1,63}$/iu'),
- 'JP' => 'Zend/Validator/Hostname/Jp.php',
- 'KR' => array(1 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu'),
- 'LI' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżĹ]{1,63}$/iu'),
- 'LT' => array(1 => '/^[\x{002d}0-9Ä
ÄÄÄįťųōŞ]{1,63}$/iu'),
- 'MD' => array(1 => '/^[\x{002d}0-9ÄâÎĹĹŁ]{1,63}$/iu'),
- 'MUSEUM' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄÄ
ÄÄÄÄÄÄÄÄÄÄĥģħčįĹġĺğĞĹĹĹĹĹĹĹĹĹĹĹĹĹťţżŧōůŹųžšźşŞÇÇÇÇ\x{01E5}\x{01E7}\x{01E9}\x{01EF}É\x{0292}áşáşáş
áťł]{1,63}$/iu'),
- 'NET' => 'Zend/Validator/Hostname/Com.php',
- 'NO' => array(1 => '/^[\x{002d}0-9a-zà åä-ĂŠĂŞĂą-ôÜøßÄÄĹĹťŧŞ]{1,63}$/iu'),
- 'NU' => 'Zend/Validator/Hostname/Com.php',
- 'ORG' => array(1 => '/^[\x{002d}0-9a-zĂĄĂŠĂùóúß]{1,63}$/iu',
- 2 => '/^[\x{002d}0-9a-zĂłÄ
ÄÄĹĹĹźş]{1,63}$/iu',
- 3 => '/^[\x{002d}0-9a-zåäüÌÊÍĂðóÜøúßýÞ]{1,63}$/iu',
- 4 => '/^[\x{002d}0-9a-zĂĄĂŠĂóÜúßĹĹą]{1,63}$/iu',
- 5 => '/^[\x{002d}0-9a-zÄ
ÄÄÄįťōųŞ]{1,63}$/iu',
- 6 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu',
- 7 => '/^[\x{002d}0-9a-zÄÄÄģčġğĹĹĹĹĄĹŤĹž]{1,63}$/iu'),
- 'PE' => array(1 => '/^[\x{002d}0-9a-zùåÊĂóúß]{1,63}$/iu'),
- 'PL' => array(1 => '/^[\x{002d}0-9a-zÄÄÄģčġğĹĹĹĹĄĹŤĹž]{1,63}$/iu',
- 2 => '/^[\x{002d}Đ°-ик-Ń\x{0450}ŃŃŃŃŃŃŃ]{1,63}$/iu',
- 3 => '/^[\x{002d}0-9a-zâÎÄĹĹŁ]{1,63}$/iu',
- 4 => '/^[\x{002d}0-9Đ°-ŃŃ\x{04C2}]{1,63}$/iu',
- 5 => '/^[\x{002d}0-9a-zà åâèÊêÏĂÎòóôÚúÝÄĥħş]{1,63}$/iu',
- 6 => '/^[\x{002d}0-9a-zà äüÌÊêòóôÜøß]{1,63}$/iu',
- 7 => '/^[\x{002d}0-9a-zĂłÄ
ÄÄĹĹĹźş]{1,63}$/iu',
- 8 => '/^[\x{002d}0-9a-zà åâãçÊêĂòóôþúß]{1,63}$/iu',
- 9 => '/^[\x{002d}0-9a-zâÎÄĹĹŁ]{1,63}$/iu',
- 10=> '/^[\x{002d}0-9a-zåäÊĂóôúýÄÄĺĞĹĹĹĄĹĽĹž]{1,63}$/iu',
- 11=> '/^[\x{002d}0-9a-zçÍ]{1,63}$/iu',
- 12=> '/^[\x{002d}0-9Đ°-ик-ŃŃŃŃŃŃŃ]{1,63}$/iu',
- 13=> '/^[\x{002d}0-9a-zÄÄÄĹĄĹž]{1,63}$/iu',
- 14=> '/^[\x{002d}0-9a-zâçÜÝßÄÄąĹ]{1,63}$/iu',
- 15=> '/^[\x{002d}0-9a-zĂĄĂŠĂùóúß]{1,63}$/iu',
- 16=> '/^[\x{002d}0-9a-zäþÜßťŞ]{1,63}$/iu',
- 17=> '/^[\x{002d}0-9a-zÄÄÄĽÄľĹĹ]{1,63}$/iu',
- 18=> '/^[\x{002d}0-9a-zâäÊÍÎô]{1,63}$/iu',
- 19=> '/^[\x{002d}0-9a-zà åâäüÌçèÊêÍÏĂÎïðùòôÜøÚúÝßýÄÄĹĹĹĹĹĄ]{1,63}$/iu',
- 20=> '/^[\x{002d}0-9a-zäüÌþÜøßťŞ]{1,63}$/iu',
- 21=> '/^[\x{002d}0-9a-zà åçèÊÏĂòóÚú]{1,63}$/iu',
- 22=> '/^[\x{002d}0-9a-zĂ ĂĄĂŠĂóÜúßĹĹą]{1,63}$/iu',
- 23=> '/^[\x{002d}0-9ÎÎŹ-Ď]{1,63}$/iu',
- 24=> '/^[\x{002d}0-9a-zà åâüÌçèÊêÍðóôÜøßÞĹ]{1,63}$/iu',
- 25=> '/^[\x{002d}0-9a-zåäÊĂóÜúßýÄÄÄĹĹĹĄĹĽĹŻĹž]{1,63}$/iu',
- 26=> '/^[\x{002d}0-9a-z¡à çèÊĂïòóúß]{1,63}$/iu',
- 27=> '/^[\x{002d}0-9Đ°-ŃŃŃŃ\x{0450}\x{045D}]{1,63}$/iu',
- 28=> '/^[\x{002d}0-9Đ°-ŃŃŃŃ]{1,63}$/iu',
- 29=> '/^[\x{002d}0-9a-zÄ
ÄÄÄįťōųŞ]{1,63}$/iu',
- 30=> '/^[\x{002d}0-9a-zåäüÌÊÍĂðóÜøúßýÞ]{1,63}$/iu',
- 31=> '/^[\x{002d}0-9a-zà âÌçèÊêÍÎïùôÚÝßÿĹ]{1,63}$/iu',
- 32=> '/^[\x{002d}0-9Đ°-ŃŃŃŃŃŃŃŃŃŃŃŇ]{1,63}$/iu',
- 33=> '/^[\x{002d}0-9×-ת]{1,63}$/iu'),
- 'PR' => array(1 => '/^[\x{002d}0-9a-zĂĄĂŠĂóúùäÍïßÜâêÎôÝà èÚÌçĹĂŁĂľ]{1,63}$/iu'),
- 'PT' => array(1 => '/^[\x{002d}0-9a-zåà âãçÊêĂóôþú]{1,63}$/iu'),
- 'RU' => array(1 => '/^[\x{002d}0-9Đ°-ŃŃ]{1,63}$/iu'),
- 'SA' => array(1 => '/^[\x{002d}.0-9\x{0621}-\x{063A}\x{0641}-\x{064A}\x{0660}-\x{0669}]{1,63}$/iu'),
- 'SE' => array(1 => '/^[\x{002d}0-9a-zäüÊÜß]{1,63}$/iu'),
- 'SH' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄ
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄĥģļħÄĊįčĹľġĺĞğĹĹĹĹĹĹĹĹĹĸĹĹĹĹĹĹĄĹżţŧĹůŹŊųōžšźŞş]{1,63}$/iu'),
- 'SJ' => array(1 => '/^[\x{002d}0-9a-zà åä-ĂŠĂŞĂą-ôÜøßÄÄĹĹťŧŞ]{1,63}$/iu'),
- 'TH' => array(1 => '/^[\x{002d}0-9a-z\x{0E01}-\x{0E3A}\x{0E40}-\x{0E4D}\x{0E50}-\x{0E59}]{1,63}$/iu'),
- 'TM' => array(1 => '/^[\x{002d}0-9a-zĂ -Üø-ĂżÄÄÄ
ÄÄÄÄÄÄÄÄÄÄÄĥģļħčįľġĺğĞĹĹĹĹĹĹĹĹĹĹĹĹĹĹťţżŧōĹůŹųžšźşŞ]{1,63}$/iu'),
- 'TW' => 'Zend/Validator/Hostname/Cn.php',
- 'TR' => array(1 => '/^[\x{002d}0-9a-zÄĹßĹÜç]{1,63}$/iu'),
- 'VE' => array(1 => '/^[\x{002d}0-9a-zĂĄĂŠĂóúßù]{1,63}$/iu'),
- 'VN' => array(1 => '/^[ĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂà åâãèÊêÏĂòóôþÚúýÄÄÄÄÄ¨ÄŠĹ¨ĹŠĆ ĆĄĆŻĆ°\x{1EA0}-\x{1EF9}]{1,63}$/iu'),
- 'اŰعاŮ' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
- 'ä¸ĺ˝' => 'Zend/Validator/Hostname/Cn.php',
- 'ĺ
Źĺ¸' => 'Zend/Validator/Hostname/Cn.php',
- 'ç˝çť' => 'Zend/Validator/Hostname/Cn.php'
- );
- protected $_idnLength = array(
- 'BIZ' => array(5 => 17, 11 => 15, 12 => 20),
- 'CN' => array(1 => 20),
- 'COM' => array(3 => 17, 5 => 20),
- 'HK' => array(1 => 15),
- 'INFO'=> array(4 => 17),
- 'KR' => array(1 => 17),
- 'NET' => array(3 => 17, 5 => 20),
- 'ORG' => array(6 => 17),
- 'TW' => array(1 => 20),
- 'اŰعاŮ' => array(1 => 30),
- 'ä¸ĺ˝' => array(1 => 20),
- 'ĺ
Źĺ¸' => array(1 => 20),
- 'ç˝çť' => array(1 => 20),
- );
- protected $_options = array(
- 'allow' => self::ALLOW_DNS,
- 'idn' => true,
- 'tld' => true,
- 'ip' => null
- );
- public function __construct($options = array()) {
- if ($options instanceof \Zend\Config\Config) {
- $options = $options->toArray(); } else if (!is_array($options)) {
- $options = func_get_args();
- $temp['allow'] = array_shift($options);
- if (!empty($options)) {
- $temp['idn'] = array_shift($options); }
- if (!empty($options)) {
- $temp['tld'] = array_shift($options); }
- if (!empty($options)) {
- $temp['ip'] = array_shift($options); }
- $options = $temp; }
- $options += $this->_options;
- $this->setOptions($options); }
- public function getOptions() {
- return $this->_options; }
- public function setOptions($options) {
- if (array_key_exists('allow', $options)) {
- $this->setAllow($options['allow']); }
- if (array_key_exists('idn', $options)) {
- $this->setValidateIdn($options['idn']); }
- if (array_key_exists('tld', $options)) {
- $this->setValidateTld($options['tld']); }
- if (array_key_exists('ip', $options)) {
- $this->setIpValidator($options['ip']); }
- return $this; }
- public function getIpValidator() {
- return $this->_options['ip']; }
- public function setIpValidator(Ip $ipValidator = null) {
- if ($ipValidator === null) {
- $ipValidator = new Ip(); }
- $this->_options['ip'] = $ipValidator;
- return $this; }
- public function getAllow() {
- return $this->_options['allow']; }
- public function setAllow($allow) {
- $this->_options['allow'] = $allow;
- return $this; }
- public function getValidateIdn() {
- return $this->_options['idn']; }
- public function setValidateIdn ($allowed) {
- $this->_options['idn'] = (bool) $allowed;
- return $this; }
- public function getValidateTld() {
- return $this->_options['tld']; }
- public function setValidateTld ($allowed) {
- $this->_options['tld'] = (bool) $allowed;
- return $this; }
- public function isValid($value) {
- if (!is_string($value)) {
- $this->_error(self::INVALID);
- return false; }
- $this->_setValue($value);
- if (preg_match('/^[0-9.a-e:.]*$/i', $value) &&
- $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
- if (!($this->_options['allow'] & self::ALLOW_IP)) {
- $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
- return false; } else {
- return true; } }
- $domainParts = explode('.', $value);
- if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) {
- $status = false;
- $origenc = iconv_get_encoding('internal_encoding');
- iconv_set_encoding('internal_encoding', 'UTF-8');
- do {
- $matches = array();
- if (preg_match('/([^.]{2,10})$/i', end($domainParts), $matches) ||
- (end($domainParts) == 'اŰعاŮ') || (end($domainParts) == 'ä¸ĺ˝') ||
- (end($domainParts) == 'ĺ
Źĺ¸') || (end($domainParts) == 'ç˝çť')) {
- reset($domainParts);
- $this->_tld = strtolower($matches[1]);
- if ($this->_options['tld']) {
- if (!in_array($this->_tld, $this->_validTlds)) {
- $this->_error(self::UNKNOWN_TLD);
- $status = false;
- break; } }
- $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i');
- if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) {
- if (is_string($this->_validIdns[strtoupper($this->_tld)])) {
- $regexChars += include($this->_validIdns[strtoupper($this->_tld)]); } else {
- $regexChars += $this->_validIdns[strtoupper($this->_tld)]; } }
- $check = 0;
- foreach ($domainParts as $domainPart) {
- if (strpos($domainPart, 'xn--') === 0) {
- $domainPart = $this->decodePunycode(substr($domainPart, 4));
- if ($domainPart === false) {
- return false; } }
- if ((strpos($domainPart, '-') === 0)
- || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3))
- || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) {
- $this->_error(self::INVALID_DASH);
- $status = false;
- break 2; }
- $checked = false;
- foreach($regexChars as $regexKey => $regexChar) {
- $status = @preg_match($regexChar, $domainPart);
- if ($status > 0) {
- $length = 63;
- if (array_key_exists(strtoupper($this->_tld), $this->_idnLength)
- && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) {
- $length = $this->_idnLength[strtoupper($this->_tld)]; }
- if (iconv_strlen($domainPart, 'UTF-8') > $length) {
- $this->_error(self::INVALID_HOSTNAME); } else {
- $checked = true;
- break; } } }
- if ($checked) {
- ++$check; } }
- if ($check !== count($domainParts)) {
- $this->_error(self::INVALID_HOSTNAME_SCHEMA);
- $status = false; } } else {
- $this->_error(self::UNDECIPHERABLE_TLD);
- $status = false; } } while (false);
- iconv_set_encoding('internal_encoding', $origenc);
- if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) {
- return true; } } else if ($this->_options['allow'] & self::ALLOW_DNS) {
- $this->_error(self::INVALID_HOSTNAME); }
- $regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}){1,254}$/';
- $status = @preg_match($regexLocal, $value);
- $allowLocal = $this->_options['allow'] & self::ALLOW_LOCAL;
- if ($status && $allowLocal) {
- return true; }
- if (!$status) {
- $this->_error(self::INVALID_LOCAL_NAME); }
- if ($status && !$allowLocal) {
- $this->_error(self::LOCAL_NAME_NOT_ALLOWED); }
- return false; }
- protected function decodePunycode($encoded) {
- $found = preg_match('/([^a-z0-9\x2d]{1,10})$/i', $encoded);
- if (empty($encoded) || ($found > 0)) {
- $this->_error(self::CANNOT_DECODE_PUNYCODE);
- return false; }
- $separator = strrpos($encoded, '-');
- if ($separator > 0) {
- for ($x = 0; $x < $separator; ++$x) {
- $decoded[] = ord($encoded[$x]); } } else {
- $this->_error(self::CANNOT_DECODE_PUNYCODE);
- return false; }
- $lengthd = count($decoded);
- $lengthe = strlen($encoded);
- $init = true;
- $base = 72;
- $index = 0;
- $char = 0x80;
- for ($indexe = ($separator) ? ($separator + 1) : 0; $indexe < $lengthe; ++$lengthd) {
- for ($old_index = $index, $pos = 1, $key = 36; 1 ; $key += 36) {
- $hex = ord($encoded[$indexe++]);
- $digit = ($hex - 48 < 10) ? $hex - 22
- : (($hex - 65 < 26) ? $hex - 65
- : (($hex - 97 < 26) ? $hex - 97
- : 36));
- $index += $digit * $pos;
- $tag = ($key <= $base) ? 1 : (($key >= $base + 26) ? 26 : ($key - $base));
- if ($digit < $tag) {
- break; }
- $pos = (int) ($pos * (36 - $tag)); }
- $delta = intval($init ? (($index - $old_index) / 700) : (($index - $old_index) / 2));
- $delta += intval($delta / ($lengthd + 1));
- for ($key = 0; $delta > 910 / 2; $key += 36) {
- $delta = intval($delta / 35); }
- $base = intval($key + 36 * $delta / ($delta + 38));
- $init = false;
- $char += (int) ($index / ($lengthd + 1));
- $index %= ($lengthd + 1);
- if ($lengthd > 0) {
- for ($i = $lengthd; $i > $index; $i--) {
- $decoded[$i] = $decoded[($i - 1)]; } }
- $decoded[$index++] = $char; }
- foreach ($decoded as $key => $value) {
- if ($value < 128) {
- $decoded[$key] = chr($value); } elseif ($value < (1 << 11)) {
- $decoded[$key] = chr(192 + ($value >> 6));
- $decoded[$key] .= chr(128 + ($value & 63)); } elseif ($value < (1 << 16)) {
- $decoded[$key] = chr(224 + ($value >> 12));
- $decoded[$key] .= chr(128 + (($value >> 6) & 63));
- $decoded[$key] .= chr(128 + ($value & 63)); } elseif ($value < (1 << 21)) {
- $decoded[$key] = chr(240 + ($value >> 18));
- $decoded[$key] .= chr(128 + (($value >> 12) & 63));
- $decoded[$key] .= chr(128 + (($value >> 6) & 63));
- $decoded[$key] .= chr(128 + ($value & 63)); } else {
- $this->_error(self::CANNOT_DECODE_PUNYCODE);
- return false; } }
- return implode($decoded); } }
- <?php
- namespace Zend\Validator;
- class Ip extends AbstractValidator {
- const INVALID = 'ipInvalid';
- const NOT_IP_ADDRESS = 'notIpAddress';
- protected $_messageTemplates = array(
- self::INVALID => "Invalid type given. String expected",
- self::NOT_IP_ADDRESS => "'%value%' does not appear to be a valid IP address",
- );
- protected $_options = array(
- 'allowipv6' => true,
- 'allowipv4' => true
- );
- public function __construct($options = array()) {
- if ($options instanceof \Zend\Config\Config) {
- $options = $options->toArray(); } else if (!is_array($options)) {
- $options = func_get_args();
- $temp['allowipv6'] = array_shift($options);
- if (!empty($options)) {
- $temp['allowipv4'] = array_shift($options); }
- $options = $temp; }
- $options += $this->_options;
- $this->setOptions($options); }
- public function getOptions() {
- return $this->_options; }
- public function setOptions($options) {
- if (array_key_exists('allowipv6', $options)) {
- $this->_options['allowipv6'] = (boolean) $options['allowipv6']; }
- if (array_key_exists('allowipv4', $options)) {
- $this->_options['allowipv4'] = (boolean) $options['allowipv4']; }
- if (!$this->_options['allowipv4'] && !$this->_options['allowipv6']) {
- throw new Exception('Nothing to validate. Check your options'); }
- return $this; }
- public function isValid($value) {
- if (!is_string($value)) {
- $this->_error(self::INVALID);
- return false; }
- $this->_setValue($value…
Large files files are truncated, but you can click here to view the full file