public function testCreatesNestedInstanceFromFlatArray() { $flatCollection = array('foo:bar:baz' => 1); $metadataDefinitionHelper = Phake::mock('Janus\\ServiceRegistry\\Connection\\Metadata\\MetadataDefinitionHelper'); Phake::when($metadataDefinitionHelper)->castData($flatCollection, 'saml20-idp')->thenReturn($flatCollection); $metaDataAssembler = new MetadataTreeBuilder(); $nestedMetadata = $metaDataAssembler->build($flatCollection, $metadataDefinitionHelper, 'saml20-idp'); $this->assertEquals(1, $nestedMetadata['foo']['bar']['baz']); }
/** * Save entity data * * @param array $metadataCollection * @throws Exception */ public function save(array $metadataCollection) { if (empty($this->_entityid) && empty($this->_eid)) { throw new Exception("Cannot save connection since neither an entityid nor an eid was set"); } $dto = new ConnectionDto(); $dto->id = $this->_eid; $dto->name = $this->_entityid; $dto->type = $this->_type; $dto->parentRevisionNr = $this->_revisionid; $dto->revisionNote = $this->_revisionnote; $dto->state = $this->_workflow; // Convert expiration date to datetime object $expirationDate = $this->_expiration; if (!is_null($expirationDate)) { $expirationDate = \DateTime::createFromFormat(DateTime::ATOM, $this->_expiration); } $dto->expirationDate = $expirationDate; $dto->metadataUrl = $this->_metadataurl; $dto->allowAllEntities = $this->_allowedall == 'yes'; $dto->arpAttributes = $this->_arpAttributes; $dto->manipulationCode = $this->_manipulation; $dto->isActive = $this->_active == 'yes'; $dto->notes = $this->_notes; // Build nested metadata collection $flatMetadataCollection = array(); /** @var $metadata Metadata */ foreach ($metadataCollection as $metadata) { $flatMetadataCollection[$metadata->getKey()] = $metadata->getValue(); } $metadataAssembler = new MetadataTreeBuilder(); $nestedMetadataCollection = $metadataAssembler->build($flatMetadataCollection, new MetadataDefinitionHelper($this->_config), $this->_type); $dto->metadata = $nestedMetadataCollection; $connection = $this->getConnectionService()->save($dto, true); $this->_eid = $connection->getId(); $this->currentRevision = $connection->getLatestRevision(); $this->_id = $this->currentRevision->getId(); $this->_revisionid = $this->currentRevision->getRevisionNr(); $this->_modified = false; }
/** * @param $metaDefinitionHelper * @param $dto */ private function toDtoMetadata($metaDefinitionHelper, $dto) { if (!$this->metadata instanceof PersistentCollection) { return; } $flatMetadata = array(); /** @var $metadataRecord \Janus\ServiceRegistry\Entity\Connection\Revision\Metadata */ foreach ($this->metadata as $metadataRecord) { $flatMetadata[$metadataRecord->getKey()] = $metadataRecord->getValue(); } if (!empty($flatMetadata)) { $metadataDtoAssembler = new MetadataTreeBuilder(); $metadataCollection = $metadataDtoAssembler->build($flatMetadata, $metaDefinitionHelper, $this->type); $dto->metadata = $metadataCollection; } }