3.1.1. Getting Started

3.1.1.1. Installation

This package is installable and autoloadable via Composer as atlas/orm. Add the following lines to your composer.json file, then call composer update.

{
    "require": {
        "atlas/orm": "~2.0"
    },
    "require-dev": {
        "atlas/cli": "~1.0"
    }
}

(The atlas/cli package provides the atlas-skeleton command-line tool to help create skeleton classes for the mapper.)

3.1.1.2. Creating Data Source Classes

You can create your data source classes by hand, but it's going to be tedious to do so. Instead, use the atlas-skeleton command to read the table information from the database. You can read more about that in the atlas/cli docs.

3.1.1.3. Instantiating Atlas

Create an Atlas instance using the AtlasBuilder.

The builder accepts a PDO, ExtendedPdo, or ConnectionLocator instance, or you can enter connection parameters and the builder will create a connection for you.

<?php
$atlasBuilder = new AtlasBuilder(new PDO(...));
// or
$atlasBuilder = new AtlasBuilder(new ExtendedPdo(...));
// or
$atlasBuilder = new AtlasBuilder(new ConnectionLocator(...));
// or
$atlasBuilder = new AtlasBuilder(
    'mysql:host=localhost;dbname=testdb',
    'username',
    'password'
);

Then get a new Atlas instance out of the builder:

<?php
$atlas = $atlasBuilder->newAtlas();

Note:

Atlas 2.5.x and earlier use the older AtlasContainer to build an Atlas object. The older approach requires you to register all mappers with the container using its setMappers() method, whereas the newer AtlasBuilder in 2.6.x lazy-loads them on demand.