public function formatFromFile(FieldSpec $spec, $value) { if (($paddingChar = $spec->getPaddingChar()) !== null) { if ($spec->getPaddingDirection() == FieldSpec::PADDING_DIRECTION_LEFT) { $value = ltrim($value, $paddingChar); } else { $value = rtrim($value, $paddingChar); } } $type = 'string'; if (isset($this->typeSpecifierMap[substr($spec->getFormatSpecifier(), -1)])) { $type = $this->typeSpecifierMap[substr($spec->getFormatSpecifier(), -1)]; } settype($value, $type); return $value; }
public function testGetters() { $default = $this->getFaker()->word; $formatSpecifier = $this->getFaker()->word; $name = $this->getFaker()->word; $slice = Slice::createFromString($this->getFaker()->numberBetween(0, 10) . ':' . $this->getFaker()->numberBetween(10, 20)); $paddingChar = $this->getFaker()->word; $paddingDirection = $this->getFaker()->word; $type = $this->getFaker()->word; $spec = new FieldSpec($name, $slice, $default, $formatSpecifier, $paddingChar, $paddingDirection, $type); $this->assertEquals($default, $spec->getDefault()); $this->assertEquals($formatSpecifier, $spec->getFormatSpecifier()); $this->assertEquals($name, $spec->getName()); $this->assertEquals($slice, $spec->getSlice()); $this->assertEquals($paddingChar, $spec->getPaddingChar()); $this->assertEquals($paddingDirection, $spec->getPaddingDirection()); $this->assertEquals($type, $spec->getType()); }
public function __construct($recordSpecName, FieldSpec $fieldSpec) { parent::__construct(sprintf('A value for %s in record %s is required.', $fieldSpec->getName(), $recordSpecName)); }