<commit_before># Events

There are several events that will automatically be called when interacting with a
Atlas objects.


## Table Events

There are several events that will automatically be called when interacting with a
Table object. If you used the Atlas CLI tool with the `--full` option, a
TableEvents class will be created for you. For example, `ThreadTableEvents.php`.
With this class, you can override any of the available mapper events.

The `insert()`, `update()`, and `delete()` methods all have 3 events associated
with them: a `before*()`, a `modify*()`, and an `after*()`. In addition, there
is a `modifySelect()` event, and a `modifySelectedRow()` event.

```php
<?php
// Runs after the Select object is created, but before it is executed
modifySelect(Table $table, TableSelect $select)

// Runs after a newly-selected row is instantiated, but before it is
// identity-mapped.
modifySelectedRow(Table $table, Row $row)

// Runs before the Insert object is created
beforeInsert(Table $table, Row $row)

// Runs after the Insert object is created, but before it is executed
modifyInsert(Table $table, Row $row, Insert $insert)

// Runs after the Insert object is executed
afterInsert(Table $table,
            Row $row,
            Insert $insert,
            PDOStatement $pdoStatement)

// Runs before the Update object is created
beforeUpdate(Table $table, Row $row)

// Runs after the Update object is created, but before it is executed
modifyUpdate(Table $table, Row $row, Update $update)

// Runs after the Update object is executed
afterUpdate(Table $table,
            Row $row,
            Update $update,
            PDOStatement $pdoStatement)

// Runs before the Delete object is created
beforeDelete(Table $table, Row $row)

// Runs after the Delete object is created, but before it is executed
modifyDelete(Table $table, Row $row, Delete $delete)

// Runs after the Delete object is executed
afterDelete(Table $table,
            Row $row,
            Delete $delete,
            PDOStatement $pdoStatement)
```

These would be the place to put behaviors such as setting `inserted_at` or
`updated_at` values, etc:

```php
<?php
namespace Blog\DataSource\Posts;

use Atlas\Table\MapperEvents;
use Atlas\Table\Table;
use Atlas\Table\Row;

/**
 * @inheritdoc
 */
class PostsTableEvents extends TableEvents
{
    public function beforeUpdate(Table $table, Row $row)
    {
        $row->inserted_at = date('Y-m-d H:i:s');
    }

    public function beforeUpdate(Table $table, Row $row)
    {
        $row->updated_at = date('Y-m-d H:i:s');
    }
}
```

## Mapper Events

The `insert()`, `update()`, and `delete()` methods all have 3 events associated
with them: a `before*()`, a `modify*()`, and an `after*()`. In addition, there<commit_msg>update docs<commit_after># Events

There are several events that will automatically be called when interacting with
Atlas objects.

## Table Events

The `insert()`, `update()`, and `delete()` methods all have 3 events associated
with them: a `before*()`, a `modify*()`, and an `after*()`. In addition, there
is a `modifySelect()` event, and a `modifySelectedRow()` event.

```php
<?php
// Runs after the Select object is created, but before it is executed
modifySelect(Table $table, TableSelect $select)

// Runs after a newly-selected row is instantiated, but before it is
// identity-mapped.
modifySelectedRow(Table $table, Row $row)

// Runs before the Insert object is created
beforeInsert(Table $table, Row $row)

// Runs after the Insert object is created, but before it is executed
modifyInsert(Table $table, Row $row, Insert $insert)

// Runs after the Insert object is executed
afterInsert(Table $table,
            Row $row,
            Insert $insert,
            PDOStatement $pdoStatement)

// Runs before the Update object is created
beforeUpdate(Table $table, Row $row)

// Runs after the Update object is created, but before it is executed
modifyUpdate(Table $table, Row $row, Update $update)

// Runs after the Update object is executed
afterUpdate(Table $table,
            Row $row,
            Update $update,
            PDOStatement $pdoStatement)

// Runs before the Delete object is created
beforeDelete(Table $table, Row $row)

// Runs after the Delete object is created, but before it is executed
modifyDelete(Table $table, Row $row, Delete $delete)

// Runs after the Delete object is executed
afterDelete(Table $table,
            Row $row,
            Delete $delete,
            PDOStatement $pdoStatement)
```

TableEvents would be the place to put behaviors such as setting `inserted_at` or
`updated_at` values, etc:

```php
<?php
namespace Blog\DataSource\Posts;

use Atlas\Table\MapperEvents;
use Atlas\Table\Table;
use Atlas\Table\Row;

/**
 * @inheritdoc
 */
class PostsTableEvents extends TableEvents
{
    public function beforeUpdate(Table $table, Row $row)
    {
        $row->inserted_at = date('Y-m-d H:i:s');
    }

    public function beforeUpdate(Table $table, Row $row)
    {
        $row->updated_at = date('Y-m-d H:i:s');
    }
}
```

## Mapper Events

The `insert()`, `update()`, and `delete()` methods all have 3 events associated
with them: a `before*()`, a `modify*()`, and an `after*()`. In addition, there
{'fraction_non_alphanumeric': 0.10794258373205741, 'fraction_numerical': 0.0007655502392344498, 'mean_word_length': 3.637089618456078, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5781108', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1500, 'n_words': 628}