From 3b0e0bdd0f46058f7529da5c03441d7b9b7c5d54 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 3 Feb 2017 17:11:28 +0100 Subject: [PATCH] FEATURE: Add basic support for faker --- configs/typo3_downloads.yml | 3 +++ readme.rst | 8 ++++++++ src/Command/FakeMysqlCommand.php | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/configs/typo3_downloads.yml b/configs/typo3_downloads.yml index 0fdb558..3fd9c0c 100644 --- a/configs/typo3_downloads.yml +++ b/configs/typo3_downloads.yml @@ -17,3 +17,6 @@ data: type: userfunc class: DSiepmann\Userfunction\RepeatingFilenames method: filename + date: + type: faker + formatter: dateTime diff --git a/readme.rst b/readme.rst index df3dba3..5e99dc6 100644 --- a/readme.rst +++ b/readme.rst @@ -71,6 +71,14 @@ types are supported: class: DSiepmann\Userfunction\RepeatingFilenames method: filename +``faker`` + Uses a formatter defined by `faker`_. + + .. code:: yml + + date: + type: faker + formatter: dateTime .. _faker: https://github.com/fzaninotto/Faker .. _Doctrine DBAL: http://www.doctrine-project.org/projects/dbal.html diff --git a/src/Command/FakeMysqlCommand.php b/src/Command/FakeMysqlCommand.php index 24aa02d..d4c7968 100644 --- a/src/Command/FakeMysqlCommand.php +++ b/src/Command/FakeMysqlCommand.php @@ -121,6 +121,18 @@ class FakeMysqlCommand extends Command return $userfunction->$userMethod(); } + if ($config['type'] === 'faker') { + $formatterToUse = $config['formatter']; + + $fakerData = $this->faker->$formatterToUse(); + + if ($fakerData instanceof \DateTime) { + $fakerData = $fakerData->format('Y-m-d H:i:s'); + } + + return $fakerData; + } + throw new \Exception('Unkown configured value.', 1486135949); } }