### Install Project Dependencies Source: https://github.com/xefi/faker-doc/blob/main/README.md Installs the necessary project dependencies using various package managers (npm, pnpm, yarn, bun). Ensure you have your preferred package manager installed. ```bash # npm npm install # pnpm pnpm install # yarn yarn install # bun bun install ``` -------------------------------- ### Install Faker PHP using Composer Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/2.usage.md This command installs the Faker PHP library as a development dependency using Composer. Ensure you have Composer installed and your PHP version is 8.3 or higher. ```bash composer require --dev xefi/faker-php ``` -------------------------------- ### Start Nuxt Development Server Source: https://github.com/xefi/faker-doc/blob/main/README.md Starts the Nuxt development server, typically accessible at http://localhost:3000. This command is used for local development and hot-reloading. ```bash # npm npm run dev # pnpm pnpm run dev # yarn yarn dev # bun bun run dev ``` -------------------------------- ### Install Nuxt Studio Dev Dependency Source: https://github.com/xefi/faker-doc/blob/main/README.md Installs the `@nuxthq/studio` package as a development dependency. This package is required for Nuxt Studio integration. ```bash # npm npm install --save-dev @nuxthq/studio # pnpm pnpm add -D @nuxthq/studio # yarn yarn add -D @nuxthq/studio # bun bun add -d @nuxthq/studio ``` -------------------------------- ### Install Xefi Faker PHP en_GB Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Installs the Xefi Faker PHP en_GB locale using Composer. This is a development dependency. ```bash composer require --dev xefi/faker-php-locales-en-gb ``` -------------------------------- ### Initialize Nuxt UI Pro Docs Template Source: https://github.com/xefi/faker-doc/blob/main/README.md Initializes a new Nuxt project using the Nuxt UI Pro Docs template. This command requires npx to be installed and available in your PATH. ```bash npx nuxi init -t github:nuxt-ui-pro/docs ``` -------------------------------- ### Install Faker PHP Laravel Package Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/3.integrations.md Installs the Xefi Faker PHP compatibility package for Laravel using Composer. This enables seamless integration with Laravel's factory system. ```bash composer require --dev xefi/faker-php-laravel ``` -------------------------------- ### Install Faker PHP Symfony Package Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/3.integrations.md Installs the Xefi Faker PHP compatibility package for Symfony using Composer. This allows Faker to be injected as a service within Symfony applications. ```bash composer require --dev xefi/faker-php-symfony ``` -------------------------------- ### Install Currencies Extension for Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/currencies.md This command installs the Currencies extension for Xefi Faker PHP using Composer. It is a development dependency and not included in the base package. ```bash composer require --dev xefi/faker-php-currencies ``` -------------------------------- ### Install Xefi Faker PHP French (Switzerland) Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md This command installs the necessary package for the French (Switzerland) locale for Xefi Faker PHP using Composer. Ensure you have Composer installed and configured. ```bash composer require --dev xefi/faker-php-locales-fr-ch ``` -------------------------------- ### Install French (Belgium) Faker Locale via Composer Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md This command installs the French (Belgium) locale extension for Xefi Faker PHP using Composer. Ensure you have Composer installed and the Xefi Faker library set up in your project. ```bash composer require --dev xefi/faker-php-locales-fr-be ``` -------------------------------- ### Install Xefi Faker PHP Images Extension Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/images.md This command installs the Xefi Faker PHP Images extension using Composer. It is a development dependency, indicated by the --dev flag. ```bash composer require --dev xefi/faker-php-images ``` -------------------------------- ### Setup Xefi Faker PHP with en_GB Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Initializes the Xefi Faker PHP generator with the 'en_GB' locale to enable the use of United Kingdom-specific data generation. ```php $faker = new Xefi\Faker\Faker('en_GB'); ``` -------------------------------- ### Install Xefi Faker PHP en_US Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-us.md This command installs the English (United States) locale for Xefi Faker PHP using Composer. It's a development dependency. ```bash composer require --dev xefi/faker-php-locales-en-us ``` -------------------------------- ### Install Xefi Faker PHP Spanish Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/es-es.md Installs the Spanish (Spain) locale for Xefi Faker PHP using Composer. This is a prerequisite for using the Spanish locale features. ```bash composer require --dev xefi/faker-php-locales-es-es ``` -------------------------------- ### Install Xefi Faker PHP Pakistan Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-pk.md Installs the necessary package for the English Pakistan locale for Xefi Faker PHP using Composer. This is a development dependency. ```bash composer require --dev xefi/faker-php-locales-en-pk ``` -------------------------------- ### Use Faker in Laravel Factories Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/3.integrations.md Demonstrates how to use the faker helper within Laravel's Eloquent model factories to generate fake data for model attributes. It assumes the faker-php-laravel package is installed. ```php namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> */ class UserFactory extends Factory { /** * The current password being used by the factory. */ protected static ?string $password; /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'name' => faker()->name(), 'email' => faker()->unique()->email(), ]; } } ``` -------------------------------- ### Configure Package Discovery in composer.json Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/4.package-development.md This JSON snippet shows how to configure your package's composer.json file to enable automatic discovery of Faker service providers. It specifies the path to the service provider class within the 'extra.faker.providers' array, ensuring Faker loads it automatically upon installation. ```json { "extra": { "faker": { "providers": [ "Xefi\\FakerNumber\\NumberServiceProvider" ] } } } ``` -------------------------------- ### Install French Locale for Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-fr.md Installs the French (France) locale package for Xefi Faker PHP using Composer. This is a prerequisite for using French-specific data generation. ```bash composer require --dev xefi/faker-php-locales-fr-fr ``` -------------------------------- ### Install Xefi Faker PHP Indian English Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-in.md Installs the Indian English locale package for Xefi Faker PHP using Composer. This is a development dependency. ```bash composer require --dev xefi/faker-php-locales-en-in ``` -------------------------------- ### Install German Locale for Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/de-de.md Installs the German locale package for Xefi Faker PHP using Composer. This is a development dependency required for using German-specific data generation. ```bash composer require --dev xefi/faker-php-locales-de-de ``` -------------------------------- ### Generate Image Object with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/images.md This PHP code snippet demonstrates how to generate an image object using the Xefi Faker library. It allows for customization of dimensions, background color, text color, and placeholder text. It also shows examples of saving the generated image to a file. ```php $faker->image(width: 1280, height: 720, backgroundColor: '#cccccc', textColor: '#333333', text: 'My Placeholder text'); // Examples for saving the image $image = $faker->image(); $image->toPng()->save('images/foo.png'); ``` -------------------------------- ### Generate SHA512 Hash with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/hash.md Generates a fake SHA512 hash string using the Xefi Faker library in PHP. This method requires the Xefi Faker library to be installed and the FakerFactory to be initialized. ```php $faker->sha512(); // e820c574579a8dc20c0890eebb7ea233937feb099f37e5b070308d841bcca81275ab64157cab8de66daaccb06468bbf6c5587b706a6c2887232912e501d7dfb3 ``` -------------------------------- ### Initialize Faker with en_US Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-us.md This PHP code demonstrates how to initialize the Xefi Faker generator with the 'en_US' locale. This setup is necessary before using any locale-specific data generation methods. ```php $faker = new Xefi\Faker\Faker('en_US'); ``` -------------------------------- ### Generate SHA256 Hash with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/hash.md Generates a fake SHA256 hash string using the Xefi Faker library in PHP. This method requires the Xefi Faker library to be installed and the FakerFactory to be initialized. ```php $faker->sha256(); // 8d7edc63ab003719669e96b83d76c89c86dede8dbfa04d7c37ea42e9fd2e28f9 ``` -------------------------------- ### Initialize Xefi Faker with Indian English Locale (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-in.md Initializes a new Xefi Faker instance with the 'en_IN' locale. This setup is necessary to utilize the Indian English locale's specific data generation capabilities. ```php $faker = new Xefi\Faker\Faker('en_IN'); ``` -------------------------------- ### Generate MD5 Hash with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/hash.md Generates a fake MD5 hash string using the Xefi Faker library in PHP. This method requires the Xefi Faker library to be installed and the FakerFactory to be initialized. ```php $faker->md5(); // 368f9d4f93fa6ac519bb6c951fd44ef8 ``` -------------------------------- ### Generate SHA1 Hash with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/hash.md Generates a fake SHA1 hash string using the Xefi Faker library in PHP. This method requires the Xefi Faker library to be installed and the FakerFactory to be initialized. ```php $faker->sha1(); // 2882fe0eb3bc73fcbef51572d0403efa1c48bb08 ``` -------------------------------- ### Setup Xefi Faker PHP with fr_CH Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md This PHP code snippet demonstrates how to initialize the Xefi Faker generator with the 'fr_CH' locale. This setup is crucial for generating data specific to French-speaking Switzerland. ```php $faker = new Xefi\Faker\Faker('fr_CH'); ``` -------------------------------- ### Generate Currency Name with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/currencies.md The `currencyName()` method returns a string representing the full name of a currency, for example, 'South Korean Won'. ```php $faker->currencyName() // South Korean Won ``` -------------------------------- ### Generate French (Belgium) Color Names with Faker Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md These PHP examples illustrate generating safe and standard color names using the Xefi Faker library. The methods provided are `safeColorName` for predefined safe colors and `colorName` for a broader range of color names. ```php $faker->safeColorName(); // Noir ``` ```php $faker->colorName() // BleuRoyal ``` -------------------------------- ### Generate Belgian IBAN with Faker Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md This PHP example demonstrates generating an IBAN for Belgium using the Faker library. It references the base method for IBAN generation and shows how to specify the country code 'BE'. ```php $faker->iban(countryCode: 'BE', format: 'See code') // BE68539007547034 ``` -------------------------------- ### Generate French (Switzerland) Financial IBAN Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md This PHP example shows how to generate an IBAN for Switzerland using Xefi Faker. It references the base method documentation for more details on options and formatting. ```php $faker->iban(countryCode: 'CH', format: 'See code') // CH6757112815366133814 ``` -------------------------------- ### Generate French (Switzerland) Color Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md These PHP examples demonstrate generating color names localized for Switzerland using Xefi Faker. It includes methods for generating 'safe' color names and general color names. ```php $faker->safeColorName(); // Noir ``` ```php $faker->colorName() // Blanc antique ``` -------------------------------- ### Generate French (Switzerland) Company Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md These PHP examples show how to generate company-related information localized for Switzerland using Xefi Faker. This includes company names, company numbers, and VAT numbers. ```php $faker->company(); // Nestlé Suisse SA ``` ```php $faker->companyNumber(); // CHE-380.842.438 ``` ```php $faker->vat(); // CHE-380.842.438 TVA ``` -------------------------------- ### Generate French (Switzerland) AVS Number Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md This PHP example shows how to generate an AVS number localized for Switzerland using Xefi Faker. It includes an option to format the output, with a note on the standard format. ```php // Formated: "756.xxxx.xxxx.xx" $faker->avs(formated: false) // 7564038982068 ``` -------------------------------- ### Generate French (Belgium) Person Data with Faker Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md These PHP examples cover generating personal information such as full name, first name, and last name, with options for specifying gender. The RRN (Belgian National Number) generation is also included, with formatting options. ```php // Gender: null(both), "M" (male) or "F" (female) $faker->name(gender: 'F') // Isabelle Dupont ``` ```php // Gender: null(both), "M" (male) or "F" (female) $faker->firstName(gender: 'F') // Isabelle ``` ```php $faker->lastName() // Dupont ``` ```php // Gender: null(both), "M" (male) or "F" (female) // Formated: "xxxx-xxxx-xx" $faker->rrn(gender: 'M', formated: true) // 12 34 56 7890 12 ``` -------------------------------- ### Generate French (Belgium) Text with Faker Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md These PHP examples demonstrate generating various lengths of text content using Xefi Faker. You can generate specific numbers of words, sentences, or paragraphs tailored to French Belgian context. ```php $faker->words(words: 3); // gestion des ressources humaines ``` ```php $faker->sentences(sentences: 3); // Chaque projet nécessite une attention particulière pour garantir la réussite en Belgique... ``` ```php $faker->paragraphs(paragraphs: 3); // La qualité des services reste un objectif central pour les entreprises belges... ``` -------------------------------- ### Generate French (Switzerland) Text Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md These PHP examples demonstrate generating text content localized for Switzerland using Xefi Faker. You can generate random words, sentences, or paragraphs, with options to specify the quantity. ```php $faker->words(words: 3); // communication productivité proposés ``` ```php $faker->sentences(sentences: 3); // Des indicateurs sont utilisés pour mesurer... ``` ```php $faker->paragraphs(paragraphs: 3); // Des indicateurs sont utilisés pour mesurer... ``` -------------------------------- ### Generate French (Switzerland) Person Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md These PHP examples demonstrate generating personal information localized for Switzerland using Xefi Faker. You can generate full names, first names, and last names, with options to specify gender. ```php // Gender: null(both), "M" (male) or "F" (female) $faker->name(gender: 'F') // Anna Steiner ``` ```php // Gender: null(both), "M" (male) or "F" (female) $faker->firstName(gender: 'F') // Anna ``` ```php $faker->lastName() // Steiner ``` -------------------------------- ### Build Nuxt Application for Production Source: https://github.com/xefi/faker-doc/blob/main/README.md Builds the Nuxt application for production deployment. This command optimizes the application for performance and size. ```bash # npm npm run build # pnpm pnpm run build # yarn yarn build # bun bun run build ``` -------------------------------- ### Generate French (Switzerland) Address Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-ch.md These PHP examples show how to generate various address components localized for Switzerland using the Xefi Faker library. These include regions, provinces (cantons), cities, post codes, house numbers, street names, and full addresses. ```php $faker->region(); // Suisse romande ``` ```php $faker->province(); // Valais ``` ```php $faker->city(); // Genève ``` ```php $faker->postCode(); // 2805 ``` ```php $faker->houseNumber(); // 181 ``` ```php $faker->streetName(); // Route du Marché ``` ```php $faker->streetAddress(); // Route du Marché 181 ``` ```php $faker->fullAddress(); // Route du Marché 181, 2805 Genève ``` -------------------------------- ### Generate Indian IBAN (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-in.md Generates an Indian International Bank Account Number (IBAN). The example shows specifying the country code 'IN' and a format string. Refer to the base method documentation for format details. ```php $faker->iban(countryCode: 'IN', format: 'See code') // IN28CU9011517189912178556470 ``` -------------------------------- ### Preview Nuxt Production Build Locally Source: https://github.com/xefi/faker-doc/blob/main/README.md Locally previews the production build of the Nuxt application. This command is useful for testing the production version before deploying. ```bash # npm npm run preview # pnpm pnpm run preview # yarn yarn preview # bun bun run preview ``` -------------------------------- ### Generate French (Belgium) Address Data with Faker Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md These PHP examples show how to generate various address components specific to Belgium using the initialized Xefi Faker object. Methods include generating provinces, regions, cities, postal codes, house numbers, street names, and full addresses. ```php $faker->province(); // Hainaut ``` ```php $faker->region(); // Wallonie ``` ```php $faker->city(); // Bruxelles ``` ```php $faker->postCode(); // 5600 ``` ```php $faker->houseNumber(); // 257 ``` ```php $faker->streetName(); // Avenue de la Gare ``` ```php $faker->streetAddress(); // 257 Avenue de la Gare ``` ```php $faker->fullAddress(); // 257 Avenue de la Gare, 5600 Bruxelles ``` -------------------------------- ### Define Faker Service Provider in PHP Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/4.package-development.md This PHP code defines a service provider for Faker, extending the base 'Provider' class. The `boot` method is used to register custom extensions, such as 'NumberExtension', allowing for custom data generation methods within Faker. ```php namespace Xefi\FakerNumber;\n\nuse Xefi\Faker\Providers\Provider;\n\nclass NumberServiceProvider extends Provider\n{\n public function boot(): void\n {\n $this->extensions([\n NumberExtension::class,\n ]);\n }\n} ``` -------------------------------- ### Create a Custom Faker Extension in PHP Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/4.package-development.md This PHP code demonstrates how to create a custom Faker extension by extending the base 'Extension' class. It defines a public method `returnNumberBetween` which generates a random integer within a specified range, making it available for use in Faker data generation. ```php namespace Xefi\Faker\Tests\Support\Extensions;\n\nuse Xefi\Faker\Extensions\Extension;\n\nclass NumberTestExtension extends Extension\n{\n public function returnNumberBetween(int $min, int $max): int\n {\n return rand($min, $max);\n }\n} ``` -------------------------------- ### Configure Nuxt for Nuxt Studio Source: https://github.com/xefi/faker-doc/blob/main/README.md Configures the Nuxt application to use the Nuxt Studio module by adding it to the `modules` array in `nuxt.config.ts`. This enables Nuxt Studio features. ```typescript export default defineNuxtConfig({ ... modules: [ ... '@nuxthq/studio' ] }) ``` -------------------------------- ### Generate Image URL with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/images.md This PHP code snippet shows how to generate a URL for a placeholder image using the Xefi Faker library. The dimensions of the image can be specified as parameters. ```php $faker->imageUrl(width: 1280, height: 720); // https://placehold.co/1280x720 ``` -------------------------------- ### Initialize Xefi Faker with Pakistan Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-pk.md Initializes the Xefi Faker instance with the 'en_PK' locale. This ensures that the generated data conforms to Pakistani standards. ```php $faker = new Xefi\Faker\Faker('en_PK'); ``` -------------------------------- ### Set Faker Locale Globally Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/2.usage.md This PHP code shows how to instantiate the Faker library with a specific locale ('fr_FR') applied globally. Subsequent calls to methods like `name()` will use data corresponding to the specified locale. ```php use Xefi\Faker\Faker; $faker = new Faker('fr_FR'); $faker->name() // Marie Durand $faker->name() // Pierre Dupont ``` -------------------------------- ### Create Custom PHP Faker Extension Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/7.custom-extension.md Defines a custom Faker extension in PHP by extending the Xefi\Faker\Extensions\Extension class and implementing a custom method to generate emails. ```php use Xefi\Faker\Extensions\Extension; class CustomEmailExtension extends Extension { public function generateRandomEmail(string $domainName): mixed { $localPart = strtolower(bin2hex(random_bytes(4))); return $localPart . '@' . $domainName; } } ``` -------------------------------- ### Regex Strategy - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/5.strategies.md Validates generated data against a provided regular expression. Useful for ensuring data conforms to specific patterns like postal codes or email domains. ```php use Xefi\Faker\Faker; $faker = new Faker(); $faker->regex('/^01$/')->postalCode(); // Postal code that begins with '01' $faker->regex('/.com$/')->email(); // Email that ends with '.com' ``` -------------------------------- ### Unique Strategy - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/5.strategies.md Ensures generated data is unique. Throws an error if the same unique value is requested too many times. Supports seeding for multiple independent unique generators. ```php use Xefi\Faker\Faker; $faker = new Faker(); $faker->unique()->numberBetween(1, 2); // 1 $faker->unique()->numberBetween(1, 2); // 2 $faker->unique()->numberBetween(1, 2); // Error too many tries ``` ```php use Xefi\Faker\Faker; $faker = new Faker(); $faker->unique('my-seed')->numberBetween(1, 2); // 1 $faker->unique('my-seed')->numberBetween(1, 2); // 2 $faker->unique('my-other-seed')->numberBetween(1, 2); // 1 ``` -------------------------------- ### Implement Multi-Locale Faker Extension in PHP Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/4.package-development.md This PHP code shows how to create a Faker extension that supports multiple locales using the 'HasLocale' trait. It defines the `getLocale` method to specify the locale, ensuring the extension is correctly associated with translated data. ```php namespace Xefi\FakerNumber\Extensions;\n\nuse Xefi\Faker\Extensions\Extension;\nuse Xefi\Faker\Extensions\Traits\HasLocale;\n\nclass NameExtension extends Extension\n{\n use HasLocale;\n\n public function getLocale(): string\n {\n return 'fr_FR';\n }\n} ``` -------------------------------- ### Generate Color Data using Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Generates color names using the Xefi Faker PHP en_GB locale. It includes methods for both safe color names and general color names. ```php $faker->safeColorName(); // Lime ``` ```php $faker->colorName() // DarkCyan ``` -------------------------------- ### Register Custom PHP Faker Extension Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/7.custom-extension.md Registers a custom extension class with Xefi Faker using the faker() helper function and the resolveExtensions method. ```php faker()->resolveExtensions([CustomEmailExtension::class]) ``` -------------------------------- ### Use Faker in Symfony DataFixtures Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/3.integrations.md Shows how to inject and use the Faker service within Symfony's Doctrine DataFixtures to populate entities with fake data. Requires the faker-php-symfony package. ```php namespace App\DataFixtures; use App\Entity\User; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager; use Xefi\Faker\Faker; class AppFixtures extends Fixture { public function __construct(private Faker $faker) {} public function load(ObjectManager $manager): void { $user = new User(); $user->setName($this->faker->name()) ->setEmail($this->faker->email()); $manager->persist($user); $manager->flush(); } } ``` -------------------------------- ### Generate Words with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/text.md Generates a specified number of words using the Xefi Faker PHP library. This function is useful for creating placeholder text or sample data. ```php $faker->words(words: 3); ``` -------------------------------- ### Generate Sentences with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/text.md Generates a specified number of sentences using the Xefi Faker PHP library. This is helpful for creating realistic-looking text content for testing or demonstration purposes. ```php $faker->sentences(sentences: 3); ``` -------------------------------- ### Generate Text Data using Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Generates various forms of text content, including words, sentences, and paragraphs, using the Xefi Faker PHP en_GB locale. The number of words, sentences, or paragraphs can be specified as arguments. ```php $faker->words(words: 3); // Innovation drives progress ``` ```php $faker->sentences(sentences: 3); // The use of technology enables teams to work smarter and ... ``` ```php $faker->paragraphs(paragraphs: 3); // Monitoring progress helps identify opportunities for growth and ... ``` -------------------------------- ### Generate Color Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-us.md These PHP methods generate color names. `safeColorName()` provides a basic set of colors, while `colorName()` generates a broader range of color names. ```php $faker->safeColorName(); // Black ``` ```php $faker->colorName() // DarkKhaki ``` -------------------------------- ### Specify Custom Name for Faker Extension in PHP Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/4.package-development.md This PHP code illustrates how to provide a custom name for a Faker extension, particularly useful when the extension's class name doesn't clearly indicate its purpose or when overriding default naming conventions. The `getName` method returns the custom identifier, and `getLocale` specifies its associated language. ```php namespace Xefi\FakerNumber\Extensions;\n\nuse Xefi\Faker\Extensions\Extension;\nuse Xefi\Faker\Extensions\Traits\HasLocale;\n\nclass NameExtension extends Extension\n{\n use HasLocale;\n\n public function getName(): string\n {\n return 'my-extension-name';\n }\n\n public function getLocale(): string\n {\n return 'fr_FR';\n }\n} ``` -------------------------------- ### Generate Currency Data with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/currencies.md The `currency()` method generates an array containing the code, name, and symbol of a currency. This is useful for obtaining complete currency information. ```php $faker->currency(); // [ // [code] => "KRW", // [name] => "South Korean Won", // [symbol] => "₩" // ] ``` -------------------------------- ### Generate Random Number Between Two Values Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/2.usage.md This PHP code snippet demonstrates how to create a Faker instance and generate a random integer within a specified range (1 to 10). The same instance can be called multiple times to produce different results. ```php use Xefi\Faker\Faker; $faker = new Faker; echo $faker->numberBetween(1, 10); ``` ```php use Xefi\Faker\Faker; $faker = new Faker; for ($i = 0; $i < 3; $i++) { echo $faker->numberBetween(1, 10); } ``` -------------------------------- ### Generate Company Data using Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Generates company-related information using the Xefi Faker PHP en_GB locale. This includes company name, VAT number, and company registration number. ```php $faker->company(); // MediCore Diagnostics ``` ```php $faker->vatNumber(); // GB783920473 ``` ```php $faker->companyRegistrationNumber(); // KH839263 ``` -------------------------------- ### Set Faker Locale for a Single Execution Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/2.usage.md This PHP code demonstrates how to set the locale for a single execution of a Faker method. The `locale()` method is chained before the desired method call, and subsequent calls on the same instance will revert to the default locale if not explicitly changed. ```php use Xefi\Faker\Faker; $faker = new Faker(); $faker->locale('fr_FR')->name() // Marie Durand $faker->name() // John Doe (no locale) ``` -------------------------------- ### Generate Address Data using Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Generates various address components using the Xefi Faker PHP en_GB locale. This includes department, region, city, street name, street address, house number, post code, and full address. ```php $faker->department(); // ['SCT' => 'Banffshire'] ``` ```php $faker->region(); // England ``` ```php $faker->city(); // Cardiff ``` ```php $faker->streetName(); // Southfield Drive ``` ```php $faker->streetAddress(); // 104 Southfield Drive ``` ```php $faker->houseNumber(); // 104 ``` ```php $faker->postCode(); // LD40 2QH ``` ```php $faker->fullAddress(); // 194 The Crescent, Coventry, Carmarthenshire, FI51 9FG ``` -------------------------------- ### Generate Fake IBAN with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/financial.md Demonstrates how to generate a fake IBAN using the Xefi Faker PHP library. The `iban` method accepts optional `countryCode` and `format` parameters to customize the output. Without arguments, it generates a default IBAN. ```php $faker->iban(countryCode: null, format: null); // PX41711762752955497163783543 ``` -------------------------------- ### Generate Person Name Data using Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-gb.md Generates person names, including first names and last names, using the Xefi Faker PHP en_GB locale. The gender can be specified as null (both), 'M' (male), or 'F' (female) for name and firstName methods. ```php // Gender: null(both), "M" (male) or "F" (female) $faker->name(gender: 'F') // Joseph Edwards ``` ```php // Gender: null(both), "M" (male) or "F" (female) $faker->firstName(gender: 'F') // Lily ``` ```php $faker->lastName() // King ``` -------------------------------- ### Initialize Xefi Faker with French (Belgium) Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/fr-be.md This PHP code snippet demonstrates how to initialize the Xefi Faker generator with the 'fr_BE' locale. This is a prerequisite for using any of the French Belgian specific faker methods. ```php $faker = new Xefi\Faker\Faker('fr_BE'); ``` -------------------------------- ### Generate Pakistani Person Names Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-pk.md Generates full names, first names, and last names, with options to specify gender for first names. This is useful for creating realistic person data. ```php // Gender: null (both), "M" (male) or "F" (female) $faker->name(gender: 'M'); // Ahmed Khan ``` ```php $faker->firstName(gender: 'F'); // Ayesha ``` ```php $faker->lastName(); // Butt ``` -------------------------------- ### Initialize Xefi Faker with Spanish Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/es-es.md Initializes the Xefi Faker instance with the 'es_ES' locale. This ensures that generated data conforms to Spanish standards. ```php $faker = new Xefi\Faker\Faker('es_ES'); ``` -------------------------------- ### Configure Faker Locale in Symfony Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/3.integrations.md Configures the locale for Xefi Faker PHP within a Symfony application by creating a YAML configuration file. This allows for locale-specific data generation. ```yaml xefi_faker_symfony: locale: fr_FR ``` -------------------------------- ### Generate Pakistani Text Content Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-pk.md Generates textual content in the form of words, sentences, and paragraphs, allowing for customization of the quantity of each element. ```php $faker->words(words: 3); // Unity Faith Discipline ``` ```php $faker->sentences(sentences: 3); // The economy of Pakistan is rapidly growing... ``` ```php $faker->paragraphs(paragraphs: 3); // Pakistan has a rich cultural heritage... ``` -------------------------------- ### Generate Person Last Name (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/person.md Generates a person's last name using the Xefi Faker library. This function does not accept any parameters and directly returns a string representing the last name. ```php $faker->lastName(); // Doe ``` -------------------------------- ### Generate Currency Symbol with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/currencies.md The `currencySymbol()` method returns a string representing the symbol of a currency, such as '₩'. ```php $faker->currencySymbol() // ₩ ``` -------------------------------- ### Generate Person Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-us.md These PHP methods generate personal data such as full names, first names, and last names. The `name()` and `firstName()` methods accept an optional gender parameter ('M' for male, 'F' for female, or null for both). ```php $faker->name(gender: 'F') // Nicholas Wilson ``` ```php $faker->firstName(gender: 'F') // Betty ``` ```php $faker->lastName() // Anderson ``` -------------------------------- ### Convert Characters - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/strings.md Converts a pattern string into a more complex string based on predefined character replacements using Xefi Faker. '#' represents a digit, '?' represents a letter, and '*' represents any character. It returns the converted string. ```php $faker->convertCharacters(string: '#?**'); // 7jm2 ``` -------------------------------- ### Generate Color Names (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-in.md Generates a safe color name and a general color name using the Faker instance. These methods provide random color names relevant to the configured locale. ```php $faker->safeColorName(); // Teal ``` ```php $faker->colorName() // CharcoalGray ``` -------------------------------- ### Generate Semver - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/strings.md Generates a random semantic versioning (Semver) string using the Xefi Faker library. It adheres to the standard Semver format (MAJOR.MINOR.PATCH) and is useful for generating version numbers for software projects. ```php $faker->semver(); // 2.80.93 ``` -------------------------------- ### Generate Text Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-us.md These PHP methods generate various forms of text data: `words()` generates a specified number of words, `sentences()` generates a specified number of sentences, and `paragraphs()` generates a specified number of paragraphs. ```php $faker->words(words: 3); // professional development enpowers ``` ```php $faker->sentences(sentences: 3); // Data analysis provides insights into performance ... ``` ```php $faker->paragraphs(paragraphs: 3); // Goals are adjusted to align with shifting ... ``` -------------------------------- ### Generate Company Information (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-in.md Generates a company name and a Goods and Services Tax Identification Number (GSTIN) for India. These are useful for creating realistic company data. ```php $faker->company(); // Godrej Group ``` ```php $faker->gstin(); // 12OCKPK3802V6Z2 ``` -------------------------------- ### Generate German Person Names Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/de-de.md Generates person names, including full names, first names, and last names, with options to specify gender. The gender parameter accepts 'M' for male, 'F' for female, or null for either. ```php // Gender: null(both), "M" (male) or "F" (female) $faker->name(gender: 'F') // Jan Zimmermann ``` ```php // Gender: null(both), "M" (male) or "F" (female) $faker->firstName(gender: 'F') // Jana ``` ```php $faker->lastName() // Klein ``` -------------------------------- ### Generate Paragraphs with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/text.md Generates a specified number of paragraphs using the Xefi Faker PHP library. This function is ideal for producing larger blocks of sample text. ```php $faker->paragraphs(paragraphs: 3); ``` -------------------------------- ### Generate Person Names (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-in.md Generates full names, first names, and last names for individuals. The 'name' and 'firstName' methods accept an optional gender parameter ('M' for male, 'F' for female, or null for both) to influence the generated name. ```php // Gender: null(both), "M" (male) or "F" (female) $faker->name(gender: 'F') // Suhana Tiwari ``` ```php // Gender: null(both), "M" (male) or "F" (female) $faker->firstName(gender: 'F') // Suhana ``` ```php $faker->lastName() // Tiwari ``` -------------------------------- ### Generate Currency Code with Xefi Faker PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/currencies.md The `currencyCode()` method returns a string representing the ISO 4217 currency code, such as 'KRW'. ```php $faker->currencyCode() // KRW ``` -------------------------------- ### Generate Pakistani Address Data Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-pk.md Generates various components of a Pakistani address, including province, province code, city, sector block, street name, street address, postal code, and a full address. ```php $faker->province(); // Punjab ``` ```php $faker->provinceCode(); // SD ``` ```php $faker->city(); // Karachi ``` ```php $faker->sectorBlock(); // F-11 ``` ```php $faker->streetName(); // Iqbal Road ``` ```php $faker->streetAddress(); // G-7 Kashmir Avenue ``` ```php $faker->postalCode(); // 44000 ``` ```php $faker->fullAddress(); // G-11 Shahrah-e-Pakistan Street, Islamabad ICT ``` -------------------------------- ### Generate HSL Color as Array - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/colors.md Generates an HSL (Hue, Saturation, Lightness) color and returns it as an array of three integers. This method is part of the Colors extension for Xefi Faker PHP. ```php $faker->hslColorAsArray() // [112, 89, 17] ``` -------------------------------- ### Generate RGB Color as Array - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/colors.md Generates an RGB color and returns it as an array of three integers, each representing a color channel (Red, Green, Blue). This method is part of the Colors extension for Xefi Faker PHP. ```php $faker->rgbColorAsArray() // [160, 17, 93] ``` -------------------------------- ### Generate Spanish Color Names Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/es-es.md Generates Spanish color names. Includes both safe color names and general color names. ```php $faker->safeColorName(); // Azul ``` ```php $faker->colorName() // BlancoFloral ``` -------------------------------- ### Generate Pakistani Color Names Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/en-pk.md Generates both safe and general color names that are commonly used or recognized. ```php $faker->safeColorName(); // Lime ``` ```php $faker->colorName(); // Saffron ``` -------------------------------- ### Initialize Xefi Faker with German Locale Source: https://github.com/xefi/faker-doc/blob/main/content/3.locales/de-de.md Initializes the Xefi Faker generator instance with the 'de_DE' locale. This step is crucial for ensuring that the faker instance produces data according to German conventions. ```php $faker = new Xefi\Faker\Faker('de_DE'); ``` -------------------------------- ### Generate Person First Name with Gender Option (PHP) Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/person.md Generates a person's first name using the Xefi Faker library. Similar to the name generator, the 'gender' parameter accepts 'M', 'F', or null for randomization. The output is a string representing the first name. ```php $faker->firstName(gender: null); // John ``` -------------------------------- ### Generate Nullable Data with Faker Source: https://github.com/xefi/faker-doc/blob/main/content/1.getting-started/6.modifiers.md The nullable modifier allows data to be null with a 50% probability by default. You can also specify a weight (0-100) to control the exact percentage chance of null. ```php use Xefi\Faker\Faker; $faker = new Faker(); $faker->nullable()->helloWorld(1, 2); // "Hello World" or null ``` ```php use Xefi\Faker\Faker; $faker = new Faker(); $faker->nullable(0)->helloWorld(1, 2); // "Hello World" $faker->nullable(100)->helloWorld(1, 2); // null ``` -------------------------------- ### Generate HSL Color - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/colors.md Generates an HSL (Hue, Saturation, Lightness) color and returns it as a string of three comma-separated integers. This method is part of the Colors extension for Xefi Faker PHP. ```php $faker->hslColor() // 242,28,24 ``` -------------------------------- ### Generate RGBA Color as Array - PHP Source: https://github.com/xefi/faker-doc/blob/main/content/2.extensions/colors.md Generates an RGBA color and returns it as an array of four numbers: three for RGB channels and one for the alpha (transparency) channel. This method is part of the Colors extension for Xefi Faker PHP. ```php $faker->rgbaColorAsArray() // [49, 61, 231, 0.31] ```