Skip to content

Commit

Permalink
Merge pull request #50 from ConductionNL/feature/REGISTERS-47/objects…
Browse files Browse the repository at this point in the history
…-mappen-open-reg

Making the mapping service ussable for other nextcloud applications
  • Loading branch information
WilcoLouwerse authored Nov 7, 2024
2 parents abe7cd4 + 791dc23 commit d40ed45
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions lib/Service/MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class MappingService
*/
public function __construct(
ArrayLoader $loader,
MappingMapper $mappingMapper
private readonly MappingMapper $mappingMapper
) {
$this->twig = new Environment($loader);
$this->twig->addExtension(new MappingExtension());
$this->twig->addRuntimeLoader(new MappingRuntimeLoader(mappingService: $this, mappingMapper: $mappingMapper));
$this->twig->addRuntimeLoader(new MappingRuntimeLoader(mappingService: $this, mappingMapper: $this->mappingMapper));

}//end __construct()

Expand Down Expand Up @@ -416,4 +416,41 @@ public function coordinateStringToArray(string $coordinates): array

}//end coordinateStringToArray()


/**
* Retrieves a single mapping by its ID.
*
* This is a wrapper function that provides controlled access to the mapping mapper.
* We use this wrapper pattern to ensure other Nextcloud apps can only interact with
* mappings through this service layer, rather than accessing the mapper directly.
* This maintains proper encapsulation and separation of concerns.
*
* @param string $mappingId The unique identifier of the mapping to retrieve
* @return Mapping The requested mapping entity
* @throws \OCP\AppFramework\Db\DoesNotExistException If mapping is not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException If multiple mappings found
*/
public function getMapping(string $mappingId): Mapping
{
// Forward the find request to the mapper while maintaining encapsulation
return $this->mappingMapper->find($mappingId);
}

/**
* Retrieves all available mappings.
*
* This is a wrapper function that provides controlled access to the mapping mapper.
* We use this wrapper pattern to ensure other Nextcloud apps can only interact with
* mappings through this service layer, rather than accessing the mapper directly.
* This maintains proper encapsulation and separation of concerns.
*
* @return array<Mapping> An array containing all mapping entities
*/
public function getMappings(): array
{
// Forward the findAll request to the mapper while maintaining encapsulation
// @todo: add filtering options
return $this->mappingMapper->findAll();
}

}

0 comments on commit d40ed45

Please sign in to comment.