From 46dc49ec266475edfa0427f3c03c2d6a8d211578 Mon Sep 17 00:00:00 2001 From: George Borges Date: Mon, 26 Jan 2015 23:34:27 +1100 Subject: [PATCH] Adding placeholders explanation to README --- README.md | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a654b3..33165a7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ THE ICONIC Database Fixtures ======== -[![Build Status](https://travis-ci.org/theiconic/fixtures.png?branch=v1.2.7)](https://travis-ci.org/theiconic/fixtures) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/fixtures/badges/quality-score.png?s=334ddfb53b2b286b443ff745b4458d61d9a1ac15)](https://scrutinizer-ci.com/g/theiconic/fixtures/) [![Coverage Status](https://coveralls.io/repos/theiconic/fixtures/badge.png?branch=master)](https://coveralls.io/r/theiconic/fixtures?branch=master) [![Latest Stable Version](https://poser.pugx.org/theiconic/fixtures/v/stable.png)](https://packagist.org/packages/theiconic/fixtures) [![License](https://poser.pugx.org/theiconic/fixtures/license.png)](https://packagist.org/packages/theiconic/fixtures) +[![Build Status](https://travis-ci.org/theiconic/fixtures.png?branch=v1.3)](https://travis-ci.org/theiconic/fixtures) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/fixtures/badges/quality-score.png?s=334ddfb53b2b286b443ff745b4458d61d9a1ac15)](https://scrutinizer-ci.com/g/theiconic/fixtures/) [![Coverage Status](https://coveralls.io/repos/theiconic/fixtures/badge.png?branch=master)](https://coveralls.io/r/theiconic/fixtures?branch=master) [![Latest Stable Version](https://poser.pugx.org/theiconic/fixtures/v/stable.png)](https://packagist.org/packages/theiconic/fixtures) [![License](https://poser.pugx.org/theiconic/fixtures/license.png)](https://packagist.org/packages/theiconic/fixtures) ## Description @@ -14,6 +14,8 @@ And it currently supports the following databases: * MySQL +The fixture manager also allows you to replace placeholders in your fixtures programatically. See examples below. + ## Usage Suppose that you have two fixtures for your country and employee tables called country.xml and employee.yml, respectively. You load them into a MySQL database with a few lines of code: @@ -50,6 +52,40 @@ $fixtureManager ->persist(); ``` +In the values for your fixtures files, you can put placeholders for the values. This allows you to change the values dynamically, such as, place the current date. + +To do this, when creating the Fixture Manager pass an array with the keys in the form "fx:placeholder:". For example: + +```php +use TheIconic\Fixtures\FixtureManager\FixtureManager; + +// Declare an array with the path to your fixtures +$fixtures = ['./fixtures/employee.yml']; + +// Create a new Fixture Manager passing such array +$fixtureManager = FixtureManager::create($fixtures, ['fx:placeholder:age' => 33]); + +``` + +And the employee.xml file would be (notice the value of "age" field): + +```xml + + + + + + 1 + John Smith + fx:placeholder:age + + + + +``` + +You can pass any value you want, just calculate it before passing it to the create static method. + ## Installation Use Composer to install this package. @@ -57,7 +93,7 @@ Use Composer to install this package. ```json { "require": { - "theiconic/fixtures": "~1.2" + "theiconic/fixtures": "~1.3" } } ```