amyavari / persian-faker-php
This is an extension for fakerphp/faker to support Persian language
Requires
- php: ^8.2.0
Requires (Dev)
- laravel/pint: ^1.18.1
- mockery/mockery: ^1.6
- phpstan/phpstan: ^1.12.7
- phpunit/phpunit: ^11.5
- rector/rector: ^1.2.8
- symfony/var-dumper: ^7.1.6
README
persian-faker-php
is an extension for fakerphp/faker that generates Persian-language and Iran-specific data, such as Persian text, addresses, personal details, and more.
To view the Persian documentation, please refer to docs/fa/01_getting_started.md.
این کتابخانه بر پایه کتابخانه fakerphp/faker ساخته شده و هدف آن پشتیبانی از متن و مشخصات فارسی بهطور خاص برای اطلاعات کشور ایران است.
برای مشاهده راهنمای فارسی، لطفاً به فایل docs/fa/01_getting_started.md مراجعه کنید.
Requirements
- PHP version
8.2.0
or higher
Installation
To install the package, use Composer.
composer require --dev amyavari/persian-faker-php
Note: This package is intended for use in a development environment, so it's recommended to install it with the --dev
flag.
Usage
You can easily create an instance of Faker in your PHP projects by calling the create()
method from the Factory
class
$persianFaker = \AliYavari\PersianFaker\Factory::create();
Usage Helper
If you prefer a simpler way to get a Persian Faker instance, you can use the global persian_faker()
helper function provided by this package. This is especially useful in Laravel or any PHP project where global helpers are available.
$persianFaker = persian_faker();
This helper will automatically resolve the Faker instance, using the Laravel service container if available, or falling back to a direct instantiation otherwise.
Available Methods
Most methods in persian-faker-php
are extensions of the fakerphp/faker library, supporting only Persian language and Iran-specific data. The implementation and arguments for these methods are the same as those in the original Faker library.
Person Details
To view the complete documentation for the person methods, please refer to docs/en/02-person.md
title($gender = null|'male'|'female') // 'آقای' titleMale() // 'آقای' titleFemale() // 'خانم' name($gender = null|'male'|'female') // 'علی محمد یاوری' firstName($gender = null|'male'|'female') // 'علی محمد' firstNameMale() // 'علی محمد' firstNameFemale() // 'نیوشا' lastName() // 'یاوری' // New method nationalCode($state = null) // '0087199084', '1127905589'
Address
To view the complete documentation for the address methods, please refer to docs/en/03-address.md
secondaryAddress() // 'طبقه 2' state() // 'یزد' city() // 'یزد' streetName() // 'پاسداران شمالی' address() // 'خیابان کارگر، کوچه گلستان، پلاک 35 // Modified: accept optional argument postcode($withSeparator = false|true) // '1234567890' , '12345-67890'
Phone
To view the complete documentation for the phone methods, please refer to docs/en/04-phone.md
// Modified: accept optional arguments phoneNumber($separator = '', $state = null) // '03512345678', '035-12345678' // New methods statePhonePrefix() // '035' cellPhone($separator = '', $provider = null) // '09121234567', '0912-123-4567'
Company
To view the complete documentation for the company methods, please refer to docs/en/05-company.md
company() // 'گروه نگاه' catchphrase() // 'یک قدم تا دنیای دیجیتال' jobTitle() // 'برنامه نویس PHP', 'مدیر محصول'
Text
To view the complete documentation for the text methods, please refer to docs/en/06-text.md
word() // 'آتش', 'خاکستری' words($nb = 3, $asText = false|true) // ['خاکستری', 'سریع' , 'دارچین'], 'خاکستری سریع دارچین' sentence($nbWords = 6, $variableNbWords = true|false) // '.نویس اتوبوس برنامه دار.', 'دیجیتال دنیا و بی یخ' sentences($nb = 3, $asText = false|true) // ['خاکستری سریع دارچین','.یخ در بهشت.'], 'خاکستری سریع دارچین. یخ در بهشت.' paragraph($nbSentences = 3, $variableNbSentences = true|false) // 'خاکستری سریع دارچین اما اینجا. یخ در بهشت بها. دیجیتال دنیا و بی یخ..' paragraphs($nb = 3, $asText = false|true) text($maxNbChars = 200) // 'ثانیه رنگ هفته ماه ملی پاییز انسان تنظیم تخممرغ بخار نهاد صعود بیعت تند تفکر توانا پناهگاه برنامه سکه برگ'
Payment
To view the complete documentation for the payment methods, please refer to docs/en/07-payment.md
// New methods bank() // 'ملت', 'مهر ایران' cardNumber($separator = '', $bank = null) // '6273 8157 2593 3210', '5894639748556308' shebaNumber($withIR = true|false, $separator = '', $bank = null) // 'IR72-0540-0008-5961-5112-7527-92'
Color
To view the complete documentation for the color methods, please refer to docs/en/08-color.md
safeColorName() // 'سیاه', 'آبی' colorName() // 'سبز زمردی', 'زغالی', 'زرد'
Contributing
Thank you for considering contributing to the Persian Faker PHP! The contribution guide can be found in the CONTRIBUTING.md
License
Persian Faker PHP was created by Ali Mohammad Yavari under the MIT license.
This package utilizes the nunomaduro/skeleton-php repository as a starting point and for configuration settings.