/** * Set type of Data that is provided, default is a string * * @param string $type Type of Data that is provided, default is a string * * @return void */ protected function setType($type) { // Check if valid type if (!in_array($type, TypeEnum::getAll())) { throw new RuntimeException(sprintf('Invalid type "%s" provided for annotation "@%s", available types are %s', $type, get_class($this), '"' . join('", "', TypeEnum::getAll()) . '"')); } $this->type = $type; }
/** * Constructor * * Field names must be all lowercase, with optional underscore and seperated with a comma. * Fields can be global (no dot) or domain specific (with one(!) dot) * * @param string $field Field Name * @param string $type Field Type (As available in TypeEnum) */ public function __construct($field, $type) { // Test field input for valid input // Field names must be all lowercase, with optional underscore and seperated with a comma. // Fields can be global (no dot) or domain specific (with one(!) dot) if (preg_match('/^([a-z_]+)(\\.([a-z_]+))?$/', $field) == 0) { throw new RuntimeException(sprintf('Invalid field name "%s" provided for "%s", ' . 'field names must be all lowercase, with optional underscore and seperated with a comma, ' . 'fields can be global (no dot) or domain specific (with one(!) dot)', $field, get_class($this))); } if (!in_array($type, TypeEnum::getAll())) { throw new RuntimeException(sprintf('Invalid type "%s" provided for "@%s", available types are %s', $type, get_class($this), '"' . join('", "', TypeEnum::getAll()) . '"')); } $this->field = $field; $this->type = $type; }
/** * Get Data of given Type * * @param string $type Type (As available in TypeEnum) * * @return mixed Data */ public function getData($type) { if (!in_array($type, TypeEnum::getAll())) { throw new RuntimeException(sprintf('Invalid type "%s" provided for getData in "@%s", available types are %s', $type, get_class($this), '"' . join('", "', TypeEnum::getAll()) . '"')); } return array_key_exists($type, $this->data) ? $this->data[$type] : null; }