4.1.1. Getting Started

4.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": "~1.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.)

4.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.

4.1.1.3. Instantiating Atlas

Create an Atlas instance using the AtlasContainer.

The container accepts a PDO, ExtendedPdo or ConnectionLocator instance or you can enter connection parameters and the container creates a connection for you.

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

Next, set the available mapper classes into the container.

<?php
$atlasContainer->setMappers([
    AuthorMapper::CLASS,
    ReplyMapper::CLASS,
    SummaryMapper::CLASS,
    TagMapper::CLASS,
    ThreadMapper::CLASS,
    TaggingMapper::CLASS,
]);

Finally, get back the Atlas instance out of the container.

<?php
$atlas = $atlasContainer->getAtlas();