<?php namespace Faker\Provider; class Internet extends \Faker\Provider\Base { protected static $freeEmailDomain = array('gmail.com', 'yahoo.com', 'hotmail.com'); protected static $tld = array('com', 'com', 'com', 'com', 'com', 'com', 'biz', 'info', 'net', 'org'); protected static $userNameFormats = array( '{{lastName}}.{{firstName}}', '{{firstName}}.{{lastName}}', '{{firstName}}##', '?{{lastName}}', ); protected static $emailFormats = array( '{{userName}}@{{domainName}}', '{{userName}}@{{freeEmailDomain}}', ); protected static $urlFormats = array( 'http://www.{{domainName}}/', 'http://{{domainName}}/', 'http://www.{{domainName}}/{{slug}}', 'http://www.{{domainName}}/{{slug}}', 'https://www.{{domainName}}/{{slug}}', 'http://www.{{domainName}}/{{slug}}.html', 'http://{{domainName}}/{{slug}}', 'http://{{domainName}}/{{slug}}', 'http://{{domainName}}/{{slug}}.html', 'https://{{domainName}}/{{slug}}.html', ); public static function toAscii($string) { $transliterationTable = array( 'IJ' => 'I','Ö' => 'O','Å’' => 'O','Ãœ' => 'U','ä' => 'a','æ' => 'a', 'ij' => 'i','ö' => 'o','Å“' => 'o','ü' => 'u','ß' => 's','Å¿' => 's', 'À' => 'A','Ã' => 'A','Â' => 'A','Ã' => 'A','Ä' => 'A','Ã…' => 'A', 'Æ' => 'A','Ä€' => 'A','Ä„' => 'A','Ä‚' => 'A','Ç' => 'C','Ć' => 'C', 'ÄŒ' => 'C','Ĉ' => 'C','ÄŠ' => 'C','ÄŽ' => 'D','Ä' => 'D','È' => 'E', 'É' => 'E','Ê' => 'E','Ë' => 'E','Ä’' => 'E','Ę' => 'E','Äš' => 'E', 'Ä”' => 'E','Ä–' => 'E','Äœ' => 'G','Äž' => 'G','Ä ' => 'G','Ä¢' => 'G', 'Ĥ' => 'H','Ħ' => 'H','ÃŒ' => 'I','Ã' => 'I','ÃŽ' => 'I','Ã' => 'I', 'Ī' => 'I','Ĩ' => 'I','Ĭ' => 'I','Ä®' => 'I','Ä°' => 'I','Ä´' => 'J', 'Ķ' => 'K','Ľ' => 'K','Ĺ' => 'K','Ä»' => 'K','Ä¿' => 'K','Å' => 'L', 'Ñ' => 'N','Ń' => 'N','Ň' => 'N','Å…' => 'N','ÅŠ' => 'N','Ã’' => 'O', 'Ó' => 'O','Ô' => 'O','Õ' => 'O','Ø' => 'O','ÅŒ' => 'O','Å' => 'O', 'ÅŽ' => 'O','Å”' => 'R','Ř' => 'R','Å–' => 'R','Åš' => 'S','Åž' => 'S', 'Åœ' => 'S','Ș' => 'S','Å ' => 'S','Ť' => 'T','Å¢' => 'T','Ŧ' => 'T', 'Èš' => 'T','Ù' => 'U','Ú' => 'U','Û' => 'U','Ū' => 'U','Å®' => 'U', 'Å°' => 'U','Ŭ' => 'U','Ũ' => 'U','Ų' => 'U','Å´' => 'W','Ŷ' => 'Y', 'Ÿ' => 'Y','Ã' => 'Y','Ź' => 'Z','Å»' => 'Z','Ž' => 'Z','à ' => 'a', 'á' => 'a','â' => 'a','ã' => 'a','Ä' => 'a','Ä…' => 'a','ă' => 'a', 'Ã¥' => 'a','ç' => 'c','ć' => 'c','Ä' => 'c','ĉ' => 'c','Ä‹' => 'c', 'Ä' => 'd','Ä‘' => 'd','è' => 'e','é' => 'e','ê' => 'e','ë' => 'e', 'Ä“' => 'e','Ä™' => 'e','Ä›' => 'e','Ä•' => 'e','Ä—' => 'e','Æ’' => 'f', 'Ä' => 'g','ÄŸ' => 'g','Ä¡' => 'g','Ä£' => 'g','Ä¥' => 'h','ħ' => 'h', 'ì' => 'i','Ã' => 'i','î' => 'i','ï' => 'i','Ä«' => 'i','Ä©' => 'i', 'Ä' => 'i','į' => 'i','ı' => 'i','ĵ' => 'j','Ä·' => 'k','ĸ' => 'k', 'Å‚' => 'l','ľ' => 'l','ĺ' => 'l','ļ' => 'l','Å€' => 'l','ñ' => 'n', 'Å„' => 'n','ň' => 'n','ņ' => 'n','ʼn' => 'n','Å‹' => 'n','ò' => 'o', 'ó' => 'o','ô' => 'o','õ' => 'o','ø' => 'o','Å' => 'o','Å‘' => 'o', 'Å' => 'o','Å•' => 'r','Å™' => 'r','Å—' => 'r','Å›' => 's','Å¡' => 's', 'Å¥' => 't','ù' => 'u','ú' => 'u','û' => 'u','Å«' => 'u','ů' => 'u', 'ű' => 'u','Å' => 'u','Å©' => 'u','ų' => 'u','ŵ' => 'w','ÿ' => 'y', 'ý' => 'y','Å·' => 'y','ż' => 'z','ź' => 'z','ž' => 'z','Α' => 'A', 'Ά' => 'A','Ἀ' => 'A','Ἁ' => 'A','Ἂ' => 'A','Ἃ' => 'A','Ἄ' => 'A', 'á¼' => 'A','Ἆ' => 'A','á¼' => 'A','ᾈ' => 'A','ᾉ' => 'A','ᾊ' => 'A', 'ᾋ' => 'A','ᾌ' => 'A','á¾' => 'A','ᾎ' => 'A','á¾' => 'A','Ᾰ' => 'A', 'á¾¹' => 'A','Ὰ' => 'A','á¾¼' => 'A','Î’' => 'B','Γ' => 'G','Δ' => 'D', 'Ε' => 'E','Έ' => 'E','Ἐ' => 'E','á¼™' => 'E','Ἒ' => 'E','á¼›' => 'E', 'Ἔ' => 'E','á¼' => 'E','Ὲ' => 'E','Ζ' => 'Z','Η' => 'I','Ή' => 'I', 'Ἠ' => 'I','Ἡ' => 'I','Ἢ' => 'I','Ἣ' => 'I','Ἤ' => 'I','á¼' => 'I', 'á¼®' => 'I','Ἧ' => 'I','ᾘ' => 'I','á¾™' => 'I','ᾚ' => 'I','á¾›' => 'I', 'ᾜ' => 'I','á¾' => 'I','ᾞ' => 'I','ᾟ' => 'I','á¿Š' => 'I','á¿Œ' => 'I', 'Θ' => 'T','Ι' => 'I','Ί' => 'I','Ϊ' => 'I','Ἰ' => 'I','á¼¹' => 'I', 'Ἲ' => 'I','á¼»' => 'I','á¼¼' => 'I','á¼½' => 'I','á¼¾' => 'I','Ἷ' => 'I', 'Ῐ' => 'I','á¿™' => 'I','á¿š' => 'I','Κ' => 'K','Λ' => 'L','Îœ' => 'M', 'Î' => 'N','Ξ' => 'K','Ο' => 'O','ÎŒ' => 'O','Ὀ' => 'O','Ὁ' => 'O', 'Ὂ' => 'O','Ὃ' => 'O','Ὄ' => 'O','á½' => 'O','Ὸ' => 'O','Î ' => 'P', 'Ρ' => 'R','Ῥ' => 'R','Σ' => 'S','Τ' => 'T','Î¥' => 'Y','ÎŽ' => 'Y', 'Ϋ' => 'Y','á½™' => 'Y','á½›' => 'Y','á½' => 'Y','Ὗ' => 'Y','Ῠ' => 'Y', 'á¿©' => 'Y','Ὺ' => 'Y','Φ' => 'F','Χ' => 'X','Ψ' => 'P','Ω' => 'O', 'Î' => 'O','Ὠ' => 'O','Ὡ' => 'O','Ὢ' => 'O','Ὣ' => 'O','Ὤ' => 'O', 'á½' => 'O','á½®' => 'O','Ὧ' => 'O','ᾨ' => 'O','ᾩ' => 'O','ᾪ' => 'O', 'ᾫ' => 'O','ᾬ' => 'O','á¾' => 'O','á¾®' => 'O','ᾯ' => 'O','Ὼ' => 'O', 'ῼ' => 'O','α' => 'a','ά' => 'a','á¼€' => 'a','á¼' => 'a','ἂ' => 'a', 'ἃ' => 'a','ἄ' => 'a','á¼…' => 'a','ἆ' => 'a','ἇ' => 'a','á¾€' => 'a', 'á¾' => 'a','ᾂ' => 'a','ᾃ' => 'a','ᾄ' => 'a','á¾…' => 'a','ᾆ' => 'a', 'ᾇ' => 'a','á½°' => 'a','á¾°' => 'a','á¾±' => 'a','á¾²' => 'a','á¾³' => 'a', 'á¾´' => 'a','ᾶ' => 'a','á¾·' => 'a','β' => 'b','γ' => 'g','δ' => 'd', 'ε' => 'e','Î' => 'e','á¼' => 'e','ἑ' => 'e','á¼’' => 'e','ἓ' => 'e', 'á¼”' => 'e','ἕ' => 'e','á½²' => 'e','ζ' => 'z','η' => 'i','ή' => 'i', 'á¼ ' => 'i','ἡ' => 'i','á¼¢' => 'i','á¼£' => 'i','ἤ' => 'i','á¼¥' => 'i', 'ἦ' => 'i','ἧ' => 'i','á¾' => 'i','ᾑ' => 'i','á¾’' => 'i','ᾓ' => 'i', 'á¾”' => 'i','ᾕ' => 'i','á¾–' => 'i','á¾—' => 'i','á½´' => 'i','á¿‚' => 'i', 'ῃ' => 'i','á¿„' => 'i','ῆ' => 'i','ῇ' => 'i','θ' => 't','ι' => 'i', 'ί' => 'i','ÏŠ' => 'i','Î' => 'i','á¼°' => 'i','á¼±' => 'i','á¼²' => 'i', 'á¼³' => 'i','á¼´' => 'i','á¼µ' => 'i','ἶ' => 'i','á¼·' => 'i','ὶ' => 'i', 'á¿' => 'i','á¿‘' => 'i','á¿’' => 'i','á¿–' => 'i','á¿—' => 'i','κ' => 'k', 'λ' => 'l','μ' => 'm','ν' => 'n','ξ' => 'k','ο' => 'o','ÏŒ' => 'o', 'á½€' => 'o','á½' => 'o','ὂ' => 'o','ὃ' => 'o','ὄ' => 'o','á½…' => 'o', 'ὸ' => 'o','Ï€' => 'p','Ï' => 'r','ῤ' => 'r','á¿¥' => 'r','σ' => 's', 'Ï‚' => 's','Ï„' => 't','Ï…' => 'y','Ï' => 'y','Ï‹' => 'y','ΰ' => 'y', 'á½' => 'y','ὑ' => 'y','á½’' => 'y','ὓ' => 'y','á½”' => 'y','ὕ' => 'y', 'á½–' => 'y','á½—' => 'y','ὺ' => 'y','á¿ ' => 'y','á¿¡' => 'y','á¿¢' => 'y', 'ῦ' => 'y','ῧ' => 'y','φ' => 'f','χ' => 'x','ψ' => 'p','ω' => 'o', 'ÏŽ' => 'o','á½ ' => 'o','ὡ' => 'o','á½¢' => 'o','á½£' => 'o','ὤ' => 'o', 'á½¥' => 'o','ὦ' => 'o','ὧ' => 'o','á¾ ' => 'o','ᾡ' => 'o','á¾¢' => 'o', 'á¾£' => 'o','ᾤ' => 'o','á¾¥' => 'o','ᾦ' => 'o','ᾧ' => 'o','á½¼' => 'o', 'ῲ' => 'o','ῳ' => 'o','á¿´' => 'o','ῶ' => 'o','á¿·' => 'o','Ð' => 'A', 'Б' => 'B','Ð’' => 'V','Г' => 'G','Д' => 'D','Е' => 'E','Ð' => 'E', 'Ж' => 'Z','З' => 'Z','И' => 'I','Й' => 'I','К' => 'K','Л' => 'L', 'Ðœ' => 'M','Ð' => 'N','О' => 'O','П' => 'P','Ð ' => 'R','С' => 'S', 'Т' => 'T','У' => 'U','Ф' => 'F','Ð¥' => 'K','Ц' => 'T','Ч' => 'C', 'Ш' => 'S','Щ' => 'S','Ы' => 'Y','Ð' => 'E','Ю' => 'Y','Я' => 'Y', 'а' => 'A','б' => 'B','в' => 'V','г' => 'G','д' => 'D','е' => 'E', 'Ñ‘' => 'E','ж' => 'Z','з' => 'Z','и' => 'I','й' => 'I','к' => 'K', 'л' => 'L','м' => 'M','н' => 'N','о' => 'O','п' => 'P','Ñ€' => 'R', 'Ñ' => 'S','Ñ‚' => 'T','у' => 'U','Ñ„' => 'F','Ñ…' => 'K','ц' => 'T', 'ч' => 'C','ш' => 'S','щ' => 'S','Ñ‹' => 'Y','Ñ' => 'E','ÑŽ' => 'Y', 'Ñ' => 'Y','ð' => 'd','Ã' => 'D','þ' => 't','Þ' => 'T','áƒ' => 'a', 'ბ' => 'b','გ' => 'g','დ' => 'd','ე' => 'e','ვ' => 'v','ზ' => 'z', 'თ' => 't','ი' => 'i','კ' => 'k','ლ' => 'l','მ' => 'm','ნ' => 'n', 'áƒ' => 'o','პ' => 'p','ჟ' => 'z','რ' => 'r','ს' => 's','ტ' => 't', 'უ' => 'u','ფ' => 'p','ქ' => 'k','ღ' => 'g','ყ' => 'q','შ' => 's', 'ჩ' => 'c','ც' => 't','ძ' => 'd','წ' => 't','áƒ' => 'c','ხ' => 'k', 'ჯ' => 'j','ჰ' => 'h','Ä' => 'a','Å£' => 't','ʼ' => "'", '̧' => '', 'ḩ' => 'h','ʼ' => "'",'‘' => "'",'’' => "'",'ừ' => 'u','/' => '', 'ế' => 'e','ả' => 'a','ị' => 'i','áº' => 'a','ệ' => 'e','ỉ' => 'i', 'ồ' => 'o','á»' => 'e','Æ¡' => 'o','ạ' => 'a','ẵ' => 'a','Æ°' => 'u', 'ằ' => 'a','ầ' => 'a','ḑ' => 'd','Ḩ' => 'H','á¸' => 'D','ḑ' => 'd', 'Ä¢' => 'G','Å ' => 'S','ļ' => 'l','ž' => 'z','Ä’' => 'E','ņ' => 'n', 'ÄŒ' => 'C','È™' => 's','È›' => 't', 'á»™' => 'o','ắ' => 'a','ÅŸ' => 's', "'" => '', 'Õ¸Ö‚' => 'u','Õ¡' => 'a','Õ¢' => 'b','Õ£' => 'g','Õ¤' => 'd', 'Õ¥' => 'e','Õ¦' => 'z','Õ§' => 'e','Õ¨' => 'y','Õ©' => 't','Õª' => 'zh', 'Õ«' => 'i','Õ¬' => 'l','Õ' => 'kh','Õ®' => 'ts','Õ¯' => 'k','Õ°' => 'h', 'Õ±' => 'dz','Õ²' => 'gh','Õ³' => 'ch','Õ´' => 'm','Õµ' => 'y','Õ¶' => 'n', 'Õ·' => 'sh','Õ¸' => 'o','Õ¹' => 'ch','Õº' => 'p','Õ»' => 'j','Õ¼' => 'r', 'Õ½' => 's','Õ¾' => 'v','Õ¿' => 't','Ö€' => 'r','Ö' => 'ts','Öƒ' => 'p', 'Ö„' => 'q','Ö‡' => 'ev','Ö…' => 'o','Ö†' => 'f', ); return str_replace(array_keys($transliterationTable), array_values($transliterationTable), $string); } private static function transliterate($string) { $transId = 'Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; Lower();'; if (function_exists('transliterator_transliterate') && $transliterator = \Transliterator::create($transId)) { $transString = $transliterator->transliterate($string); } else { $transString = static::toAscii($string); } return preg_replace('/[^A-Za-z0-9_.]/u', '', $transString); } /** * @example 'jdoe@acme.biz' */ public function email() { $format = static::randomElement(static::$emailFormats); return $this->generator->parse($format); } /** * @example 'jdoe@example.com' */ final public function safeEmail() { return preg_replace('/\s/u', '', $this->userName() . '@' . static::safeEmailDomain()); } /** * @example 'jdoe@gmail.com' */ public function freeEmail() { return preg_replace('/\s/u', '', $this->userName() . '@' . static::freeEmailDomain()); } /** * @example 'jdoe@dawson.com' */ public function companyEmail() { return preg_replace('/\s/u', '', $this->userName() . '@' . $this->domainName()); } /** * @example 'gmail.com' */ public static function freeEmailDomain() { return static::randomElement(static::$freeEmailDomain); } /** * @example 'example.org' */ final public static function safeEmailDomain() { $domains = array( 'example.com', 'example.org', 'example.net' ); return static::randomElement($domains); } /** * @example 'jdoe' */ public function userName() { $format = static::randomElement(static::$userNameFormats); $username = static::bothify($this->generator->parse($format)); return static::transliterate($username); } /** * @example 'fY4èHdZv68' */ public function password($minLength = 6, $maxLength = 20) { $pattern = str_repeat('*', $this->numberBetween($minLength, $maxLength)); return $this->asciify($pattern); } /** * @example 'tiramisu.com' */ public function domainName() { return $this->domainWord() . '.' . $this->tld(); } /** * @example 'faber' */ public function domainWord() { $lastName = $this->generator->format('lastName'); return static::transliterate($lastName); } /** * @example 'com' */ public function tld() { return static::randomElement(static::$tld); } /** * @example 'http://www.runolfsdottir.com/' */ public function url() { $format = static::randomElement(static::$urlFormats); return $this->generator->parse($format); } /** * @example 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum' */ public function slug($nbWords = 6, $variableNbWords = true) { if ($nbWords <= 0) { return ''; } if ($variableNbWords) { $nbWords = (int) ($nbWords * mt_rand(60, 140) / 100) + 1; } $words = $this->generator->words($nbWords); return join($words, '-'); } /** * @example '237.149.115.38' */ public function ipv4() { return long2ip(mt_rand(0, 1) == 0 ? mt_rand(-2147483648, 0) : mt_rand(1, 2147483647)); } /** * @example '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1' */ public function ipv6() { $res = array(); for ($i=0; $i < 8; $i++) { $res []= dechex(mt_rand(0, "65535")); } return join(':', $res); } /** * @example '10.1.1.17' */ public static function localIpv4() { if (static::numberBetween(0, 1) === 0) { // 10.x.x.x range $ip = long2ip(static::numberBetween(167772160, 184549375)); } else { // 192.168.x.x range $ip = long2ip(static::numberBetween(3232235520, 3232301055)); } return $ip; } /** * @example '32:F1:39:2F:D6:18' */ public static function macAddress() { for ($i=0; $i<6; $i++) { $mac[] = sprintf('%02X', static::numberBetween(0, 0xff)); } $mac = implode(':', $mac); return $mac; } }