File manager - Edit - /home/autoph/public_html/projects/api/public/faker.tar
Back
composer.json 0000644 00000002671 15025036220 0007267 0 ustar 00 { "name": "fakerphp/faker", "type": "library", "description": "Faker is a PHP library that generates fake data for you.", "keywords": [ "faker", "fixtures", "data" ], "license": "MIT", "authors": [ { "name": "François Zaninotto" } ], "require": { "php": "^7.4 || ^8.0", "psr/container": "^2.0", "symfony/deprecation-contracts": "^3.0" }, "require-dev": { "ext-intl": "*", "bamarni/composer-bin-plugin": "^1.4.1", "symfony/phpunit-bridge": "^4.4 || ^5.2" }, "autoload": { "psr-4": { "Faker\\": "src/" } }, "autoload-dev": { "psr-4": { "Faker\\Test\\": "test/Faker/", "Faker\\Test\\Fixture\\": "test/Fixture/" } }, "conflict": { "fzaninotto/faker": "*" }, "suggest": { "ext-curl": "Required by Faker\\Provider\\Image to download images.", "ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.", "ext-mbstring": "Required for multibyte Unicode string functionality." }, "config": { "allow-plugins": { "bamarni/composer-bin-plugin": true, "composer/package-versions-deprecated": true }, "sort-packages": true }, "extra": { "branch-alias": { "dev-main": "v1.19-dev" } } } CHANGELOG.md 0000644 00000015152 15025036220 0006354 0 ustar 00 # CHANGELOG ## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.19.0...main) ## [2022-02-02, v1.19.0](https://github.com/FakerPHP/Faker/compare/v1.18.0..v1.19.0) - Added color extension to core (#442) - Added conflict with `doctrine/persistence` below version `1.4` - Fix for support on different Doctrine ORM versions (#414) - Fix usage of `Doctrine\Persistence` dependency - Fix CZ Person birthNumber docblock return type (#437) - Fix is_IS Person docbock types (#439) - Fix is_IS Address docbock type (#438) - Fix regexify escape backslash in character class (#434) - Removed UUID from Generator to be able to extend it (#441) - ## [2022-01-23, v1.18.0](https://github.com/FakerPHP/Faker/compare/v1.17.0..v1.18.0) - Deprecated UUID, use uuid3 to specify version (#427) - Reset formatters when adding a new provider (#366) - Helper methods to use our custom generators (#155) - Set allow-plugins for Composer 2.2 (#405) - Fix kk_KZ\Person::individualIdentificationNumber generation (#411) - Allow for -> syntax to be used in parsing (#423) - Person->name was missing string return type (#424) - Generate a valid BE TAX number (#415) - Added the UUID extension to Core (#427) ## [2021-12-05, v1.17.0](https://github.com/FakerPHP/Faker/compare/v1.16.0..v1.17.0) - Partial PHP 8.1 compatibility (#373) - Add payment provider for `ne_NP` locale (#375) - Add Egyptian Arabic `ar_EG` locale (#377) - Updated list of South African TLDs (#383) - Fixed formatting of E.164 numbers (#380) - Allow `symfony/deprecation-contracts` `^3.0` (#397) ## [2021-09-06, v1.16.0](https://github.com/FakerPHP/Faker/compare/v1.15.0..v1.16.0) - Add Company extension - Add Address extension - Add Person extension - Add PhoneNumber extension - Add VersionExtension (#350) - Stricter types in Extension\Container and Extension\GeneratorAwareExtension (#345) - Fix deprecated property access in `nl_NL` (#348) - Add support for `psr/container` >= 2.0 (#354) - Add missing union types in Faker\Generator (#352) ## [2021-07-06, v1.15.0](https://github.com/FakerPHP/Faker/compare/v1.14.1..v1.15.0) - Updated the generator phpdoc to help identify magic methods (#307) - Prevent direct access and triggered deprecation warning for "word" (#302) - Updated length on all global e164 numbers (#301) - Updated last names from different source (#312) - Don't generate birth number of '000' for Swedish personal identity (#306) - Add job list for localization id_ID (#339) ## [2021-03-30, v1.14.1](https://github.com/FakerPHP/Faker/compare/v1.14.0..v1.14.1) - Fix where randomNumber and randomFloat would return a 0 value (#291 / #292) ## [2021-03-29, v1.14.0](https://github.com/FakerPHP/Faker/compare/v1.13.0..v1.14.0) - Fix for realText to ensure the text keeps closer to its boundaries (#152) - Fix where regexify produces a random character instead of a literal dot (#135 - Deprecate zh_TW methods that only call base methods (#122) - Add used extensions to composer.json as suggestion (#120) - Moved TCNo and INN from calculator to localized providers (#108) - Fix regex dot/backslash issue where a dot is replaced with a backslash as escape character (#206) - Deprecate direct property access (#164) - Added test to assert unique() behaviour (#233) - Added RUC for the es_PE locale (#244) - Test IBAN formats for Latin America (AR/PE/VE) (#260) - Added VAT number for en_GB (#255) - Added new districts for the ne_NP locale (#258) - Fix for U.S. Area Code Generation (#261) - Fix in numerify where a better random numeric value is guaranteed (#256) - Fix e164PhoneNumber to only generate valid phone numbers with valid country codes (#264) - Extract fixtures into separate classes (#234) - Remove french domains that no longer exists (#277) - Fix error that occurs when getting a polish title (#279) - Use valid area codes for North America E164 phone numbers (#280) - Adding support for extensions and PSR-11 (#154) - Adding trait for GeneratorAwareExtension (#165) - Added helper class for extension (#162) - Added blood extension to core (#232) - Added barcode extension to core (#252) - Added number extension (#257) - Various code style updates - Added a note about our breaking change promise (#273) ## [2020-12-18, v1.13.0](https://github.com/FakerPHP/Faker/compare/v1.12.1..v1.13.0) Several fixes and new additions in this release. A lot of cleanup has been done on the codebase on both tests and consistency. - Feature/pl pl license plate (#62) - Fix greek phone numbers (#16) - Move AT payment provider logic to de_AT (#72) - Fix wiktionary links (#73) - Fix AT person links (#74) - Fix AT cities (#75) - Deprecate at_AT providers (#78) - Add Austrian `ssn()` to `Person` provider (#79) - Fix typos in id_ID Address (#83) - Austrian post codes (#86) - Updated Polish data (#70) - Improve Austrian social security number generation (#88) - Move US phone numbers with extension to own method (#91) - Add UK National Insurance number generator (#89) - Fix en_SG phone number generator (#100) - Remove usage of mt_rand (#87) - Remove whitespace from beginning of el_GR phone numbers (#105) - Building numbers can not be 0, 00, 000 (#107) - Add 172.16/12 local IPv4 block (#121) - Add JCB credit card type (#124) - Remove json_decode from emoji generation (#123) - Remove ro street address (#146) ## [2020-12-11, v1.12.1](https://github.com/FakerPHP/Faker/compare/v1.12.0..v1.12.1) This is a security release that prevents a hacker to execute code on the server. ## [2020-11-23, v1.12.0](https://github.com/FakerPHP/Faker/compare/v1.11.0..v1.12.0) - Fix ro_RO first and last day of year calculation offset (#65) - Fix en_NG locale test namespaces that did not match PSR-4 (#57) - Added Singapore NRIC/FIN provider (#56) - Added provider for Lithuanian municipalities (#58) - Added blood types provider (#61) ## [2020-11-15, v1.11.0](https://github.com/FakerPHP/Faker/compare/v1.10.1..v1.11.0) - Added Provider for Swedish Municipalities - Updates to person names in pt_BR - Many code style changes ## [2020-10-28, v1.10.1](https://github.com/FakerPHP/Faker/compare/v1.10.0..v1.10.1) - Updates the Danish addresses in dk_DK - Removed offense company names in nl_NL - Clarify changelog with original fork - Standin replacement for LoremPixel to Placeholder.com (#11) ## [2020-10-27, v1.10.0](https://github.com/FakerPHP/Faker/compare/v1.9.1..v1.10.0) - Support PHP 7.1-8.0 - Fix typo in de_DE Company Provider - Fix dateTimeThisYear method - Fix typo in de_DE jobTitleFormat - Fix IBAN generation for CR - Fix typos in greek first names - Fix US job title typo - Do not clear entity manager for doctrine orm populator - Remove persian rude words - Corrections to RU names ## 2020-10-27, v1.9.1 - Initial version. Same as `fzaninotto/Faker:v1.9.1`. src/ValidGenerator.php 0000644 00000004122 15025036220 0010744 0 ustar 00 <?php namespace Faker; use Faker\Extension\Extension; /** * Proxy for other generators, to return only valid values. Works with * Faker\Generator\Base->valid() * * @mixin Generator */ class ValidGenerator { protected $generator; protected $validator; protected $maxRetries; /** * @param Extension|Generator $generator * @param callable|null $validator * @param int $maxRetries */ public function __construct($generator, $validator = null, $maxRetries = 10000) { if (null === $validator) { $validator = static function () { return true; }; } elseif (!is_callable($validator)) { throw new \InvalidArgumentException('valid() only accepts callables as first argument'); } $this->generator = $generator; $this->validator = $validator; $this->maxRetries = $maxRetries; } public function ext(string $id) { return new self($this->generator->ext($id), $this->validator, $this->maxRetries); } /** * Catch and proxy all generator calls but return only valid values * * @param string $attribute * * @deprecated Use a method instead. */ public function __get($attribute) { trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute); return $this->__call($attribute, []); } /** * Catch and proxy all generator calls with arguments but return only valid values * * @param string $name * @param array $arguments */ public function __call($name, $arguments) { $i = 0; do { $res = call_user_func_array([$this->generator, $name], $arguments); ++$i; if ($i > $this->maxRetries) { throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a valid value', $this->maxRetries)); } } while (!call_user_func($this->validator, $res)); return $res; } } src/Calculator/Isbn.php 0000644 00000003012 15025036220 0011017 0 ustar 00 <?php namespace Faker\Calculator; /** * Utility class for validating ISBN-10 */ class Isbn { /** * @var string ISBN-10 validation pattern */ public const PATTERN = '/^\d{9}[\dX]$/'; /** * ISBN-10 check digit * * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-10_check_digits * * @param string $input ISBN without check-digit * * @throws \LengthException When wrong input length passed */ public static function checksum(string $input): string { // We're calculating check digit for ISBN-10 // so, the length of the input should be 9 $length = 9; if (strlen($input) !== $length) { throw new \LengthException(sprintf('Input length should be equal to %d', $length)); } $digits = str_split($input); array_walk( $digits, static function (&$digit, $position) { $digit = (10 - $position) * (int) $digit; } ); $result = (11 - array_sum($digits) % 11) % 11; // 10 is replaced by X return ($result < 10) ? (string) $result : 'X'; } /** * Checks whether the provided number is a valid ISBN-10 number * * @param string $isbn ISBN to check */ public static function isValid(string $isbn): bool { if (!preg_match(self::PATTERN, $isbn)) { return false; } return self::checksum(substr($isbn, 0, -1)) === substr($isbn, -1); } } src/Calculator/Luhn.php 0000644 00000002763 15025036220 0011046 0 ustar 00 <?php namespace Faker\Calculator; /** * Utility class for generating and validating Luhn numbers. * * Luhn algorithm is used to validate credit card numbers, IMEI numbers, and * National Provider Identifier numbers. * * @see http://en.wikipedia.org/wiki/Luhn_algorithm */ class Luhn { private static function checksum(string $number): int { $length = strlen($number); $sum = 0; for ($i = $length - 1; $i >= 0; $i -= 2) { $sum += (int) $number[$i]; } for ($i = $length - 2; $i >= 0; $i -= 2) { $sum += array_sum(str_split((string) ((int) $number[$i] * 2))); } return $sum % 10; } public static function computeCheckDigit(string $partialNumber): string { $checkDigit = self::checksum($partialNumber . '0'); if ($checkDigit === 0) { return '0'; } return (string) (10 - $checkDigit); } /** * Checks whether a number (partial number + check digit) is Luhn compliant */ public static function isValid(string $number): bool { return self::checksum($number) === 0; } /** * Generate a Luhn compliant number. */ public static function generateLuhnNumber(string $partialValue): string { if (!preg_match('/^\d+$/', $partialValue)) { throw new \InvalidArgumentException('Argument should be an integer.'); } return $partialValue . Luhn::computeCheckDigit($partialValue); } } src/Calculator/Iban.php 0000644 00000003031 15025036220 0010776 0 ustar 00 <?php namespace Faker\Calculator; class Iban { /** * Generates IBAN Checksum * * @return string Checksum (numeric string) */ public static function checksum(string $iban): string { // Move first four digits to end and set checksum to '00' $checkString = substr($iban, 4) . substr($iban, 0, 2) . '00'; // Replace all letters with their number equivalents $checkString = preg_replace_callback('/[A-Z]/', ['self', 'alphaToNumberCallback'], $checkString); // Perform mod 97 and subtract from 98 $checksum = 98 - self::mod97($checkString); return str_pad((string) $checksum, 2, '0', STR_PAD_LEFT); } private static function alphaToNumberCallback(array $match): int { return self::alphaToNumber($match[0]); } /** * Converts letter to number */ public static function alphaToNumber(string $char): int { return ord($char) - 55; } /** * Calculates mod97 on a numeric string * * @param string $number Numeric string */ public static function mod97(string $number): int { $checksum = (int) $number[0]; for ($i = 1, $size = strlen($number); $i < $size; ++$i) { $checksum = (10 * $checksum + (int) $number[$i]) % 97; } return $checksum; } /** * Checks whether an IBAN has a valid checksum */ public static function isValid(string $iban): bool { return self::checksum($iban) === substr($iban, 2, 2); } } src/Calculator/Ean.php 0000644 00000002200 15025036220 0010625 0 ustar 00 <?php namespace Faker\Calculator; /** * Utility class for validating EAN-8 and EAN-13 numbers */ class Ean { /** * @var string EAN validation pattern */ public const PATTERN = '/^(?:\d{8}|\d{13})$/'; /** * Computes the checksum of an EAN number. * * @see https://en.wikipedia.org/wiki/International_Article_Number * * @param string $digits * * @return int */ public static function checksum($digits) { $sequence = (strlen($digits) + 1) === 8 ? [3, 1] : [1, 3]; $sums = 0; foreach (str_split($digits) as $n => $digit) { $sums += ((int) $digit) * $sequence[$n % 2]; } return (10 - $sums % 10) % 10; } /** * Checks whether the provided number is an EAN compliant number and that * the checksum is correct. * * @param string $ean An EAN number * * @return bool */ public static function isValid($ean) { if (!preg_match(self::PATTERN, $ean)) { return false; } return self::checksum(substr($ean, 0, -1)) === (int) substr($ean, -1); } } src/Generator.php 0000644 00000026611 15025036220 0007773 0 ustar 00 <?php namespace Faker; use Faker\Container\ContainerInterface; use Faker\Extension\BarcodeExtension; use Faker\Extension\BloodExtension; use Faker\Extension\ColorExtension; use Faker\Extension\DateTimeExtension; use Faker\Extension\FileExtension; use Faker\Extension\NumberExtension; use Faker\Extension\UuidExtension; use Faker\Extension\VersionExtension; /** * @mixin BarcodeExtension * @mixin BloodExtension * @mixin ColorExtension * @mixin DateTimeExtension * @mixin FileExtension * @mixin NumberExtension * @mixin VersionExtension * @mixin UuidExtension */ class Generator { protected array $formatters = []; private ContainerInterface $container; private UniqueGenerator $uniqueGenerator; public function __construct(ContainerInterface $container = null) { $this->container = $container ?: Container\ContainerBuilder::getDefault(); } /** * @template T of Extension\Extension * * @param class-string<T> $id * * @throws Extension\ExtensionNotFound * * @return T */ public function ext(string $id) { if (!$this->container->has($id)) { throw new Extension\ExtensionNotFound(sprintf( 'No Faker extension with id "%s" was loaded.', $id )); } $extension = $this->container->get($id); if ($extension instanceof Extension\GeneratorAwareExtension) { $extension = $extension->withGenerator($this); } return $extension; } /** * With the unique generator you are guaranteed to never get the same two * values. * * <code> * // will never return twice the same value * $faker->unique()->randomElement(array(1, 2, 3)); * </code> * * @param bool $reset If set to true, resets the list of existing values * @param int $maxRetries Maximum number of retries to find a unique value, * After which an OverflowException is thrown. * * @throws \OverflowException When no unique value can be found by iterating $maxRetries times * * @return self A proxy class returning only non-existing values */ public function unique($reset = false, $maxRetries = 10000) { if ($reset || $this->uniqueGenerator === null) { $this->uniqueGenerator = new UniqueGenerator($this, $maxRetries); } return $this->uniqueGenerator; } /** * Get a value only some percentage of the time. * * @param float $weight A probability between 0 and 1, 0 means that we always get the default value. * * @return self */ public function optional(float $weight = 0.5, $default = null) { if ($weight > 1) { trigger_deprecation('fakerphp/faker', '1.16', 'First argument ($weight) to method "optional()" must be between 0 and 1. You passed %f, we assume you meant %f.', $weight, $weight / 100); $weight = $weight / 100; } return new ChanceGenerator($this, $weight, $default); } /** * To make sure the value meet some criteria, pass a callable that verifies the * output. If the validator fails, the generator will try again. * * The value validity is determined by a function passed as first argument. * * <code> * $values = array(); * $evenValidator = function ($digit) { * return $digit % 2 === 0; * }; * for ($i=0; $i < 10; $i++) { * $values []= $faker->valid($evenValidator)->randomDigit; * } * print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6] * </code> * * @param ?\Closure $validator A function returning true for valid values * @param int $maxRetries Maximum number of retries to find a valid value, * After which an OverflowException is thrown. * * @throws \OverflowException When no valid value can be found by iterating $maxRetries times * * @return self A proxy class returning only valid values */ public function valid(?\Closure $validator = null, int $maxRetries = 10000) { return new ValidGenerator($this, $validator, $maxRetries); } public function seed($seed = null) { if ($seed === null) { mt_srand(); } else { mt_srand((int) $seed, MT_RAND_PHP); } } public function format($format, $arguments = []) { return call_user_func_array($this->getFormatter($format), $arguments); } /** * @param string $format * * @return callable */ public function getFormatter($format) { if (isset($this->formatters[$format])) { return $this->formatters[$format]; } if (method_exists($this, $format)) { $this->formatters[$format] = [$this, $format]; return $this->formatters[$format]; } // "Faker\Core\Barcode->ean13" if (preg_match('|^([a-zA-Z0-9\\\]+)->([a-zA-Z0-9]+)$|', $format, $matches)) { $this->formatters[$format] = [$this->ext($matches[1]), $matches[2]]; return $this->formatters[$format]; } foreach ($this->providers as $provider) { if (method_exists($provider, $format)) { $this->formatters[$format] = [$provider, $format]; return $this->formatters[$format]; } } throw new \InvalidArgumentException(sprintf('Unknown format "%s"', $format)); } /** * Replaces tokens ('{{ tokenName }}') with the result from the token method call * * @param string $string String that needs to bet parsed * * @return string */ public function parse($string) { $callback = function ($matches) { return $this->format($matches[1]); }; return preg_replace_callback('/{{\s?(\w+|[\w\\\]+->\w+?)\s?}}/u', $callback, $string); } /** * Get a random MIME type * * @example 'video/avi' */ public function mimeType() { return $this->ext(Extension\FileExtension::class)->mimeType(); } /** * Get a random file extension (without a dot) * * @example avi */ public function fileExtension() { return $this->ext(Extension\FileExtension::class)->extension(); } /** * Get a full path to a new real file on the system. */ public function filePath() { return $this->ext(Extension\FileExtension::class)->filePath(); } /** * Get an actual blood type * * @example 'AB' */ public function bloodType(): string { return $this->ext(Extension\BloodExtension::class)->bloodType(); } /** * Get a random resis value * * @example '+' */ public function bloodRh(): string { return $this->ext(Extension\BloodExtension::class)->bloodRh(); } /** * Get a full blood group * * @example 'AB+' */ public function bloodGroup(): string { return $this->ext(Extension\BloodExtension::class)->bloodGroup(); } /** * Get a random EAN13 barcode. * * @example '4006381333931' */ public function ean13(): string { return $this->ext(Extension\BarcodeExtension::class)->ean13(); } /** * Get a random EAN8 barcode. * * @example '73513537' */ public function ean8(): string { return $this->ext(Extension\BarcodeExtension::class)->ean8(); } /** * Get a random ISBN-10 code * * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number * * @example '4881416324' */ public function isbn10(): string { return $this->ext(Extension\BarcodeExtension::class)->isbn10(); } /** * Get a random ISBN-13 code * * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number * * @example '9790404436093' */ public function isbn13(): string { return $this->ext(Extension\BarcodeExtension::class)->isbn13(); } /** * Returns a random number between $int1 and $int2 (any order) * * @example 79907610 */ public function numberBetween($int1 = 0, $int2 = 2147483647): int { return $this->ext(Extension\NumberExtension::class)->numberBetween((int) $int1, (int) $int2); } /** * Returns a random number between 0 and 9 */ public function randomDigit(): int { return $this->ext(Extension\NumberExtension::class)->randomDigit(); } /** * Generates a random digit, which cannot be $except */ public function randomDigitNot($except): int { return $this->ext(Extension\NumberExtension::class)->randomDigitNot((int) $except); } /** * Returns a random number between 1 and 9 */ public function randomDigitNotZero(): int { return $this->ext(Extension\NumberExtension::class)->randomDigitNotZero(); } /** * Return a random float number * * @example 48.8932 */ public function randomFloat($nbMaxDecimals = null, $min = 0, $max = null): float { return $this->ext(Extension\NumberExtension::class)->randomFloat( $nbMaxDecimals !== null ? (int) $nbMaxDecimals : null, (float) $min, $max !== null ? (float) $max : null ); } /** * Returns a random integer with 0 to $nbDigits digits. * * The maximum value returned is mt_getrandmax() * * @param int|null $nbDigits Defaults to a random number between 1 and 9 * @param bool $strict Whether the returned number should have exactly $nbDigits * * @example 79907610 */ public function randomNumber($nbDigits = null, $strict = false): int { return $this->ext(Extension\NumberExtension::class)->randomNumber( $nbDigits !== null ? (int) $nbDigits : null, (bool) $strict ); } /** * Get a version number in semantic versioning syntax 2.0.0. (https://semver.org/spec/v2.0.0.html) * * @param bool $preRelease Pre release parts may be randomly included * @param bool $build Build parts may be randomly included * * @example 1.0.0 * @example 1.0.0-alpha.1 * @example 1.0.0-alpha.1+b71f04d */ public function semver(bool $preRelease = false, bool $build = false): string { return $this->ext(Extension\VersionExtension::class)->semver($preRelease, $build); } /** * @deprecated */ protected function callFormatWithMatches($matches) { trigger_deprecation('fakerphp/faker', '1.14', 'Protected method "callFormatWithMatches()" is deprecated and will be removed.'); return $this->format($matches[1]); } /** * @param string $attribute * * @deprecated Use a method instead. */ public function __get($attribute) { trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute); return $this->format($attribute); } /** * @param string $method * @param array $attributes */ public function __call($method, $attributes) { return $this->format($method, $attributes); } public function __destruct() { $this->seed(); } public function __wakeup() { $this->formatters = []; } } src/Core/Color.php 0000644 00000012034 15025036220 0010005 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Extension; use Faker\Extension\Helper; /** * @experimental This class is experimental and does not fall under our BC promise */ final class Color implements Extension\ColorExtension { /** * @var string[] */ private $safeColorNames = [ 'black', 'maroon', 'green', 'navy', 'olive', 'purple', 'teal', 'lime', 'blue', 'silver', 'gray', 'yellow', 'fuchsia', 'aqua', 'white', ]; /** * @var string[] */ private $allColorNames = [ 'AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque', 'Black', 'BlanchedAlmond', 'Blue', 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue', 'Chartreuse', 'Chocolate', 'Coral', 'CornflowerBlue', 'Cornsilk', 'Crimson', 'Cyan', 'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGreen', 'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'Darkorange', 'DarkOrchid', 'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray', 'DarkTurquoise', 'DarkViolet', 'DeepPink', 'DeepSkyBlue', 'DimGray', 'DimGrey', 'DodgerBlue', 'FireBrick', 'FloralWhite', 'ForestGreen', 'Fuchsia', 'Gainsboro', 'GhostWhite', 'Gold', 'GoldenRod', 'Gray', 'Green', 'GreenYellow', 'HoneyDew', 'HotPink', 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender', 'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue', 'LightCoral', 'LightCyan', 'LightGoldenRodYellow', 'LightGray', 'LightGreen', 'LightPink', 'LightSalmon', 'LightSeaGreen', 'LightSkyBlue', 'LightSlateGray', 'LightSteelBlue', 'LightYellow', 'Lime', 'LimeGreen', 'Linen', 'Magenta', 'Maroon', 'MediumAquaMarine', 'MediumBlue', 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue', 'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed', 'MidnightBlue', 'MintCream', 'MistyRose', 'Moccasin', 'NavajoWhite', 'Navy', 'OldLace', 'Olive', 'OliveDrab', 'Orange', 'OrangeRed', 'Orchid', 'PaleGoldenRod', 'PaleGreen', 'PaleTurquoise', 'PaleVioletRed', 'PapayaWhip', 'PeachPuff', 'Peru', 'Pink', 'Plum', 'PowderBlue', 'Purple', 'Red', 'RosyBrown', 'RoyalBlue', 'SaddleBrown', 'Salmon', 'SandyBrown', 'SeaGreen', 'SeaShell', 'Sienna', 'Silver', 'SkyBlue', 'SlateBlue', 'SlateGray', 'Snow', 'SpringGreen', 'SteelBlue', 'Tan', 'Teal', 'Thistle', 'Tomato', 'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen', ]; /** * @example '#fa3cc2' */ public function hexColor(): string { $number = new Number(); return '#' . str_pad(dechex($number->numberBetween(1, 16777215)), 6, '0', STR_PAD_LEFT); } /** * @example '#ff0044' */ public function safeHexColor(): string { $number = new Number(); $color = str_pad(dechex($number->numberBetween(0, 255)), 3, '0', STR_PAD_LEFT); return sprintf( '#%s%s%s%s%s%s', $color[0], $color[0], $color[1], $color[1], $color[2], $color[2] ); } /** * @example 'array(0,255,122)' * * @return int[] */ public function rgbColorAsArray(): array { $color = $this->hexColor(); return [ hexdec(substr($color, 1, 2)), hexdec(substr($color, 3, 2)), hexdec(substr($color, 5, 2)), ]; } /** * @example '0,255,122' */ public function rgbColor(): string { return implode(',', $this->rgbColorAsArray()); } /** * @example 'rgb(0,255,122)' */ public function rgbCssColor(): string { return sprintf( 'rgb(%s)', $this->rgbColor() ); } /** * @example 'rgba(0,255,122,0.8)' */ public function rgbaCssColor(): string { $number = new Number(); return sprintf( 'rgba(%s,%s)', $this->rgbColor(), $number->randomFloat(1, 0, 1) ); } /** * @example 'blue' */ public function safeColorName(): string { return Helper::randomElement($this->safeColorNames); } /** * @example 'NavajoWhite' */ public function colorName(): string { return Helper::randomElement($this->allColorNames); } /** * @example '340,50,20' */ public function hslColor(): string { $number = new Number(); return sprintf( '%s,%s,%s', $number->numberBetween(0, 360), $number->numberBetween(0, 100), $number->numberBetween(0, 100) ); } /** * @example array(340, 50, 20) * * @return int[] */ public function hslColorAsArray(): array { $number = new Number(); return [ $number->numberBetween(0, 360), $number->numberBetween(0, 100), $number->numberBetween(0, 100), ]; } } src/Core/Number.php 0000644 00000003543 15025036220 0010164 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Extension; /** * @experimental This class is experimental and does not fall under our BC promise */ final class Number implements Extension\NumberExtension { public function numberBetween(int $min = 0, int $max = 2147483647): int { $int1 = min($min, $max); $int2 = max($min, $max); return mt_rand($int1, $int2); } public function randomDigit(): int { return mt_rand(0, 9); } public function randomDigitNot(int $except): int { $result = self::numberBetween(0, 8); if ($result >= $except) { ++$result; } return $result; } public function randomDigitNotZero(): int { return mt_rand(1, 9); } public function randomFloat(?int $nbMaxDecimals = null, float $min = 0, ?float $max = null): float { if (null === $nbMaxDecimals) { $nbMaxDecimals = $this->randomDigit(); } if (null === $max) { $max = $this->randomNumber(); if ($min > $max) { $max = $min; } } if ($min > $max) { $tmp = $min; $min = $max; $max = $tmp; } return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $nbMaxDecimals); } public function randomNumber(int $nbDigits = null, bool $strict = false): int { if (null === $nbDigits) { $nbDigits = $this->randomDigitNotZero(); } $max = 10 ** $nbDigits - 1; if ($max > mt_getrandmax()) { throw new \InvalidArgumentException('randomNumber() can only generate numbers up to mt_getrandmax()'); } if ($strict) { return mt_rand(10 ** ($nbDigits - 1), $max); } return mt_rand(0, $max); } } src/Core/Barcode.php 0000644 00000001771 15025036220 0010274 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Calculator; use Faker\Extension; /** * @experimental This class is experimental and does not fall under our BC promise */ final class Barcode implements Extension\BarcodeExtension { private function ean(int $length = 13): string { $code = Extension\Helper::numerify(str_repeat('#', $length - 1)); return sprintf('%s%s', $code, Calculator\Ean::checksum($code)); } public function ean13(): string { return $this->ean(); } public function ean8(): string { return $this->ean(8); } public function isbn10(): string { $code = Extension\Helper::numerify(str_repeat('#', 9)); return sprintf('%s%s', $code, Calculator\Isbn::checksum($code)); } public function isbn13(): string { $code = '97' . mt_rand(8, 9) . Extension\Helper::numerify(str_repeat('#', 9)); return sprintf('%s%s', $code, Calculator\Ean::checksum($code)); } } src/Core/Coordinates.php 0000644 00000003437 15025036220 0011210 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Extension\Extension; class Coordinates implements Extension { /** * @example '77.147489' * * @return float Uses signed degrees format (returns a float number between -90 and 90) */ public function latitude(float $min = -90.0, float $max = 90.0): float { if ($min < -90 || $max < -90) { throw new \LogicException('Latitude cannot be less that -90.0'); } if ($min > 90 || $max > 90) { throw new \LogicException('Latitude cannot be greater that 90.0'); } return $this->randomFloat(6, $min, $max); } /** * @example '86.211205' * * @return float Uses signed degrees format (returns a float number between -180 and 180) */ public function longitude(float $min = -180.0, float $max = 180.0): float { if ($min < -180 || $max < -180) { throw new \LogicException('Longitude cannot be less that -180.0'); } if ($min > 180 || $max > 180) { throw new \LogicException('Longitude cannot be greater that 180.0'); } return $this->randomFloat(6, $min, $max); } /** * @example array('77.147489', '86.211205') * * @return array{latitude: float, longitude: float} */ public function localCoordinates(): array { return [ 'latitude' => static::latitude(), 'longitude' => static::longitude(), ]; } private function randomFloat(int $nbMaxDecimals, float $min, float $max): float { if ($min > $max) { throw new \LogicException('Invalid coordinates boundaries'); } return round($min + mt_rand() / mt_getrandmax() * ($max - $min), $nbMaxDecimals); } } src/Core/DateTime.php 0000644 00000014200 15025036220 0010420 0 ustar 00 <?php namespace Faker\Core; use Faker\Extension\DateTimeExtension; use Faker\Extension\GeneratorAwareExtension; use Faker\Extension\GeneratorAwareExtensionTrait; use Faker\Extension\Helper; /** * @experimental * * @since 1.20.0 */ final class DateTime implements DateTimeExtension, GeneratorAwareExtension { use GeneratorAwareExtensionTrait; /** * @var string[] */ private $centuries = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII', 'XIX', 'XX', 'XXI']; /** * @var string */ private $defaultTimezone = null; /** * Get the POSIX-timestamp of a DateTime, int or string. * * @param \DateTime|float|int|string $until * * @return false|int */ protected function getTimestamp($until = 'now') { if (is_numeric($until)) { return (int) $until; } if ($until instanceof \DateTime) { return $until->getTimestamp(); } return strtotime(empty($until) ? 'now' : $until); } /** * Get a DateTime created based on a POSIX-timestamp. * * @param int $timestamp the UNIX / POSIX-compatible timestamp */ protected function getTimestampDateTime(int $timestamp): \DateTime { return new \DateTime('@' . $timestamp); } protected function setDefaultTimezone(string $timezone = null): void { $this->defaultTimezone = $timezone; } protected function getDefaultTimezone(): ?string { return $this->defaultTimezone; } protected function resolveTimezone(?string $timezone): string { if ($timezone !== null) { return $timezone; } return null === $this->defaultTimezone ? date_default_timezone_get() : $this->defaultTimezone; } /** * Internal method to set the timezone on a DateTime object. */ protected function setTimezone(\DateTime $dateTime, ?string $timezone): \DateTime { $timezone = $this->resolveTimezone($timezone); return $dateTime->setTimezone(new \DateTimeZone($timezone)); } public function dateTime($until = 'now', string $timezone = null): \DateTime { return $this->setTimezone( $this->getTimestampDateTime($this->unixTime($until)), $timezone ); } public function dateTimeAD($until = 'now', string $timezone = null): \DateTime { $min = (PHP_INT_SIZE > 4) ? -62135597361 : -PHP_INT_MAX; return $this->setTimezone( $this->getTimestampDateTime($this->generator->numberBetween($min, $this->getTimestamp($until))), $timezone ); } public function dateTimeBetween($from = '-30 years', $until = 'now', string $timezone = null): \DateTime { $start = $this->getTimestamp($from); $end = $this->getTimestamp($until); if ($start > $end) { throw new \InvalidArgumentException('"$from" must be anterior to "$until".'); } $timestamp = $this->generator->numberBetween($start, $end); return $this->setTimezone( $this->getTimestampDateTime($timestamp), $timezone ); } public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', string $timezone = null): \DateTime { $intervalObject = \DateInterval::createFromDateString($interval); $datetime = $from instanceof \DateTime ? $from : new \DateTime($from); $other = (clone $datetime)->add($intervalObject); $begin = min($datetime, $other); $end = $datetime === $begin ? $other : $datetime; return $this->dateTimeBetween($begin, $end, $timezone); } public function dateTimeThisWeek($until = 'sunday this week', string $timezone = null): \DateTime { return $this->dateTimeBetween('monday this week', $until, $timezone); } public function dateTimeThisMonth($until = 'last day of this month', string $timezone = null): \DateTime { return $this->dateTimeBetween('first day of this month', $until, $timezone); } public function dateTimeThisYear($until = 'last day of december', string $timezone = null): \DateTime { return $this->dateTimeBetween('first day of january', $until, $timezone); } public function dateTimeThisDecade($until = 'now', string $timezone = null): \DateTime { $year = floor(date('Y') / 10) * 10; return $this->dateTimeBetween("first day of january $year", $until, $timezone); } public function dateTimeThisCentury($until = 'now', string $timezone = null): \DateTime { $year = floor(date('Y') / 100) * 100; return $this->dateTimeBetween("first day of january $year", $until, $timezone); } public function date(string $format = 'Y-m-d', $until = 'now'): string { return $this->dateTime($until)->format($format); } public function time(string $format = 'H:i:s', $until = 'now'): string { return $this->date($format, $until); } public function unixTime($until = 'now'): int { return $this->generator->numberBetween(0, $this->getTimestamp($until)); } public function iso8601($until = 'now'): string { return $this->date(\DateTime::ISO8601, $until); } public function amPm($until = 'now'): string { return $this->date('a', $until); } public function dayOfMonth($until = 'now'): string { return $this->date('d', $until); } public function dayOfWeek($until = 'now'): string { return $this->date('l', $until); } public function month($until = 'now'): string { return $this->date('m', $until); } public function monthName($until = 'now'): string { return $this->date('F', $until); } public function year($until = 'now'): string { return $this->date('Y', $until); } public function century(): string { return Helper::randomElement($this->centuries); } public function timezone(): string { return Helper::randomElement(\DateTimeZone::listIdentifiers()); } } src/Core/Version.php 0000644 00000003310 15025036220 0010351 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Extension\GeneratorAwareExtension; use Faker\Extension\GeneratorAwareExtensionTrait; use Faker\Extension\Helper; use Faker\Extension\VersionExtension; final class Version implements VersionExtension, GeneratorAwareExtension { use GeneratorAwareExtensionTrait; /** * @var string[] */ private array $semverCommonPreReleaseIdentifiers = ['alpha', 'beta', 'rc']; /** * Represents v2.0.0 of the semantic versioning: https://semver.org/spec/v2.0.0.html */ public function semver(bool $preRelease = false, bool $build = false): string { return sprintf( '%d.%d.%d%s%s', mt_rand(0, 9), mt_rand(0, 99), mt_rand(0, 99), $preRelease && mt_rand(0, 1) ? '-' . $this->semverPreReleaseIdentifier() : '', $build && mt_rand(0, 1) ? '+' . $this->semverBuildIdentifier() : '' ); } /** * Common pre-release identifier */ private function semverPreReleaseIdentifier(): string { $ident = Helper::randomElement($this->semverCommonPreReleaseIdentifiers); if (!mt_rand(0, 1)) { return $ident; } return $ident . '.' . mt_rand(1, 99); } /** * Common random build identifier */ private function semverBuildIdentifier(): string { if (mt_rand(0, 1)) { // short git revision syntax: https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection return substr(sha1(Helper::lexify('??????')), 0, 7); } // date syntax return $this->generator->ext(\Faker\Extension\DateTimeExtension::class)->date('YmdHis'); } } src/Core/File.php 0000644 00000056227 15025036220 0007622 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Extension; /** * @experimental This class is experimental and does not fall under our BC promise */ final class File implements Extension\FileExtension { /** * MIME types from the apache.org file. Some types are truncated. * * @var array Map of MIME types => file extension(s) * * @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types */ private $mimeTypes = [ 'application/atom+xml' => 'atom', 'application/ecmascript' => 'ecma', 'application/emma+xml' => 'emma', 'application/epub+zip' => 'epub', 'application/java-archive' => 'jar', 'application/java-vm' => 'class', 'application/javascript' => 'js', 'application/json' => 'json', 'application/jsonml+json' => 'jsonml', 'application/lost+xml' => 'lostxml', 'application/mathml+xml' => 'mathml', 'application/mets+xml' => 'mets', 'application/mods+xml' => 'mods', 'application/mp4' => 'mp4s', 'application/msword' => ['doc', 'dot'], 'application/octet-stream' => [ 'bin', 'dms', 'lrf', 'mar', 'so', 'dist', 'distz', 'pkg', 'bpk', 'dump', 'elc', 'deploy', ], 'application/ogg' => 'ogx', 'application/omdoc+xml' => 'omdoc', 'application/pdf' => 'pdf', 'application/pgp-encrypted' => 'pgp', 'application/pgp-signature' => ['asc', 'sig'], 'application/pkix-pkipath' => 'pkipath', 'application/pkixcmp' => 'pki', 'application/pls+xml' => 'pls', 'application/postscript' => ['ai', 'eps', 'ps'], 'application/pskc+xml' => 'pskcxml', 'application/rdf+xml' => 'rdf', 'application/reginfo+xml' => 'rif', 'application/rss+xml' => 'rss', 'application/rtf' => 'rtf', 'application/sbml+xml' => 'sbml', 'application/vnd.adobe.air-application-installer-package+zip' => 'air', 'application/vnd.adobe.xdp+xml' => 'xdp', 'application/vnd.adobe.xfdf' => 'xfdf', 'application/vnd.ahead.space' => 'ahead', 'application/vnd.dart' => 'dart', 'application/vnd.data-vision.rdz' => 'rdz', 'application/vnd.dece.data' => ['uvf', 'uvvf', 'uvd', 'uvvd'], 'application/vnd.dece.ttml+xml' => ['uvt', 'uvvt'], 'application/vnd.dece.unspecified' => ['uvx', 'uvvx'], 'application/vnd.dece.zip' => ['uvz', 'uvvz'], 'application/vnd.denovo.fcselayout-link' => 'fe_launch', 'application/vnd.dna' => 'dna', 'application/vnd.dolby.mlp' => 'mlp', 'application/vnd.dpgraph' => 'dpg', 'application/vnd.dreamfactory' => 'dfac', 'application/vnd.ds-keypoint' => 'kpxx', 'application/vnd.dvb.ait' => 'ait', 'application/vnd.dvb.service' => 'svc', 'application/vnd.dynageo' => 'geo', 'application/vnd.ecowin.chart' => 'mag', 'application/vnd.enliven' => 'nml', 'application/vnd.epson.esf' => 'esf', 'application/vnd.epson.msf' => 'msf', 'application/vnd.epson.quickanime' => 'qam', 'application/vnd.epson.salt' => 'slt', 'application/vnd.epson.ssf' => 'ssf', 'application/vnd.ezpix-album' => 'ez2', 'application/vnd.ezpix-package' => 'ez3', 'application/vnd.fdf' => 'fdf', 'application/vnd.fdsn.mseed' => 'mseed', 'application/vnd.fdsn.seed' => ['seed', 'dataless'], 'application/vnd.flographit' => 'gph', 'application/vnd.fluxtime.clip' => 'ftc', 'application/vnd.hal+xml' => 'hal', 'application/vnd.hydrostatix.sof-data' => 'sfd-hdstx', 'application/vnd.ibm.minipay' => 'mpy', 'application/vnd.ibm.secure-container' => 'sc', 'application/vnd.iccprofile' => ['icc', 'icm'], 'application/vnd.igloader' => 'igl', 'application/vnd.immervision-ivp' => 'ivp', 'application/vnd.kde.karbon' => 'karbon', 'application/vnd.kde.kchart' => 'chrt', 'application/vnd.kde.kformula' => 'kfo', 'application/vnd.kde.kivio' => 'flw', 'application/vnd.kde.kontour' => 'kon', 'application/vnd.kde.kpresenter' => ['kpr', 'kpt'], 'application/vnd.kde.kspread' => 'ksp', 'application/vnd.kde.kword' => ['kwd', 'kwt'], 'application/vnd.kenameaapp' => 'htke', 'application/vnd.kidspiration' => 'kia', 'application/vnd.kinar' => ['kne', 'knp'], 'application/vnd.koan' => ['skp', 'skd', 'skt', 'skm'], 'application/vnd.kodak-descriptor' => 'sse', 'application/vnd.las.las+xml' => 'lasxml', 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd', 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe', 'application/vnd.lotus-1-2-3' => '123', 'application/vnd.lotus-approach' => 'apr', 'application/vnd.lotus-freelance' => 'pre', 'application/vnd.lotus-notes' => 'nsf', 'application/vnd.lotus-organizer' => 'org', 'application/vnd.lotus-screencam' => 'scm', 'application/vnd.mozilla.xul+xml' => 'xul', 'application/vnd.ms-artgalry' => 'cil', 'application/vnd.ms-cab-compressed' => 'cab', 'application/vnd.ms-excel' => [ 'xls', 'xlm', 'xla', 'xlc', 'xlt', 'xlw', ], 'application/vnd.ms-excel.addin.macroenabled.12' => 'xlam', 'application/vnd.ms-excel.sheet.binary.macroenabled.12' => 'xlsb', 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm', 'application/vnd.ms-excel.template.macroenabled.12' => 'xltm', 'application/vnd.ms-fontobject' => 'eot', 'application/vnd.ms-htmlhelp' => 'chm', 'application/vnd.ms-ims' => 'ims', 'application/vnd.ms-lrm' => 'lrm', 'application/vnd.ms-officetheme' => 'thmx', 'application/vnd.ms-pki.seccat' => 'cat', 'application/vnd.ms-pki.stl' => 'stl', 'application/vnd.ms-powerpoint' => ['ppt', 'pps', 'pot'], 'application/vnd.ms-powerpoint.addin.macroenabled.12' => 'ppam', 'application/vnd.ms-powerpoint.presentation.macroenabled.12' => 'pptm', 'application/vnd.ms-powerpoint.slide.macroenabled.12' => 'sldm', 'application/vnd.ms-powerpoint.slideshow.macroenabled.12' => 'ppsm', 'application/vnd.ms-powerpoint.template.macroenabled.12' => 'potm', 'application/vnd.ms-project' => ['mpp', 'mpt'], 'application/vnd.ms-word.document.macroenabled.12' => 'docm', 'application/vnd.ms-word.template.macroenabled.12' => 'dotm', 'application/vnd.ms-works' => ['wps', 'wks', 'wcm', 'wdb'], 'application/vnd.ms-wpl' => 'wpl', 'application/vnd.ms-xpsdocument' => 'xps', 'application/vnd.mseq' => 'mseq', 'application/vnd.musician' => 'mus', 'application/vnd.oasis.opendocument.chart' => 'odc', 'application/vnd.oasis.opendocument.chart-template' => 'otc', 'application/vnd.oasis.opendocument.database' => 'odb', 'application/vnd.oasis.opendocument.formula' => 'odf', 'application/vnd.oasis.opendocument.formula-template' => 'odft', 'application/vnd.oasis.opendocument.graphics' => 'odg', 'application/vnd.oasis.opendocument.graphics-template' => 'otg', 'application/vnd.oasis.opendocument.image' => 'odi', 'application/vnd.oasis.opendocument.image-template' => 'oti', 'application/vnd.oasis.opendocument.presentation' => 'odp', 'application/vnd.oasis.opendocument.presentation-template' => 'otp', 'application/vnd.oasis.opendocument.spreadsheet' => 'ods', 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots', 'application/vnd.oasis.opendocument.text' => 'odt', 'application/vnd.oasis.opendocument.text-master' => 'odm', 'application/vnd.oasis.opendocument.text-template' => 'ott', 'application/vnd.oasis.opendocument.text-web' => 'oth', 'application/vnd.olpc-sugar' => 'xo', 'application/vnd.oma.dd2+xml' => 'dd2', 'application/vnd.openofficeorg.extension' => 'oxt', 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx', 'application/vnd.openxmlformats-officedocument.presentationml.slide' => 'sldx', 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'ppsx', 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'potx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'xltx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx', 'application/vnd.pvi.ptid1' => 'ptid', 'application/vnd.quark.quarkxpress' => [ 'qxd', 'qxt', 'qwd', 'qwt', 'qxl', 'qxb', ], 'application/vnd.realvnc.bed' => 'bed', 'application/vnd.recordare.musicxml' => 'mxl', 'application/vnd.recordare.musicxml+xml' => 'musicxml', 'application/vnd.rig.cryptonote' => 'cryptonote', 'application/vnd.rim.cod' => 'cod', 'application/vnd.rn-realmedia' => 'rm', 'application/vnd.rn-realmedia-vbr' => 'rmvb', 'application/vnd.route66.link66+xml' => 'link66', 'application/vnd.sailingtracker.track' => 'st', 'application/vnd.seemail' => 'see', 'application/vnd.sema' => 'sema', 'application/vnd.semd' => 'semd', 'application/vnd.semf' => 'semf', 'application/vnd.shana.informed.formdata' => 'ifm', 'application/vnd.shana.informed.formtemplate' => 'itp', 'application/vnd.shana.informed.interchange' => 'iif', 'application/vnd.shana.informed.package' => 'ipk', 'application/vnd.simtech-mindmapper' => ['twd', 'twds'], 'application/vnd.smaf' => 'mmf', 'application/vnd.stepmania.stepchart' => 'sm', 'application/vnd.sun.xml.calc' => 'sxc', 'application/vnd.sun.xml.calc.template' => 'stc', 'application/vnd.sun.xml.draw' => 'sxd', 'application/vnd.sun.xml.draw.template' => 'std', 'application/vnd.sun.xml.impress' => 'sxi', 'application/vnd.sun.xml.impress.template' => 'sti', 'application/vnd.sun.xml.math' => 'sxm', 'application/vnd.sun.xml.writer' => 'sxw', 'application/vnd.sun.xml.writer.global' => 'sxg', 'application/vnd.sun.xml.writer.template' => 'stw', 'application/vnd.sus-calendar' => ['sus', 'susp'], 'application/vnd.svd' => 'svd', 'application/vnd.symbian.install' => ['sis', 'sisx'], 'application/vnd.syncml+xml' => 'xsm', 'application/vnd.syncml.dm+wbxml' => 'bdm', 'application/vnd.syncml.dm+xml' => 'xdm', 'application/vnd.tao.intent-module-archive' => 'tao', 'application/vnd.tcpdump.pcap' => ['pcap', 'cap', 'dmp'], 'application/vnd.tmobile-livetv' => 'tmo', 'application/vnd.trid.tpt' => 'tpt', 'application/vnd.triscape.mxs' => 'mxs', 'application/vnd.trueapp' => 'tra', 'application/vnd.ufdl' => ['ufd', 'ufdl'], 'application/vnd.uiq.theme' => 'utz', 'application/vnd.umajin' => 'umj', 'application/vnd.unity' => 'unityweb', 'application/vnd.uoml+xml' => 'uoml', 'application/vnd.vcx' => 'vcx', 'application/vnd.visio' => ['vsd', 'vst', 'vss', 'vsw'], 'application/vnd.visionary' => 'vis', 'application/vnd.vsf' => 'vsf', 'application/vnd.wap.wbxml' => 'wbxml', 'application/vnd.wap.wmlc' => 'wmlc', 'application/vnd.wap.wmlscriptc' => 'wmlsc', 'application/vnd.webturbo' => 'wtb', 'application/vnd.wolfram.player' => 'nbp', 'application/vnd.wordperfect' => 'wpd', 'application/vnd.wqd' => 'wqd', 'application/vnd.wt.stf' => 'stf', 'application/vnd.xara' => 'xar', 'application/vnd.xfdl' => 'xfdl', 'application/voicexml+xml' => 'vxml', 'application/widget' => 'wgt', 'application/winhlp' => 'hlp', 'application/wsdl+xml' => 'wsdl', 'application/wspolicy+xml' => 'wspolicy', 'application/x-7z-compressed' => '7z', 'application/x-bittorrent' => 'torrent', 'application/x-blorb' => ['blb', 'blorb'], 'application/x-bzip' => 'bz', 'application/x-cdlink' => 'vcd', 'application/x-cfs-compressed' => 'cfs', 'application/x-chat' => 'chat', 'application/x-chess-pgn' => 'pgn', 'application/x-conference' => 'nsc', 'application/x-cpio' => 'cpio', 'application/x-csh' => 'csh', 'application/x-debian-package' => ['deb', 'udeb'], 'application/x-dgc-compressed' => 'dgc', 'application/x-director' => [ 'dir', 'dcr', 'dxr', 'cst', 'cct', 'cxt', 'w3d', 'fgd', 'swa', ], 'application/x-font-ttf' => ['ttf', 'ttc'], 'application/x-font-type1' => ['pfa', 'pfb', 'pfm', 'afm'], 'application/x-font-woff' => 'woff', 'application/x-freearc' => 'arc', 'application/x-futuresplash' => 'spl', 'application/x-gca-compressed' => 'gca', 'application/x-glulx' => 'ulx', 'application/x-gnumeric' => 'gnumeric', 'application/x-gramps-xml' => 'gramps', 'application/x-gtar' => 'gtar', 'application/x-hdf' => 'hdf', 'application/x-install-instructions' => 'install', 'application/x-iso9660-image' => 'iso', 'application/x-java-jnlp-file' => 'jnlp', 'application/x-latex' => 'latex', 'application/x-lzh-compressed' => ['lzh', 'lha'], 'application/x-mie' => 'mie', 'application/x-mobipocket-ebook' => ['prc', 'mobi'], 'application/x-ms-application' => 'application', 'application/x-ms-shortcut' => 'lnk', 'application/x-ms-wmd' => 'wmd', 'application/x-ms-wmz' => 'wmz', 'application/x-ms-xbap' => 'xbap', 'application/x-msaccess' => 'mdb', 'application/x-msbinder' => 'obd', 'application/x-mscardfile' => 'crd', 'application/x-msclip' => 'clp', 'application/x-msdownload' => ['exe', 'dll', 'com', 'bat', 'msi'], 'application/x-msmediaview' => [ 'mvb', 'm13', 'm14', ], 'application/x-msmetafile' => ['wmf', 'wmz', 'emf', 'emz'], 'application/x-rar-compressed' => 'rar', 'application/x-research-info-systems' => 'ris', 'application/x-sh' => 'sh', 'application/x-shar' => 'shar', 'application/x-shockwave-flash' => 'swf', 'application/x-silverlight-app' => 'xap', 'application/x-sql' => 'sql', 'application/x-stuffit' => 'sit', 'application/x-stuffitx' => 'sitx', 'application/x-subrip' => 'srt', 'application/x-sv4cpio' => 'sv4cpio', 'application/x-sv4crc' => 'sv4crc', 'application/x-t3vm-image' => 't3', 'application/x-tads' => 'gam', 'application/x-tar' => 'tar', 'application/x-tcl' => 'tcl', 'application/x-tex' => 'tex', 'application/x-tex-tfm' => 'tfm', 'application/x-texinfo' => ['texinfo', 'texi'], 'application/x-tgif' => 'obj', 'application/x-ustar' => 'ustar', 'application/x-wais-source' => 'src', 'application/x-x509-ca-cert' => ['der', 'crt'], 'application/x-xfig' => 'fig', 'application/x-xliff+xml' => 'xlf', 'application/x-xpinstall' => 'xpi', 'application/x-xz' => 'xz', 'application/x-zmachine' => 'z1', 'application/xaml+xml' => 'xaml', 'application/xcap-diff+xml' => 'xdf', 'application/xenc+xml' => 'xenc', 'application/xhtml+xml' => ['xhtml', 'xht'], 'application/xml' => ['xml', 'xsl'], 'application/xml-dtd' => 'dtd', 'application/xop+xml' => 'xop', 'application/xproc+xml' => 'xpl', 'application/xslt+xml' => 'xslt', 'application/xspf+xml' => 'xspf', 'application/xv+xml' => ['mxml', 'xhvml', 'xvml', 'xvm'], 'application/yang' => 'yang', 'application/yin+xml' => 'yin', 'application/zip' => 'zip', 'audio/adpcm' => 'adp', 'audio/basic' => ['au', 'snd'], 'audio/midi' => ['mid', 'midi', 'kar', 'rmi'], 'audio/mp4' => 'mp4a', 'audio/mpeg' => [ 'mpga', 'mp2', 'mp2a', 'mp3', 'm2a', 'm3a', ], 'audio/ogg' => ['oga', 'ogg', 'spx'], 'audio/vnd.dece.audio' => ['uva', 'uvva'], 'audio/vnd.rip' => 'rip', 'audio/webm' => 'weba', 'audio/x-aac' => 'aac', 'audio/x-aiff' => ['aif', 'aiff', 'aifc'], 'audio/x-caf' => 'caf', 'audio/x-flac' => 'flac', 'audio/x-matroska' => 'mka', 'audio/x-mpegurl' => 'm3u', 'audio/x-ms-wax' => 'wax', 'audio/x-ms-wma' => 'wma', 'audio/x-pn-realaudio' => ['ram', 'ra'], 'audio/x-pn-realaudio-plugin' => 'rmp', 'audio/x-wav' => 'wav', 'audio/xm' => 'xm', 'image/bmp' => 'bmp', 'image/cgm' => 'cgm', 'image/g3fax' => 'g3', 'image/gif' => 'gif', 'image/ief' => 'ief', 'image/jpeg' => ['jpeg', 'jpg', 'jpe'], 'image/ktx' => 'ktx', 'image/png' => 'png', 'image/prs.btif' => 'btif', 'image/sgi' => 'sgi', 'image/svg+xml' => ['svg', 'svgz'], 'image/tiff' => ['tiff', 'tif'], 'image/vnd.adobe.photoshop' => 'psd', 'image/vnd.dece.graphic' => ['uvi', 'uvvi', 'uvg', 'uvvg'], 'image/vnd.dvb.subtitle' => 'sub', 'image/vnd.djvu' => ['djvu', 'djv'], 'image/vnd.dwg' => 'dwg', 'image/vnd.dxf' => 'dxf', 'image/vnd.fastbidsheet' => 'fbs', 'image/vnd.fpx' => 'fpx', 'image/vnd.fst' => 'fst', 'image/vnd.fujixerox.edmics-mmr' => 'mmr', 'image/vnd.fujixerox.edmics-rlc' => 'rlc', 'image/vnd.ms-modi' => 'mdi', 'image/vnd.ms-photo' => 'wdp', 'image/vnd.net-fpx' => 'npx', 'image/vnd.wap.wbmp' => 'wbmp', 'image/vnd.xiff' => 'xif', 'image/webp' => 'webp', 'image/x-3ds' => '3ds', 'image/x-cmu-raster' => 'ras', 'image/x-cmx' => 'cmx', 'image/x-freehand' => ['fh', 'fhc', 'fh4', 'fh5', 'fh7'], 'image/x-icon' => 'ico', 'image/x-mrsid-image' => 'sid', 'image/x-pcx' => 'pcx', 'image/x-pict' => ['pic', 'pct'], 'image/x-portable-anymap' => 'pnm', 'image/x-portable-bitmap' => 'pbm', 'image/x-portable-graymap' => 'pgm', 'image/x-portable-pixmap' => 'ppm', 'image/x-rgb' => 'rgb', 'image/x-tga' => 'tga', 'image/x-xbitmap' => 'xbm', 'image/x-xpixmap' => 'xpm', 'image/x-xwindowdump' => 'xwd', 'message/rfc822' => ['eml', 'mime'], 'model/iges' => ['igs', 'iges'], 'model/mesh' => ['msh', 'mesh', 'silo'], 'model/vnd.collada+xml' => 'dae', 'model/vnd.dwf' => 'dwf', 'model/vnd.gdl' => 'gdl', 'model/vnd.gtw' => 'gtw', 'model/vnd.mts' => 'mts', 'model/vnd.vtu' => 'vtu', 'model/vrml' => ['wrl', 'vrml'], 'model/x3d+binary' => 'x3db', 'model/x3d+vrml' => 'x3dv', 'model/x3d+xml' => 'x3d', 'text/cache-manifest' => 'appcache', 'text/calendar' => ['ics', 'ifb'], 'text/css' => 'css', 'text/csv' => 'csv', 'text/html' => ['html', 'htm'], 'text/n3' => 'n3', 'text/plain' => [ 'txt', 'text', 'conf', 'def', 'list', 'log', 'in', ], 'text/prs.lines.tag' => 'dsc', 'text/richtext' => 'rtx', 'text/sgml' => ['sgml', 'sgm'], 'text/tab-separated-values' => 'tsv', 'text/troff' => [ 't', 'tr', 'roff', 'man', 'me', 'ms', ], 'text/turtle' => 'ttl', 'text/uri-list' => ['uri', 'uris', 'urls'], 'text/vcard' => 'vcard', 'text/vnd.curl' => 'curl', 'text/vnd.curl.dcurl' => 'dcurl', 'text/vnd.curl.scurl' => 'scurl', 'text/vnd.curl.mcurl' => 'mcurl', 'text/vnd.dvb.subtitle' => 'sub', 'text/vnd.fly' => 'fly', 'text/vnd.fmi.flexstor' => 'flx', 'text/vnd.graphviz' => 'gv', 'text/vnd.in3d.3dml' => '3dml', 'text/vnd.in3d.spot' => 'spot', 'text/vnd.sun.j2me.app-descriptor' => 'jad', 'text/vnd.wap.wml' => 'wml', 'text/vnd.wap.wmlscript' => 'wmls', 'text/x-asm' => ['s', 'asm'], 'text/x-fortran' => ['f', 'for', 'f77', 'f90'], 'text/x-java-source' => 'java', 'text/x-opml' => 'opml', 'text/x-pascal' => ['p', 'pas'], 'text/x-nfo' => 'nfo', 'text/x-setext' => 'etx', 'text/x-sfv' => 'sfv', 'text/x-uuencode' => 'uu', 'text/x-vcalendar' => 'vcs', 'text/x-vcard' => 'vcf', 'video/3gpp' => '3gp', 'video/3gpp2' => '3g2', 'video/h261' => 'h261', 'video/h263' => 'h263', 'video/h264' => 'h264', 'video/jpeg' => 'jpgv', 'video/jpm' => ['jpm', 'jpgm'], 'video/mj2' => 'mj2', 'video/mp4' => 'mp4', 'video/mpeg' => ['mpeg', 'mpg', 'mpe', 'm1v', 'm2v'], 'video/ogg' => 'ogv', 'video/quicktime' => ['qt', 'mov'], 'video/vnd.dece.hd' => ['uvh', 'uvvh'], 'video/vnd.dece.mobile' => ['uvm', 'uvvm'], 'video/vnd.dece.pd' => ['uvp', 'uvvp'], 'video/vnd.dece.sd' => ['uvs', 'uvvs'], 'video/vnd.dece.video' => ['uvv', 'uvvv'], 'video/vnd.dvb.file' => 'dvb', 'video/vnd.fvt' => 'fvt', 'video/vnd.mpegurl' => ['mxu', 'm4u'], 'video/vnd.ms-playready.media.pyv' => 'pyv', 'video/vnd.uvvu.mp4' => ['uvu', 'uvvu'], 'video/vnd.vivo' => 'viv', 'video/webm' => 'webm', 'video/x-f4v' => 'f4v', 'video/x-fli' => 'fli', 'video/x-flv' => 'flv', 'video/x-m4v' => 'm4v', 'video/x-matroska' => ['mkv', 'mk3d', 'mks'], 'video/x-mng' => 'mng', 'video/x-ms-asf' => ['asf', 'asx'], 'video/x-ms-vob' => 'vob', 'video/x-ms-wm' => 'wm', 'video/x-ms-wmv' => 'wmv', 'video/x-ms-wmx' => 'wmx', 'video/x-ms-wvx' => 'wvx', 'video/x-msvideo' => 'avi', 'video/x-sgi-movie' => 'movie', ]; public function mimeType(): string { return array_rand($this->mimeTypes, 1); } public function extension(): string { $extension = $this->mimeTypes[array_rand($this->mimeTypes, 1)]; return is_array($extension) ? $extension[array_rand($extension, 1)] : $extension; } public function filePath(): string { return tempnam(sys_get_temp_dir(), 'faker'); } } src/Core/Uuid.php 0000644 00000003331 15025036220 0007635 0 ustar 00 <?php namespace Faker\Core; use Faker\Extension\UuidExtension; final class Uuid implements UuidExtension { public function uuid3(): string { $number = new Number(); // fix for compatibility with 32bit architecture; each mt_rand call is restricted to 32bit // two such calls will cause 64bits of randomness regardless of architecture $seed = $number->numberBetween(0, 2147483647) . '#' . $number->numberBetween(0, 2147483647); // Hash the seed and convert to a byte array $val = md5($seed, true); $byte = array_values(unpack('C16', $val)); // extract fields from byte array $tLo = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) | $byte[3]; $tMi = ($byte[4] << 8) | $byte[5]; $tHi = ($byte[6] << 8) | $byte[7]; $csLo = $byte[9]; $csHi = $byte[8] & 0x3f | (1 << 7); // correct byte order for big edian architecture if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) { $tLo = (($tLo & 0x000000ff) << 24) | (($tLo & 0x0000ff00) << 8) | (($tLo & 0x00ff0000) >> 8) | (($tLo & 0xff000000) >> 24); $tMi = (($tMi & 0x00ff) << 8) | (($tMi & 0xff00) >> 8); $tHi = (($tHi & 0x00ff) << 8) | (($tHi & 0xff00) >> 8); } // apply version number $tHi &= 0x0fff; $tHi |= (3 << 12); // cast to string return sprintf( '%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x', $tLo, $tMi, $tHi, $csHi, $csLo, $byte[10], $byte[11], $byte[12], $byte[13], $byte[14], $byte[15] ); } } src/Core/Blood.php 0000644 00000001445 15025036220 0007772 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Core; use Faker\Extension; /** * @experimental This class is experimental and does not fall under our BC promise */ final class Blood implements Extension\BloodExtension { /** * @var string[] */ private $bloodTypes = ['A', 'AB', 'B', 'O']; /** * @var string[] */ private $bloodRhFactors = ['+', '-']; public function bloodType(): string { return Extension\Helper::randomElement($this->bloodTypes); } public function bloodRh(): string { return Extension\Helper::randomElement($this->bloodRhFactors); } public function bloodGroup(): string { return sprintf( '%s%s', $this->bloodType(), $this->bloodRh() ); } } src/UniqueGenerator.php 0000644 00000004440 15025036220 0011156 0 ustar 00 <?php namespace Faker; use Faker\Extension\Extension; /** * Proxy for other generators that returns only unique values. * * Instantiated through @see Generator::unique(). * * @mixin Generator */ class UniqueGenerator { protected $generator; protected $maxRetries; /** * Maps from method names to a map with serialized result keys. * * @example [ * 'phone' => ['0123' => null], * 'city' => ['London' => null, 'Tokyo' => null], * ] * * @var array<string, array<string, null>> */ protected $uniques = []; /** * @param Extension|Generator $generator * @param int $maxRetries * @param array<string, array<string, null>> $uniques */ public function __construct($generator, $maxRetries = 10000, &$uniques = []) { $this->generator = $generator; $this->maxRetries = $maxRetries; $this->uniques = &$uniques; } public function ext(string $id) { return new self($this->generator->ext($id), $this->maxRetries, $this->uniques); } /** * Catch and proxy all generator calls but return only unique values * * @param string $attribute * * @deprecated Use a method instead. */ public function __get($attribute) { trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute); return $this->__call($attribute, []); } /** * Catch and proxy all generator calls with arguments but return only unique values * * @param string $name * @param array $arguments */ public function __call($name, $arguments) { if (!isset($this->uniques[$name])) { $this->uniques[$name] = []; } $i = 0; do { $res = call_user_func_array([$this->generator, $name], $arguments); ++$i; if ($i > $this->maxRetries) { throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries)); } } while (array_key_exists(serialize($res), $this->uniques[$name])); $this->uniques[$name][serialize($res)] = null; return $res; } } src/Container/Container.php 0000644 00000007457 15025036220 0011720 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Container; use Faker\Extension\Extension; /** * A simple implementation of a container. * * @experimental This class is experimental and does not fall under our BC promise */ final class Container implements ContainerInterface { /** * @var array<string, callable|object|string> */ private $definitions; private $services = []; /** * Create a container object with a set of definitions. The array value MUST * produce an object that implements Extension. * * @param array<string, callable|object|string> $definitions */ public function __construct(array $definitions) { $this->definitions = $definitions; } /** * Retrieve a definition from the container. * * @param string $id * * @throws \InvalidArgumentException * @throws \RuntimeException * @throws ContainerException * @throws NotInContainerException */ public function get($id): Extension { if (!is_string($id)) { throw new \InvalidArgumentException(sprintf( 'First argument of %s::get() must be string', self::class )); } if (array_key_exists($id, $this->services)) { return $this->services[$id]; } if (!$this->has($id)) { throw new NotInContainerException(sprintf( 'There is not service with id "%s" in the container.', $id )); } $definition = $this->definitions[$id]; $service = $this->services[$id] = $this->getService($id, $definition); if (!$service instanceof Extension) { throw new \RuntimeException(sprintf( 'Service resolved for identifier "%s" does not implement the %s" interface.', $id, Extension::class )); } return $service; } /** * Get the service from a definition. * * @param callable|object|string $definition */ private function getService($id, $definition) { if (is_callable($definition)) { try { return $definition(); } catch (\Throwable $e) { throw new ContainerException( sprintf('Error while invoking callable for "%s"', $id), 0, $e ); } } elseif (is_object($definition)) { return $definition; } elseif (is_string($definition)) { if (class_exists($definition)) { try { return new $definition(); } catch (\Throwable $e) { throw new ContainerException(sprintf('Could not instantiate class "%s"', $id), 0, $e); } } throw new ContainerException(sprintf( 'Could not instantiate class "%s". Class was not found.', $id )); } else { throw new ContainerException(sprintf( 'Invalid type for definition with id "%s"', $id )); } } /** * Check if the container contains a given identifier. * * @param string $id * * @throws \InvalidArgumentException */ public function has($id): bool { if (!is_string($id)) { throw new \InvalidArgumentException(sprintf( 'First argument of %s::get() must be string', self::class )); } return array_key_exists($id, $this->definitions); } /** * Get the bindings between Extension interfaces and implementations. */ public function getDefinitions(): array { return $this->definitions; } } src/Container/ContainerBuilder.php 0000644 00000005072 15025036220 0013216 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Container; use Faker\Core; use Faker\Extension\BarcodeExtension; use Faker\Extension\BloodExtension; use Faker\Extension\ColorExtension; use Faker\Extension\DateTimeExtension; use Faker\Extension\FileExtension; use Faker\Extension\NumberExtension; use Faker\Extension\UuidExtension; use Faker\Extension\VersionExtension; /** * @experimental This class is experimental and does not fall under our BC promise */ final class ContainerBuilder { /** * @var array<string, callable|object|string> */ private $definitions = []; /** * @param callable|object|string $value * * @throws \InvalidArgumentException */ public function add($value, string $name = null): self { if (!is_string($value) && !is_callable($value) && !is_object($value)) { throw new \InvalidArgumentException(sprintf( 'First argument to "%s::add()" must be a string, callable or object.', self::class )); } if ($name === null) { if (is_string($value)) { $name = $value; } elseif (is_object($value)) { $name = get_class($value); } else { throw new \InvalidArgumentException(sprintf( 'Second argument to "%s::add()" is required not passing a string or object as first argument', self::class )); } } $this->definitions[$name] = $value; return $this; } public function build(): ContainerInterface { return new Container($this->definitions); } /** * Get an array with extension that represent the default English * functionality. */ public static function defaultExtensions(): array { return [ BarcodeExtension::class => Core\Barcode::class, BloodExtension::class => Core\Blood::class, ColorExtension::class => Core\Color::class, DateTimeExtension::class => Core\DateTime::class, FileExtension::class => Core\File::class, NumberExtension::class => Core\Number::class, VersionExtension::class => Core\Version::class, UuidExtension::class => Core\Uuid::class, ]; } public static function getDefault(): ContainerInterface { $instance = new self(); foreach (self::defaultExtensions() as $id => $definition) { $instance->add($definition, $id); } return $instance->build(); } } src/Container/ContainerException.php 0000644 00000000454 15025036220 0013565 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Container; use Psr\Container\ContainerExceptionInterface; /** * @experimental This class is experimental and does not fall under our BC promise */ final class ContainerException extends \RuntimeException implements ContainerExceptionInterface { } src/Container/NotInContainerException.php 0000644 00000000457 15025036220 0014540 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Container; use Psr\Container\NotFoundExceptionInterface; /** * @experimental This class is experimental and does not fall under our BC promise */ final class NotInContainerException extends \RuntimeException implements NotFoundExceptionInterface { } src/Container/ContainerInterface.php 0000644 00000000453 15025036220 0013526 0 ustar 00 <?php namespace Faker\Container; use Psr\Container\ContainerInterface as BaseContainerInterface; interface ContainerInterface extends BaseContainerInterface { /** * Get the bindings between Extension interfaces and implementations. */ public function getDefinitions(): array; } src/ChanceGenerator.php 0000644 00000002622 15025036220 0011071 0 ustar 00 <?php namespace Faker; use Faker\Extension\Extension; /** * This generator returns a default value for all called properties * and methods. It works with Faker\Generator::optional(). * * @mixin Generator */ class ChanceGenerator { private $generator; private $weight; protected $default; /** * @param Extension|Generator $generator */ public function __construct($generator, float $weight, $default = null) { $this->default = $default; $this->generator = $generator; $this->weight = $weight; } public function ext(string $id) { return new self($this->generator->ext($id), $this->weight, $this->default); } /** * Catch and proxy all generator calls but return only valid values * * @param string $attribute * * @deprecated Use a method instead. */ public function __get($attribute) { trigger_deprecation('fakerphp/faker', '1.14', 'Accessing property "%s" is deprecated, use "%s()" instead.', $attribute, $attribute); return $this->__call($attribute, []); } /** * @param string $name * @param array $arguments */ public function __call($name, $arguments) { if (mt_rand(1, 100) <= (100 * $this->weight)) { return call_user_func_array([$this->generator, $name], $arguments); } return $this->default; } } src/Guesser/Name.php 0000644 00000012476 15025036220 0010346 0 ustar 00 <?php namespace Faker\Guesser; use Faker\Extension\Helper; use Faker\Generator; class Name { protected $generator; public function __construct(Generator $generator) { $this->generator = $generator; } /** * Guess a generator based on the name of a field. * * @param string $name Name of the field to guess * @param int|null $size Length of field, if known * * @return callable|null */ public function guessFormat(string $name, ?int $size = null) { $name = Helper::toLower($name); $generator = $this->generator; if (preg_match('/^is[_A-Z]/', $name)) { return static function () use ($generator) { return $generator->boolean; }; } if (preg_match('/(_a|A)t$/', $name)) { return static function () use ($generator) { return $generator->dateTime; }; } switch (str_replace('_', '', $name)) { case 'firstname': return static function () use ($generator) { return $generator->firstName; }; case 'lastname': return static function () use ($generator) { return $generator->lastName; }; case 'username': case 'login': return static function () use ($generator) { return $generator->userName; }; case 'email': case 'emailaddress': return static function () use ($generator) { return $generator->email; }; case 'phonenumber': case 'phone': case 'telephone': case 'telnumber': return static function () use ($generator) { return $generator->phoneNumber; }; case 'address': return static function () use ($generator) { return $generator->address; }; case 'city': case 'town': return static function () use ($generator) { return $generator->city; }; case 'streetaddress': return static function () use ($generator) { return $generator->streetAddress; }; case 'postcode': case 'zipcode': return static function () use ($generator) { return $generator->postcode; }; case 'state': return static function () use ($generator) { return $generator->state; }; case 'county': if ($this->generator->locale == 'en_US') { return static function () use ($generator) { return sprintf('%s County', $generator->city); }; } return static function () use ($generator) { return $generator->state; }; case 'country': switch ($size) { case 2: return static function () use ($generator) { return $generator->countryCode; }; case 3: return static function () use ($generator) { return $generator->countryISOAlpha3; }; case 5: case 6: return static function () use ($generator) { return $generator->locale; }; default: return static function () use ($generator) { return $generator->country; }; } // no break case 'locale': return static function () use ($generator) { return $generator->locale; }; case 'currency': case 'currencycode': return static function () use ($generator) { return $generator->currencyCode; }; case 'url': case 'website': return static function () use ($generator) { return $generator->url; }; case 'company': case 'companyname': case 'employer': return static function () use ($generator) { return $generator->company; }; case 'title': if ($size !== null && $size <= 10) { return static function () use ($generator) { return $generator->title; }; } return static function () use ($generator) { return $generator->sentence; }; case 'body': case 'summary': case 'article': case 'description': return static function () use ($generator) { return $generator->text; }; } return null; } } src/Extension/PersonExtension.php 0000644 00000002142 15025036220 0013155 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface PersonExtension extends Extension { public const GENDER_FEMALE = 'female'; public const GENDER_MALE = 'male'; /** * @param string|null $gender 'male', 'female' or null for any * * @example 'John Doe' */ public function name(?string $gender = null): string; /** * @param string|null $gender 'male', 'female' or null for any * * @example 'John' */ public function firstName(?string $gender = null): string; public function firstNameMale(): string; public function firstNameFemale(): string; /** * @example 'Doe' */ public function lastName(): string; /** * @example 'Mrs.' * * @param string|null $gender 'male', 'female' or null for any */ public function title(?string $gender = null): string; /** * @example 'Mr.' */ public function titleMale(): string; /** * @example 'Mrs.' */ public function titleFemale(): string; } src/Extension/GeneratorAwareExtension.php 0000644 00000000751 15025036220 0014621 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Extension; use Faker\Generator; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface GeneratorAwareExtension extends Extension { /** * This method MUST be implemented in such a way as to retain the * immutability of the extension, and MUST return an instance that has the * new Generator. */ public function withGenerator(Generator $generator): Extension; } src/Extension/VersionExtension.php 0000644 00000001163 15025036220 0013336 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface VersionExtension extends Extension { /** * Get a version number in semantic versioning syntax 2.0.0. (https://semver.org/spec/v2.0.0.html) * * @param bool $preRelease Pre release parts may be randomly included * @param bool $build Build parts may be randomly included * * @example 1.0.0 * @example 1.0.0-alpha.1 * @example 1.0.0-alpha.1+b71f04d */ public function semver(bool $preRelease = false, bool $build = false): string; } src/Extension/PhoneNumberExtension.php 0000644 00000000555 15025036220 0014137 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface PhoneNumberExtension extends Extension { /** * @example '555-123-546' */ public function phoneNumber(): string; /** * @example +27113456789 */ public function e164PhoneNumber(): string; } src/Extension/CompanyExtension.php 0000644 00000000602 15025036220 0013314 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface CompanyExtension extends Extension { /** * @example 'Acme Ltd' */ public function company(): string; /** * @example 'Ltd' */ public function companySuffix(): string; public function jobTitle(): string; } src/Extension/ExtensionNotFound.php 0000644 00000000322 15025036220 0013441 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Extension; /** * @experimental This class is experimental and does not fall under our BC promise */ final class ExtensionNotFound extends \LogicException { } src/Extension/UuidExtension.php 0000644 00000000524 15025036220 0012617 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface UuidExtension extends Extension { /** * Generate name based md5 UUID (version 3). * * @example '7e57d004-2b97-0e7a-b45f-5387367791cd' */ public function uuid3(): string; } src/Extension/BarcodeExtension.php 0000644 00000001514 15025036220 0013250 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface BarcodeExtension extends Extension { /** * Get a random EAN13 barcode. * * @example '4006381333931' */ public function ean13(): string; /** * Get a random EAN8 barcode. * * @example '73513537' */ public function ean8(): string; /** * Get a random ISBN-10 code * * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number * * @example '4881416324' */ public function isbn10(): string; /** * Get a random ISBN-13 code * * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number * * @example '9790404436093' */ public function isbn13(): string; } src/Extension/AddressExtension.php 0000644 00000001372 15025036220 0013300 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface AddressExtension extends Extension { /** * @example '791 Crist Parks, Sashabury, IL 86039-9874' */ public function address(): string; /** * Randomly return a real city name. */ public function city(): string; /** * @example 86039-9874 */ public function postcode(): string; /** * @example 'Crist Parks' */ public function streetName(): string; /** * @example '791 Crist Parks' */ public function streetAddress(): string; /** * Randomly return a building number. */ public function buildingNumber(): string; } src/Extension/NumberExtension.php 0000644 00000002557 15025036220 0013151 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface NumberExtension extends Extension { /** * Returns a random number between $int1 and $int2 (any order) * * @param int $min default to 0 * @param int $max defaults to 32 bit max integer, ie 2147483647 * * @example 79907610 */ public function numberBetween(int $min, int $max): int; /** * Returns a random number between 0 and 9 */ public function randomDigit(): int; /** * Generates a random digit, which cannot be $except */ public function randomDigitNot(int $except): int; /** * Returns a random number between 1 and 9 */ public function randomDigitNotZero(): int; /** * Return a random float number * * @example 48.8932 */ public function randomFloat(?int $nbMaxDecimals, float $min, ?float $max): float; /** * Returns a random integer with 0 to $nbDigits digits. * * The maximum value returned is mt_getrandmax() * * @param int|null $nbDigits Defaults to a random number between 1 and 9 * @param bool $strict Whether the returned number should have exactly $nbDigits * * @example 79907610 */ public function randomNumber(?int $nbDigits, bool $strict): int; } src/Extension/FileExtension.php 0000644 00000001043 15025036220 0012565 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface FileExtension extends Extension { /** * Get a random MIME type * * @example 'video/avi' */ public function mimeType(): string; /** * Get a random file extension (without a dot) * * @example avi */ public function extension(): string; /** * Get a full path to a new real file on the system. */ public function filePath(): string; } src/Extension/Extension.php 0000644 00000000372 15025036220 0011771 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Extension; /** * An extension is the only way to add new functionality to Faker. * * @experimental This interface is experimental and does not fall under our BC promise */ interface Extension { } src/Extension/DateTimeExtension.php 0000644 00000021704 15025036220 0013410 0 ustar 00 <?php namespace Faker\Extension; /** * FakerPHP extension for Date-related randomization. * * Functions accepting a date string use the `strtotime()` function internally. * * @experimental * * @since 1.20.0 */ interface DateTimeExtension extends Extension { /** * Get a DateTime object between January 1, 1970, and `$until` (defaults to "now"). * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php * * @example DateTime('2005-08-16 20:39:21') */ public function dateTime($until = 'now', string $timezone = null): \DateTime; /** * Get a DateTime object for a date between January 1, 0001, and now. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @example DateTime('1265-03-22 21:15:52') * * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeAD($until = 'now', string $timezone = null): \DateTime; /** * Get a DateTime object a random date between `$from` and `$until`. * Accepts date strings that can be recognized by `strtotime()`. * * @param \DateTime|string $from defaults to 30 years ago * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeBetween($from = '-30 years', $until = 'now', string $timezone = null): \DateTime; /** * Get a DateTime object based on a random date between `$from` and an interval. * Accepts date string that can be recognized by `strtotime()`. * * @param \DateTime|int|string $from defaults to 30 years ago * @param string $interval defaults to 5 days after * @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeInInterval($from = '-30 years', string $interval = '+5 days', string $timezone = null): \DateTime; /** * Get a date time object somewhere inside the current week. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone zone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeThisWeek($until = 'now', string $timezone = null): \DateTime; /** * Get a date time object somewhere inside the current month. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeThisMonth($until = 'now', string $timezone = null): \DateTime; /** * Get a date time object somewhere inside the current year. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeThisYear($until = 'now', string $timezone = null): \DateTime; /** * Get a date time object somewhere inside the current decade. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeThisDecade($until = 'now', string $timezone = null): \DateTime; /** * Get a date time object somewhere inside the current century. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * @param string|null $timezone timezone for generated date, fallback to `DateTime::$defaultTimezone` and `date_default_timezone_get()`. * * @see \DateTimeZone * @see http://php.net/manual/en/timezones.php * @see http://php.net/manual/en/function.date-default-timezone-get.php */ public function dateTimeThisCentury($until = 'now', string $timezone = null): \DateTime; /** * Get a date string between January 1, 1970, and `$until`. * * @param string $format DateTime format * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @see https://www.php.net/manual/en/datetime.format.php */ public function date(string $format = 'Y-m-d', $until = 'now'): string; /** * Get a time string (24h format by default). * * @param string $format DateTime format * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @see https://www.php.net/manual/en/datetime.format.php */ public function time(string $format = 'H:i:s', $until = 'now'): string; /** * Get a UNIX (POSIX-compatible) timestamp between January 1, 1970, and `$until`. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" */ public function unixTime($until = 'now'): int; /** * Get a date string according to the ISO-8601 standard. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" */ public function iso8601($until = 'now'): string; /** * Get a string containing either "am" or "pm". * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @example 'am' */ public function amPm($until = 'now'): string; /** * Get a localized random day of the month. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @example '16' */ public function dayOfMonth($until = 'now'): string; /** * Get a localized random day of the week. * * Uses internal DateTime formatting, hence PHP's internal locale will be used (change using `setlocale()`). * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @example 'Tuesday' * * @see setlocale * @see https://www.php.net/manual/en/function.setlocale.php Set a different output language */ public function dayOfWeek($until = 'now'): string; /** * Get a random month (numbered). * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @example '7' */ public function month($until = 'now'): string; /** * Get a random month. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @see setlocale * @see https://www.php.net/manual/en/function.setlocale.php Set a different output language * * @example 'September' */ public function monthName($until = 'now'): string; /** * Get a random year between 1970 and `$until`. * * @param \DateTime|int|string $until maximum timestamp, defaults to "now" * * @example '1987' */ public function year($until = 'now'): string; /** * Get a random century, formatted as Roman numerals. * * @example 'XVII' */ public function century(): string; /** * Get a random timezone, uses `\DateTimeZone::listIdentifiers()` internally. * * @example 'Europe/Rome' */ public function timezone(): string; } src/Extension/GeneratorAwareExtensionTrait.php 0000644 00000000736 15025036220 0015630 0 ustar 00 <?php declare(strict_types=1); namespace Faker\Extension; use Faker\Generator; /** * A helper trait to be used with GeneratorAwareExtension. */ trait GeneratorAwareExtensionTrait { /** * @var Generator|null */ private $generator; /** * @return static */ public function withGenerator(Generator $generator): Extension { $instance = clone $this; $instance->generator = $generator; return $instance; } } src/Extension/Helper.php 0000644 00000006763 15025036220 0011246 0 ustar 00 <?php namespace Faker\Extension; /** * A class with some methods that may make building extensions easier. * * @experimental This class is experimental and does not fall under our BC promise */ final class Helper { /** * Returns a random element from a passed array. */ public static function randomElement(array $array) { if ($array === []) { return null; } return $array[array_rand($array, 1)]; } /** * Replaces all hash sign ('#') occurrences with a random number * Replaces all percentage sign ('%') occurrences with a non-zero number. * * @param string $string String that needs to bet parsed */ public static function numerify(string $string): string { // instead of using randomDigit() several times, which is slow, // count the number of hashes and generate once a large number $toReplace = []; if (($pos = strpos($string, '#')) !== false) { for ($i = $pos, $last = strrpos($string, '#', $pos) + 1; $i < $last; ++$i) { if ($string[$i] === '#') { $toReplace[] = $i; } } } if ($nbReplacements = count($toReplace)) { $maxAtOnce = strlen((string) mt_getrandmax()) - 1; $numbers = ''; $i = 0; while ($i < $nbReplacements) { $size = min($nbReplacements - $i, $maxAtOnce); $numbers .= str_pad((string) mt_rand(0, 10 ** $size - 1), $size, '0', STR_PAD_LEFT); $i += $size; } for ($i = 0; $i < $nbReplacements; ++$i) { $string[$toReplace[$i]] = $numbers[$i]; } } return self::replaceWildcard($string, '%', static function () { return mt_rand(1, 9); }); } /** * Replaces all question mark ('?') occurrences with a random letter. * * @param string $string String that needs to bet parsed */ public static function lexify(string $string): string { return self::replaceWildcard($string, '?', static function () { return chr(mt_rand(97, 122)); }); } /** * Replaces hash signs ('#') and question marks ('?') with random numbers and letters * An asterisk ('*') is replaced with either a random number or a random letter. * * @param string $string String that needs to bet parsed */ public static function bothify(string $string): string { $string = self::replaceWildcard($string, '*', static function () { return mt_rand(0, 1) ? '#' : '?'; }); return Helper::lexify(Helper::numerify($string)); } /** * Converts string to lowercase. * Uses mb_string extension if available. * * @param string $string String that should be converted to lowercase */ public static function toLower(string $string): string { return extension_loaded('mbstring') ? mb_strtolower($string, 'UTF-8') : strtolower($string); } private static function replaceWildcard(string $string, string $wildcard, callable $callback): string { if (($pos = strpos($string, $wildcard)) === false) { return $string; } for ($i = $pos, $last = strrpos($string, $wildcard, $pos) + 1; $i < $last; ++$i) { if ($string[$i] === $wildcard) { $string[$i] = call_user_func($callback); } } return $string; } } src/Extension/ColorExtension.php 0000644 00000002155 15025036220 0012771 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface ColorExtension extends Extension { /** * @example '#fa3cc2' */ public function hexColor(): string; /** * @example '#ff0044' */ public function safeHexColor(): string; /** * @example 'array(0,255,122)' * * @return int[] */ public function rgbColorAsArray(): array; /** * @example '0,255,122' */ public function rgbColor(): string; /** * @example 'rgb(0,255,122)' */ public function rgbCssColor(): string; /** * @example 'rgba(0,255,122,0.8)' */ public function rgbaCssColor(): string; /** * @example 'blue' */ public function safeColorName(): string; /** * @example 'NavajoWhite' */ public function colorName(): string; /** * @example '340,50,20' */ public function hslColor(): string; /** * @example array(340, 50, 20) * * @return int[] */ public function hslColorAsArray(): array; } src/Extension/BloodExtension.php 0000644 00000001017 15025036220 0012746 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface BloodExtension extends Extension { /** * Get an actual blood type * * @example 'AB' */ public function bloodType(): string; /** * Get a random resis value * * @example '+' */ public function bloodRh(): string; /** * Get a full blood group * * @example 'AB+' */ public function bloodGroup(): string; } src/Extension/CountryExtension.php 0000644 00000000402 15025036220 0013347 0 ustar 00 <?php namespace Faker\Extension; /** * @experimental This interface is experimental and does not fall under our BC promise */ interface CountryExtension extends Extension { /** * @example 'Japan' */ public function country(): string; } src/Factory.php 0000644 00000003771 15025036220 0007456 0 ustar 00 <?php namespace Faker; class Factory { public const DEFAULT_LOCALE = 'en_US'; protected static $defaultProviders = ['Address', 'Barcode', 'Biased', 'Color', 'Company', 'DateTime', 'File', 'HtmlLorem', 'Image', 'Internet', 'Lorem', 'Medical', 'Miscellaneous', 'Payment', 'Person', 'PhoneNumber', 'Text', 'UserAgent', 'Uuid']; /** * Create a new generator * * @param string $locale * * @return Generator */ public static function create($locale = self::DEFAULT_LOCALE) { $generator = new Generator(); foreach (static::$defaultProviders as $provider) { $providerClassName = self::getProviderClassname($provider, $locale); $generator->addProvider(new $providerClassName($generator)); } return $generator; } /** * @param string $provider * @param string $locale * * @return string */ protected static function getProviderClassname($provider, $locale = '') { if ($providerClass = self::findProviderClassname($provider, $locale)) { return $providerClass; } // fallback to default locale if ($providerClass = self::findProviderClassname($provider, static::DEFAULT_LOCALE)) { return $providerClass; } // fallback to no locale if ($providerClass = self::findProviderClassname($provider)) { return $providerClass; } throw new \InvalidArgumentException(sprintf('Unable to find provider "%s" with locale "%s"', $provider, $locale)); } /** * @param string $provider * @param string $locale * * @return string|null */ protected static function findProviderClassname($provider, $locale = '') { $providerClass = 'Faker\\' . ($locale ? sprintf('Provider\%s\%s', $locale, $provider) : sprintf('Provider\%s', $provider)); if (class_exists($providerClass, true)) { return $providerClass; } return null; } } psalm.baseline.xml 0000644 00000014337 15025036220 0010166 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <files psalm-version="4.17.0@6f4707aa41c9174353a6434bba3fc8840f981d9c"> <file src="src/Calculator/Luhn.php"> <InvalidReturnStatement occurrences="1"> <code>0</code> </InvalidReturnStatement> <InvalidReturnType occurrences="1"> <code>string</code> </InvalidReturnType> </file> <file src="src/Generator.php"> <InvalidReturnStatement occurrences="3"> <code>$this->uniqueGenerator</code> <code>new ChanceGenerator($this, $weight, $default)</code> <code>new ValidGenerator($this, $validator, $maxRetries)</code> </InvalidReturnStatement> <InvalidReturnType occurrences="3"> <code>self</code> <code>self</code> <code>self</code> </InvalidReturnType> </file> <file src="src/ORM/CakePHP/EntityPopulator.php"> <UndefinedClass occurrences="1"> <code>TableRegistry</code> </UndefinedClass> </file> <file src="src/ORM/Doctrine/EntityPopulator.php"> <UndefinedClass occurrences="6"> <code>$this->class</code> <code>\Doctrine\ODM\MongoDB\Mapping\ClassMetadata</code> <code>\Doctrine\ODM\MongoDB\Mapping\ClassMetadata</code> <code>\Doctrine\ODM\MongoDB\Mapping\ClassMetadata</code> <code>\Doctrine\ORM\Mapping\ClassMetadata</code> <code>\Doctrine\ORM\Mapping\ClassMetadata</code> </UndefinedClass> <UndefinedInterfaceMethod occurrences="3"> <code>createQueryBuilder</code> <code>getAssociationMappings</code> <code>newInstance</code> </UndefinedInterfaceMethod> </file> <file src="src/ORM/Mandango/EntityPopulator.php"> <UndefinedClass occurrences="2"> <code>Mandango</code> <code>Mandango</code> </UndefinedClass> </file> <file src="src/ORM/Mandango/Populator.php"> <UndefinedClass occurrences="2"> <code>$this->mandango</code> <code>Mandango</code> </UndefinedClass> </file> <file src="src/ORM/Propel/ColumnTypeGuesser.php"> <UndefinedClass occurrences="1"> <code>\ColumnMap</code> </UndefinedClass> </file> <file src="src/ORM/Propel/EntityPopulator.php"> <UndefinedClass occurrences="9"> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>\ColumnMap</code> </UndefinedClass> </file> <file src="src/ORM/Propel/Populator.php"> <UndefinedClass occurrences="1"> <code>\Propel</code> </UndefinedClass> <UndefinedDocblockClass occurrences="1"> <code>PropelPDO</code> </UndefinedDocblockClass> </file> <file src="src/ORM/Propel2/ColumnTypeGuesser.php"> <UndefinedClass occurrences="1"> <code>ColumnMap</code> </UndefinedClass> </file> <file src="src/ORM/Propel2/EntityPopulator.php"> <UndefinedClass occurrences="9"> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>$columnMap</code> <code>ColumnMap</code> </UndefinedClass> </file> <file src="src/ORM/Propel2/Populator.php"> <UndefinedClass occurrences="1"> <code>Propel</code> </UndefinedClass> <UndefinedDocblockClass occurrences="1"> <code>PropelPDO</code> </UndefinedDocblockClass> </file> <file src="src/ORM/Spot/EntityPopulator.php"> <InvalidReturnStatement occurrences="1"> <code>$this->mapper</code> </InvalidReturnStatement> <InvalidReturnType occurrences="1"> <code>string</code> </InvalidReturnType> <UndefinedClass occurrences="5"> <code>$relation</code> <code>$relation</code> <code>BelongsTo</code> <code>Locator</code> <code>Mapper</code> </UndefinedClass> <UndefinedDocblockClass occurrences="8"> <code>$locator</code> <code>$this->mapper</code> <code>$this->mapper</code> <code>$this->mapper</code> <code>$this->mapper</code> <code>$this->mapper</code> <code>Locator</code> <code>Mapper</code> </UndefinedDocblockClass> </file> <file src="src/ORM/Spot/Populator.php"> <UndefinedClass occurrences="2"> <code>$this->locator</code> <code>Locator</code> </UndefinedClass> <UndefinedDocblockClass occurrences="1"> <code>Locator</code> </UndefinedDocblockClass> </file> <file src="src/Provider/Base.php"> <UndefinedDocblockClass occurrences="1"> <code>Closure</code> </UndefinedDocblockClass> </file> <file src="src/Provider/File.php"> <FalsableReturnStatement occurrences="1"> <code>false</code> </FalsableReturnStatement> </file> <file src="src/Provider/PhoneNumber.php"> <InvalidReturnStatement occurrences="1"> <code>$imei</code> </InvalidReturnStatement> <InvalidReturnType occurrences="1"> <code>int</code> </InvalidReturnType> </file> <file src="src/Provider/ar_SA/Address.php"> <UndefinedPropertyFetch occurrences="1"> <code>static::$cityPrefix</code> </UndefinedPropertyFetch> </file> <file src="src/Provider/cs_CZ/Person.php"> <NonStaticSelfCall occurrences="2"> <code>static::birthNumber(static::GENDER_FEMALE)</code> <code>static::birthNumber(static::GENDER_MALE)</code> </NonStaticSelfCall> </file> <file src="src/Provider/en_SG/Person.php"> <InvalidArrayOffset occurrences="1"> <code>$checksumArr[$checksum % 11]</code> </InvalidArrayOffset> </file> <file src="src/Provider/is_IS/Person.php"> <InvalidArrayOffset occurrences="1"> <code>$ref[$i]</code> </InvalidArrayOffset> </file> <file src="src/Provider/ja_JP/Text.php"> <UndefinedMethod occurrences="1"> <code>static::split($text)</code> </UndefinedMethod> </file> <file src="src/Provider/pl_PL/Person.php"> <UndefinedDocblockClass occurrences="1"> <code>DateTime</code> </UndefinedDocblockClass> </file> <file src="src/Provider/sl_SI/Person.php"> <NonStaticSelfCall occurrences="2"> <code>static::lastName()</code> <code>static::lastName()</code> </NonStaticSelfCall> </file> </files> README.md 0000644 00000005607 15025036220 0006026 0 ustar 00 <p style="text-align: center"><img src="https://github.com/FakerPHP/Artwork/raw/main/src/socialcard.png" alt="Social card of FakerPHP"></p> # Faker [](https://packagist.org/packages/fakerphp/faker) [](https://github.com/FakerPHP/Faker/actions) [](https://shepherd.dev/github/FakerPHP/Faker) [](https://codecov.io/gh/FakerPHP/Faker) Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you. It's heavily inspired by Perl's [Data::Faker](https://metacpan.org/pod/Data::Faker), and by Ruby's [Faker](https://rubygems.org/gems/faker). ## Getting Started ### Installation Faker requires PHP >= 7.1. ```shell composer require fakerphp/faker ``` ### Documentation Full documentation can be found over on [fakerphp.github.io](https://fakerphp.github.io). ### Basic Usage Use `Faker\Factory::create()` to create and initialize a Faker generator, which can generate data by accessing methods named after the type of data you want. ```php <?php require_once 'vendor/autoload.php'; // use the factory to create a Faker\Generator instance $faker = Faker\Factory::create(); // generate data by calling methods echo $faker->name(); // 'Vince Sporer' echo $faker->email(); // 'walter.sophia@hotmail.com' echo $faker->text(); // 'Numquam ut mollitia at consequuntur inventore dolorem.' ``` Each call to `$faker->name()` yields a different (random) result. This is because Faker uses `__call()` magic, and forwards `Faker\Generator->$method()` calls to `Faker\Generator->format($method, $attributes)`. ```php <?php for ($i = 0; $i < 3; $i++) { echo $faker->name() . "\n"; } // 'Cyrus Boyle' // 'Alena Cummerata' // 'Orlo Bergstrom' ``` ## License Faker is released under the MIT License. See [`LICENSE`](LICENSE) for details. ## Backward compatibility promise Faker is using [Semver](https://semver.org/). This means that versions are tagged with MAJOR.MINOR.PATCH. Only a new major version will be allowed to break backward compatibility (BC). Classes marked as `@experimental` or `@internal` are not included in our backward compatibility promise. You are also not guaranteed that the value returned from a method is always the same. You are guaranteed that the data type will not change. PHP 8 introduced [named arguments](https://wiki.php.net/rfc/named_params), which increased the cost and reduces flexibility for package maintainers. The names of the arguments for methods in Faker is not included in our BC promise. LICENSE 0000644 00000002242 15025036220 0005544 0 ustar 00 Copyright (c) 2011 François Zaninotto Portions Copyright (c) 2008 Caius Durling Portions Copyright (c) 2008 Adam Royle Portions Copyright (c) 2008 Fiona Burrows 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.
| ver. 1.4 |
.
| PHP 8.0.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings