diff --git a/readme.md b/readme.md index ddea5d23..a256fe9f 100644 --- a/readme.md +++ b/readme.md @@ -38,13 +38,27 @@ echo $faker->lorem; Each of the generator properties (like `name`, `address`, and `lorem`) are called "formatters". A faker generator has many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale. +### `Faker\Provider\Internet` + + domainName() // 'mueller.info' + domainWord() // 'von' + email() // 'cshields@rosenbaum.com' + freeEmail() // 'dayna55@gmail.com' + freeEmailDomain() // 'yahoo.com' + ipv4() // '237.149.115.38' + ipv6() // '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1' + safeEmail() // 'nbatz@example.org' + tld() // 'info' + url() // 'http://www.runolfsdottir.com/' + userName() // 'tremblay.haylie' + ### `Faker\Provider\Lorem` - lorem() // 'Fuga totam reiciendis qui architecto fugiat. (...) Voluptas optio quos sed.' + lorem() // 'Fuga totam reiciendis qui architecto fugiat. (...)' paragraph() // 'Sed a nam et sint autem. Aut officia aut. Blanditiis et ducimus.' - paragraphs() // array('Amet et est.', (...) 'Rerum exercitationem est.') + paragraphs() // array('Amet et est. (...)', 'Sequi cum culpa rem. Rerum exercitationem est.') sentence() // 'Sit vitae voluptas sint non.' - sentences() // array('Ut optio quos qui illo error nihil.', ('Vero a officia id corporis incidunt.' (...), 'Provident esse hic eligendi quos culpa ut.') + sentences() // array('Ut optio quos qui illo error nihil.', 'Vero a officia id corporis incidunt.', 'Provident esse hic eligendi quos culpa ut.') word() // 'aut' words() // array('porro', 'sed', 'magni') @@ -81,8 +95,8 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle ### `Faker\Provider\en_US\PhoneNumber` - phoneNumber() // '132-149-0269x3767' - + phoneNumber() // '132-149-0269x3767' + ## Localization `Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale. diff --git a/src/Factory.php b/src/Factory.php index 8b0fc449..e6fb68b3 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -8,7 +8,7 @@ class Factory { const DEFAULT_LOCALE = 'en_US'; - protected static $defaultProviders = array('Name', 'Address', 'PhoneNumber', 'Company', 'Lorem'); + protected static $defaultProviders = array('Name', 'Address', 'PhoneNumber', 'Company', 'Lorem', 'Internet'); public static function create($locale = self::DEFAULT_LOCALE) { diff --git a/src/Provider/Internet.php b/src/Provider/Internet.php new file mode 100644 index 00000000..a15bb9a7 --- /dev/null +++ b/src/Provider/Internet.php @@ -0,0 +1,126 @@ +generator->parse($format); + } + + /** + * @example 'jdoe@example.com' + */ + public function safeEmail() + { + return $this->userName() . '@example.' . static::randomElement(static::$safeEmailTld); + } + + /** + * @example 'jdoe@gmail.com' + */ + public function freeEmail() + { + return $this->userName() . '@' . static::freeEmailDomain(); + } + + /** + * @example 'gmail.com' + */ + public static function freeEmailDomain() + { + return static::randomElement(static::$freeEmailDomain); + } + + /** + * @example 'jdoe' + */ + public function userName() + { + $format = static::randomElement(static::$userNameFormats); + return strtolower(static::bothify($this->generator->parse($format))); + } + + /** + * @example 'tiramisu.com' + */ + public function domainName() + { + return $this->domainWord() . '.' . $this->tld(); + } + + /** + * @example 'faber' + */ + public function domainWord() + { + $company = $this->generator->format('company'); + $companyElements = explode(' ', $company); + $company = $companyElements[0]; + $company = preg_replace('/\W/', '', $company); + + return strtolower($company); + } + + /** + * @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 '237.149.115.38' + */ + public function ipv4() + { + return long2ip(mt_rand(0, "4294967295")); + } + + /** + * @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); + } +} \ No newline at end of file diff --git a/test/test.php b/test/test.php index cb3d2e5d..932da57a 100644 --- a/test/test.php +++ b/test/test.php @@ -5,7 +5,7 @@ $generator = Faker\Factory::create(); - + address ?> @@ -21,7 +21,7 @@ $generator = Faker\Factory::create(); bs ?> - +