From 54e24a4cc4100898c9c333f21b733ed2b2efff84 Mon Sep 17 00:00:00 2001 From: ixarlie Date: Wed, 14 Oct 2015 20:59:56 +0200 Subject: [PATCH] add namespace configuration --- src/Codesleeve/Fixture/Drivers/DriverInterface.php | 3 ++- src/Codesleeve/Fixture/Drivers/Eloquent.php | 8 +++++++- src/Codesleeve/Fixture/Drivers/Standard.php | 3 ++- src/Codesleeve/Fixture/Fixture.php | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Codesleeve/Fixture/Drivers/DriverInterface.php b/src/Codesleeve/Fixture/Drivers/DriverInterface.php index 6a5bdf4..53ca6fd 100644 --- a/src/Codesleeve/Fixture/Drivers/DriverInterface.php +++ b/src/Codesleeve/Fixture/Drivers/DriverInterface.php @@ -8,9 +8,10 @@ interface DriverInterface * * @param string $tableName * @param array $records + * @param array $config * @return array */ - public function buildRecords($tableName, array $records); + public function buildRecords($tableName, array $records, array $config); /** * Truncate a table. diff --git a/src/Codesleeve/Fixture/Drivers/Eloquent.php b/src/Codesleeve/Fixture/Drivers/Eloquent.php index 5a91bc2..f56369d 100644 --- a/src/Codesleeve/Fixture/Drivers/Eloquent.php +++ b/src/Codesleeve/Fixture/Drivers/Eloquent.php @@ -47,15 +47,21 @@ public function __construct(PDO $db, Str $str) * * @param string $tableName * @param array $records + * @param array $config * @return array */ - public function buildRecords($tableName, array $records) + public function buildRecords($tableName, array $records, array $config) { $insertedRecords = array(); $this->tables[$tableName] = $tableName; foreach ($records as $recordName => $recordValues) { $model = $this->generateModelName($tableName); + + // Prefix namespace if comes from configuration. + if (isset($config['namespace'])) { + $model = sprintf('%s\%s', $config['namespace'], $model); + } $record = new $model; foreach ($recordValues as $columnName => $columnValue) { diff --git a/src/Codesleeve/Fixture/Drivers/Standard.php b/src/Codesleeve/Fixture/Drivers/Standard.php index c8eeb46..1f78603 100644 --- a/src/Codesleeve/Fixture/Drivers/Standard.php +++ b/src/Codesleeve/Fixture/Drivers/Standard.php @@ -33,9 +33,10 @@ public function __construct(PDO $db) * * @param string $tableName * @param array $records + * @param array $config * @return array */ - public function buildRecords($tableName, array $records) + public function buildRecords($tableName, array $records, array $config) { $insertedRecords = array(); $this->tables[$tableName] = $tableName; diff --git a/src/Codesleeve/Fixture/Fixture.php b/src/Codesleeve/Fixture/Fixture.php index a3141cb..4a23560 100644 --- a/src/Codesleeve/Fixture/Fixture.php +++ b/src/Codesleeve/Fixture/Fixture.php @@ -313,6 +313,6 @@ protected function loadFixture($fixture) } - $this->fixtures[$tableName] = $this->driver->buildRecords($tableName, $records); + $this->fixtures[$tableName] = $this->driver->buildRecords($tableName, $records, $this->config); } }