/** * Assign a type-casted value to the data object * * Fields of unknown types will not be added to the object. * * @param \stdClass $data * @param Column $column * @param mixed $value */ private function assignValue(\stdClass $data, Column $column, $value) { $field_name = $column->getName(); switch ($column->getType()) { default: break; case FieldType::DATETIME(): $data->{$field_name} = $this->serialiseDateTime($value); break; case FieldType::INT(): $data->{$field_name} = (int) $value; break; case FieldType::STRING(): $data->{$field_name} = (string) $value; break; case FieldType::DECIMAL(): $data->{$field_name} = (double) $value; break; case FieldType::BOOL(): $data->{$field_name} = (bool) $value; break; case FieldType::SET(): $data->{$field_name} = json_encode($value); break; case FieldType::OBJECT(): $data->{$field_name} = $this->serialiseObject($value); break; } }
/** * Parse a ColumnAnnotation and return a Column object * * @param ColumnAnnotation $column_annotation * @param string $name * @return Column */ private function parseColumnAnnotation(ColumnAnnotation $column_annotation, $name) { $column = new Column($name); /** @noinspection PhpParamsInspection */ $column->setType(FieldType::memberByValue($column_annotation->type)); $column->setName($column_annotation->name); $column->setGetter($column_annotation->getter); $column->setSetter($column_annotation->setter); $column->setClassName($column_annotation->class_name); return $column; }
/** * Create a column from schema * * @param string $property * @param array $column_schema * @return Column */ private function createColumn($property, array $column_schema) { $column = new Column($property); $column->setId($this->getNode($column_schema, Schema::COLUMN_ID, false, false)); $column->setGetter($this->getNode($column_schema, Schema::GETTER, false)); $column->setSetter($this->getNode($column_schema, Schema::SETTER, false)); $column->setClassName($this->getNode($column_schema, Schema::COLUMN_CLASS, false)); $column->setProperty($property); /** @var FieldType $type */ $type = FieldType::memberByValue($this->getNode($column_schema, Schema::COLUMN_TYPE, false, 'string')); $column->setType($type); return $column; }