Skip to content

Commit 3fd3797

Browse files
committed
Maps better, exceptions better, arrays work, tests
1 parent e2e47e4 commit 3fd3797

File tree

9 files changed

+510
-164
lines changed

9 files changed

+510
-164
lines changed

phpunit-debug.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
export XDEBUG_CONFIG=idekey=netbeans-xdebug
4+
exec phpunit "$@"
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rezonant\MapperBundle\Exceptions;
4+
5+
/**
6+
*
7+
*/
8+
class FabricationFailedException extends \Exception {
9+
public function __construct($message) {
10+
parent::__construct("Failed to fabricate instance: $message");
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Rezonant\MapperBundle\Exceptions;
4+
5+
class InvalidTypeException extends \Exception {
6+
public function __construct($type) {
7+
parent::__construct("Invalid type: $type");
8+
}
9+
}

src/Rezonant/MapperBundle/Map.php

+9
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ function getFields() {
1919
function setFields($fields) {
2020
$this->fields = $fields;
2121
}
22+
23+
public function getField($fieldName) {
24+
foreach ($this->fields as $field) {
25+
if ($field->field == $fieldName)
26+
return $field;
27+
}
28+
29+
return null;
30+
}
2231
}

src/Rezonant/MapperBundle/MapBuilder.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ class MapBuilder {
1111
* @param Map $map
1212
* @return MapBuilder
1313
*/
14-
public function field($sourceFieldName, $destinationFieldName, Map $map = NULL)
14+
public function field($sourceFieldName, $destinationFieldName, $destinationType = NULL, Map $map = NULL)
1515
{
16+
if (is_null($sourceFieldName))
17+
throw new \InvalidArgumentException('$sourceFieldName cannot be null');
18+
19+
if (is_null($destinationFieldName))
20+
throw new \InvalidArgumentException('$destinationFieldName cannot be null');
21+
1622
$mapField = new MapField($sourceFieldName);
1723
$mapField->setDestinationField($destinationFieldName);
24+
$mapField->setDestinationType($destinationType);
1825
$mapField->setSubmap($map);
1926
$this->fields[] = $mapField;
2027

src/Rezonant/MapperBundle/MapField.php

+9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ public function __construct($name)
1111

1212
private $name;
1313
private $destinationField;
14+
private $destinationType;
1415
private $submap;
1516

17+
function getDestinationType() {
18+
return $this->destinationType;
19+
}
20+
21+
function setDestinationType($destinationType) {
22+
$this->destinationType = $destinationType;
23+
}
24+
1625
function getSubmap() {
1726
return $this->submap;
1827
}

0 commit comments

Comments
 (0)