<commit_before><?php
namespace Atlas;

use Atlas\Mapper\Mapper;
use Atlas\Mapper\MapperLocator;
use Atlas\Table\TableSelect;

class Atlas
{
    protected $mapperLocator;

    public function __construct(MapperLocator $mapperLocator)
    {
        $this->mapperLocator = $mapperLocator;
    }

    public function getMapperLocator()
    {
        return $this->mapperLocator;
    }

    public function mapper($mapperClass)
    {
        return $this->mapperLocator->get($mapperClass);
    }

    public function fetchRecord($mapperClass, $primaryVal, array $with = [])
    {
        $mapper = $this->mapper($mapperClass);
        $record = $mapper->fetchRecord($primaryVal);
        if ($record) {
            $mapper->getRelations()->stitchIntoRecord(
                $this,
                $record,
                $with
            );
        }
        return $record;
    }

    public function fetchRecordSet($mapperClass, $primaryVals, array $with = [])
    {
        $mapper = $this->mapper($mapperClass);
        $recordSet = $mapper->fetchRecordSet($primaryVals);
        if ($recordSet) {
            $mapper->getRelations()->stitchIntoRecordSet(
                $this,
                $recordSet,
                $with
            );
        }
        return $recordSet;
    }

    public function select($mapperClass, array $colsVals = [])
    {
        $mapper = $this->mapper($mapperClass);
        return $this->newSelect($mapper, $mapper->select($colsVals));
    }

    public function insert($entity)
    {
        return $this->mapper($entity)->insert($entity);
    }

    public function update($entity)
    {
        return $this->mapper($entity)->update($entity);
    }

    public function delete($entity)
    {
        return $this->mapper($entity)->delete($entity);
    }

    protected function newSelect(Mapper $mapper, TableSelect $select)
    {
        return new AtlasSelect($this, $mapper, $select);
    }
}<commit_msg>allow mapper() to take various inputs<commit_after><?php
namespace Atlas;

use Atlas\Mapper\Mapper;
use Atlas\Mapper\MapperLocator;
use Atlas\Mapper\Record;
use Atlas\Table\TableSelect;

class Atlas
{
    protected $mapperLocator;

    public function __construct(MapperLocator $mapperLocator)
    {
        $this->mapperLocator = $mapperLocator;
    }

    public function getMapperLocator()
    {
        return $this->mapperLocator;
    }

    public function mapper($spec)
    {
        $mapperClass = $this->getMapperClass($spec);
        return $this->mapperLocator->get($mapperClass);
    }

    protected function getMapperClass($spec)
    {
        if (is_object($spec)) {
            $spec = get_class($spec);
        }

        if (substr($spec, -6) == 'Record') {
            $spec = substr($spec, 0, -6) . 'Mapper';
        }

        return $spec;
    }

    public function fetchRecord($spec, $primaryVal, array $with = [])
    {
        $mapper = $this->mapper($spec);
        $record = $mapper->fetchRecord($primaryVal);
        if ($record) {
            $mapper->getRelations()->stitchIntoRecord(
                $this,
                $record,
                $with
            );
        }
        return $record;
    }

    public function fetchRecordSet($spec, $primaryVals, array $with = [])
    {
        $mapper = $this->mapper($spec);
        $recordSet = $mapper->fetchRecordSet($primaryVals);
        if ($recordSet) {
            $mapper->getRelations()->stitchIntoRecordSet(
                $this,
                $recordSet,
                $with
            );
        }
        return $recordSet;
    }

    public function select($spec, array $colsVals = [])
    {
        $mapper = $this->mapper($spec);
        return $this->newAtlasSelect($mapper, $mapper->select($colsVals));
    }

    public function insert(Record $record)
    {
        return $this->mapper($record)->insert($record);
    }

    public function update(Record $record)
    {
        return $this->mapper($record)->update($record);
    }

    public function delete(Record $record)
    {
        return $this->mapper($record)->delete($record);
    }

    protected function newAtlasSelect(Mapper $mapper, TableSelect $select)
    {
        return new AtlasSelect($this, $mapper, $select);
    }
}
{'fraction_non_alphanumeric': 0.13381937911571026, 'fraction_numerical': 0.0007055503292568204, 'mean_word_length': 2.190547636909227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '2169213', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1238, 'n_words': 232}