composer config extra.symfony.allow-contrib true
composer require atlas/symfony ~1.0
.env (replace placeholders):
ATLAS_PDO_DSN=mysql:host=localhost;dbname=your_db
ATLAS_PDO_USERNAME=your_user
ATLAS_PDO_PASSWORD=your_password
mkdir -p src/DataSource
php bin/console atlas:skeleton
atlas.yaml under config/packages/ for directory/namespace paths.// src/Service/ThreadService.php
namespace App\Service;
use Atlas\Orm\Atlas;
use App\DataSource\Thread\Thread;
class ThreadService {
public function __construct(private Atlas $atlas) {}
public function getThread(int $id) {
return $this->atlas->fetchRecord(Thread::class, $id);
}
}
Atlas via Symfony’s DI container (no manual instantiation).php bin/console debug:container Atlas to verify service availability.Atlas via constructor (type-hinted).
public function __construct(Atlas $atlas) { ... }
src/DataSource/ (e.g., Thread.php).
// src/DataSource/Thread/Thread.php
namespace App\DataSource\Thread;
use Atlas\Orm\Mapper;
class Thread extends Mapper {
public function getPosts() {
return $this->hasMany(Post::class);
}
}
atlas.yaml:
atlas:
orm:
atlas:
transaction_class: Atlas\Orm\Transaction\AutoTransact
$this->atlas->beginTransaction();
try {
$this->atlas->fetchRecord(...);
$this->atlas->commit();
} catch (\Exception $e) {
$this->atlas->rollBack();
}
atlas.yaml:
atlas:
orm:
atlas:
log_queries: true
atlas.yaml:
connections:
default:
dsn: '%env(ATLAS_PDO_DSN)%'
options:
!php/const PDO::ATTR_EMULATE_PREPARES: false
class User extends Mapper {
public function getPosts() {
return $this->hasMany(Post::class);
}
}
use Atlas\Orm\Behavior\Timestampable;
class Post extends Mapper {
use Timestampable;
}
php bin/console atlas:skeleton
php bin/console atlas:migrate
Namespace/Directory Mismatch:
atlas:skeleton fails, verify atlas.cli.config.input.directory and namespace in atlas.yaml match your src/DataSource/ setup.atlas.yaml or regenerate with correct paths.PDO Connection Issues:
.env variables (ATLAS_PDO_*) are correctly set and the database is reachable.log_queries: true and check profiler for errors.Transaction Leaks:
try/catch with commit()/rollBack().AutoTransact for simplicity (but test edge cases).Case Sensitivity:
threads → Thread).atlas.cli.transform if needed:
atlas:
cli:
transform:
threads: ForumThread
Profiler Not Showing Queries:
log_queries: true and the Symfony Profiler toolbar is enabled in config/packages/dev/profiler.yaml.$this->atlas->getLogger()->setLevel(\Psr\Log\LogLevel::DEBUG);
var_dump($record->toArray());
log_queries and inspect the profiler.Custom Mappers:
Extend Atlas\Orm\Mapper to add domain logic:
class CustomMapper extends Mapper {
public function customMethod() { ... }
}
Event Listeners:
Use Atlas events (e.g., Atlas\Orm\Event\BeforeSave) via Symfony’s event dispatcher:
# config/services.yaml
services:
App\EventListener\AtlasListener:
tags:
- { name: kernel.event_listener, event: atlas.before_save, method: onBeforeSave }
Custom Transactions:
Implement Atlas\Orm\Transaction\TransactionInterface for advanced control.
with() to avoid N+1 queries:
$thread = $this->atlas->fetchRecord(Thread::class, 1, ['posts']);
RecordSet methods:
$records = $this->atlas->fetchAll(Thread::class);
$records->each(fn($record) => $record->setStatus('active'));
$this->atlas->saveAll($records);
cp vendor/atlas/orm/resources/phpstorm.meta.php ./.phpstorm.meta.php
src/DataSource/ as a "Sources" root.How can I help you explore Laravel packages today?