Mongolid\Manager::getMapper PHP Method

getMapper() public method

Retrieves a DataMapper for the given $entityClass. This can only be done if the Schema for that entity has been previously registered with registerSchema() method.
public getMapper ( string $entityClass ) : DataMapper | null
$entityClass string Class of the entity that needs to be mapped.
return Mongolid\DataMapper\DataMapper | null DataMapper configured for the $entityClass.
    public function getMapper(string $entityClass)
    {
        if (isset($this->schemas[$entityClass])) {
            $dataMapper = Ioc::make(DataMapper::class);
            $dataMapper->setSchema($this->schemas[$entityClass] ?? null);
            return $dataMapper;
        }
    }

Usage Example

Exemplo n.º 1
0
 public function testShouldNotGetDataMapperForUnknownEntities()
 {
     // Arrange
     $manager = new Manager();
     // Assert
     $result = $manager->getMapper('Unknow');
     $this->assertNull($result);
 }