/** * This method returns the data in the model's format and will handle the transformation * if necessary. * * @access public * @return \Unicity\MappingService\Data\Field the data in the model's format */ public function toModelFormat() { $field = new MappingService\Data\Field(MappingService\Data\FormatType::model(), $this->field); $field->setInfo($this->field->getInfo()); return $field; }
/** * This method attempts to call a getter. * * @access protected * @param string $scope the scope of the getter * @param string $field the name of the field * @return \Unicity\MappingService\Data\Field the aggregated field data * @throws \Unicity\Throwable\Parse\Exception indicates that there is a parsing * problem */ protected function __getter($scope, $field) { $nodes = $this->resource->xpath("/translators/translator[@name='{$this->name}']/fields/field[@name='{$field}' and @scope='{$scope}']"); if (count($nodes) > 0) { $attributes = $nodes[0]->attributes(); $aggregated_field = new MappingService\Data\Field(MappingService\Data\FormatType::model()); $items = $nodes->children(); foreach ($items as $item) { $attributes = $item->attributes(); if (!isset($attributes['name'])) { throw new Throwable\Parse\Exception('Unable to parse ":scope" method in translator.', array(':scope' => $scope)); } $name = $this->__valueOf($attributes['name']); if (isset($attributes['location'])) { $segments = explode('.', $this->__valueOf($attributes['location'])); if (count($segments) > 0) { $property = $this->models; foreach ($segments as $segment) { $property = $property->{$segment}; } $aggregated_field->putItem($name, $property); } } } if (isset($attributes['translation'])) { $translation = $this->__valueOf($attributes['translation']); return $translation::factory($aggregated_field)->toCanonicalFormat(); } return $aggregated_field; } }