metadata = $metadata; } protected function getMetadata() { return $this->metadata; } public function read($name, $scope) { return $this->getMetadata()->get($this->metadataType.'.'.$scope.'.fields.'.$name); } public function create($name, $fieldDef, $scope) { return $this->update($name, $fieldDef, $scope); } public function update($name, $fieldDef, $scope) { $defs = $this->normalizeDefs($name, $fieldDef); return $this->setEntityDefs($defs, $scope); } public function delete($name, $scope) { $unsets = 'fields.'.$name; return $this->getMetadata()->unsets($unsets, $this->metadataType, $scope); } /** * Add all needed block for a field defenition * * @param string $fieldName * @param array $fieldDef * @return array */ protected function normalizeDefs($fieldName, array $fieldDef) { return array( 'fields' => array( $fieldName => $fieldDef, ), ); } protected function setEntityDefs($defs, $scope) { $data = Json::encode($defs); $result = $this->getMetadata()->set($data, $this->metadataType, $scope); return $result; } }