2.1.1. Getting Started

2.1.1.1. Integrations

If you are using Symfony 4, you can get started by installing the Atlas.Symfony bundle.

If you are using Slim 3, please see the cookbook recipe for Atlas.

Otherwise, read below for the stock installation instructions.

2.1.1.2. 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": "~3.0"
    },
    "require-dev": {
        "atlas/cli": "~2.0"
    }
}

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

Note:

If you are using PHPStorm, you may wish to copy the IDE meta file to your project to get full autocompletion on Atlas classes:

cp ./vendor/atlas/orm/resources/phpstorm.meta.php ./.phpstorm.meta.php

2.1.1.3. Skeleton Generation

Next, you will need to create the prerequsite data-source classes using Atlas.Cli 2.x.

2.1.1.4. Instantiating Atlas

Now you can create an Atlas instance by using its static new() method and passing your PDO connection parameters:

use Atlas\Orm\Atlas;

$atlas = Atlas::new(
    'mysql:host=localhost;dbname=testdb',
    'username',
    'password'
);

Optionally, you may pass a Transaction class name as the final parameter. (By default, Atlas will use an AutoCommit strategy, where transactions have to be managed manually.)

use Atlas\Orm\Atlas;
use Atlas\Orm\Transaction\AutoTransact;

$atlas = Atlas::new(
    'mysql:host=localhost;dbname=testdb',
    'username',
    'password',
    AutoTransact::CLASS
);

Alternatively, use the AtlasBuilder if you need to define a custom factory callable, such as for TableEvents and MapperEvents classes.

use Atlas\Orm\AtlasBuilder;
use Atlas\Orm\Transaction\BeginOnRead;

$builder = new AtlasBuilder(
    'mysql:host=localhost;dbname=testdb',
    'username',
    'password'
);

// get the ConnectionLocator to set read and write connection factories
$builder->getConnectionLocator()->...;

// set a Transaction class (the default is AutoCommit)
$builder->setTransactionClass(BeginOnRead::CLASS);

// set a custom factory callable
$builder->setFactory(function ($class) {
    return new $class();
});

// get a new Atlas instance
$atlas = $builder->newAtlas();

2.1.1.5. Next Steps

Now you can use Atlas to work with your database to fetch and persist Record objects, as well as perform other interactions.