public function test_field_construction() { $resource = $this->buildFakeResource(); $field = new Field($resource, 'myCoolField', 'my_cool_field', Field::TYPE_DATE, 'd-M-Y'); $this->assertEquals($resource, $field->getResource()); $this->assertEquals('myCoolField', $field->getAlias()); $this->assertEquals('my_cool_field', $field->getName()); $this->assertEquals(Field::TYPE_DATE, $field->getType()); $this->assertEquals('d-M-Y', $field->getFormatString()); }
public function buildFieldFormatterForField(Field $field) { switch ($field->getType()) { case Field::TYPE_DATE: case Field::TYPE_DATETIME: $formatString = $field->getFormatString(); if ($formatString === null) { $formatString = $field->getType() === Field::TYPE_DATE ? DateTimeFieldFormatter::DEFAULT_DATE_FORMAT_STRING : DateTimeFieldFormatter::DEFAULT_DATETIME_FORMAT_STRING; } return new DateTimeFieldFormatter($formatString); break; case Field::TYPE_STRING: return new StringFieldFormatter(); case Field::TYPE_NUMBER: return new NumberFieldFormatter(); case Field::TYPE_BOOL: return new BoolFieldFormatter(); default: throw new \InvalidArgumentException(sprintf('unknown field type[%s], cannot create related formatter', $field->getType())); } }