<commit_before><?php

namespace Bolt\Mapping;

use Bolt\Database\IntegrityChecker;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Bolt\Mapping\ClassMetadata as BoltClassMetadata;
use Doctrine\DBAL\Schema\Table;

/**
 * This is a Bolt specific metadata driver that provides mapping information
 * for the internal and user-defined schemas. To do this it takes in the constructor,
 * an instance of IntegrityChecker and uses this to read in the schema.
 *
 * @author <NAME> <<EMAIL>>
 */
class MetadataDriver implements MappingDriver
{
    
    /**
     * IntegrityChecker object
     */
    protected $integrityChecker;
    
    /**
     * Array of contenttypes
     */
    protected $contenttypes;
    
    /**
     * array of metadata mappings
     */
    protected $metadata;
    
    /**
     * @var array
     */
    protected $defaultAliases = array(
        'bolt_authtoken' => 'Bolt\Entity\Authtoken',
        'bolt_cron' => 'Bolt\Entity\Cron',
        'bolt_log' => 'Bolt\Entity\Log',
        'bolt_log_change' => 'Bolt\Entity\LogChange',
        'bolt_log_system' => 'Bolt\Entity\LogSystem',
        'bolt_relations' => 'Bolt\Entity\Relations',
        'bolt_taxonomy' => 'Bolt\Entity\Taxonomy',
        'bolt_users' => 'Bolt\Entity\Users'
    );
    
    protected $typemap;
    
    /**
     * @var string - a default entity for any table not matched
     */
    protected $fallbackEntity = 'Bolt\Entity\Content';
    
    /**
     * @var boolean
     */
    protected $initialized = false;

    /**
     * @param IntegrityChecker $integrityChecker
     */
    public function __construct(IntegrityChecker $integrityChecker, array $contenttypes, array $typemap)
    {
        $this->integrityChecker = $integrityChecker;
        $this->contenttypes = $contenttypes;
        $this->typemap = $typemap;
    }
    
    /**
     * Reads the schema from IntegrityChecker and creates mapping data
     * 
     * @return void
     */
    public function initialize()
    {
        foreach ($this->integrityChecker->getTablesSchema() as $table) {
            $this->loadMetadataForTable($table);
        }
        $this->initialized = true;
    }
    
    protected function loadMetadataForTable(Table $table)
    {
        $tblName = $table->getName();
        
        if (isset($this->defaultAliases[$tblName])) {
            $className = $this->defaultAliases[$tblName];
        } else {
            $className = $tblName;
        }<commit_msg>keep an array of unmapped metadata<commit_after><?php

namespace Bolt\Mapping;

use Bolt\Database\IntegrityChecker;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Bolt\Mapping\ClassMetadata as BoltClassMetadata;
use Doctrine\DBAL\Schema\Table;

/**
 * This is a Bolt specific metadata driver that provides mapping information
 * for the internal and user-defined schemas. To do this it takes in the constructor,
 * an instance of IntegrityChecker and uses this to read in the schema.
 *
 * @author <NAME> <<EMAIL>>
 */
class MetadataDriver implements MappingDriver
{
    
    /**
     * IntegrityChecker object
     */
    protected $integrityChecker;
    
    /**
     * Array of contenttypes
     */
    protected $contenttypes;
    
    /**
     * array of metadata mappings
     */
    protected $metadata;
    
    /**
     * @var array
     */
    protected $defaultAliases = array(
        'bolt_authtoken' => 'Bolt\Entity\Authtoken',
        'bolt_cron' => 'Bolt\Entity\Cron',
        'bolt_log' => 'Bolt\Entity\Log',
        'bolt_log_change' => 'Bolt\Entity\LogChange',
        'bolt_log_system' => 'Bolt\Entity\LogSystem',
        'bolt_relations' => 'Bolt\Entity\Relations',
        'bolt_taxonomy' => 'Bolt\Entity\Taxonomy',
        'bolt_users' => 'Bolt\Entity\Users'
    );
    
    protected $typemap;
    
    /**
     *  Keeps a reference of which metadata is not mapped to
     *  a specific entity.
     * 
     *  @var array $unmapped 
     */
    protected $unmapped;
    
    /**
     * @var string - a default entity for any table not matched
     */
    protected $fallbackEntity = 'Bolt\Entity\Content';
    
    /**
     * @var boolean
     */
    protected $initialized = false;

    /**
     * @param IntegrityChecker $integrityChecker
     */
    public function __construct(IntegrityChecker $integrityChecker, array $contenttypes, array $typemap)
    {
        $this->integrityChecker = $integrityChecker;
        $this->contenttypes = $contenttypes;
        $this->typemap = $typemap;
    }
    
    /**
     * Reads the schema from IntegrityChecker and creates mapping data
     * 
     * @return void
     */
    public function initialize()
    {
        foreach ($this->integrityChecker->getTablesSchema() as $table) {
            $this->loadMetadataForTable($table);
        }
        $this->initialized = true;
    }
    
    protected function loadMetadataForTable(Table $table)
    {
        $tblName = $table->getName();
        
        if (isset($this->defaultAliases[$tblName])) {
            $className = $this->defaultAliases[$tblName];
        } else {
            $className = $tblName;
            $this->unmapped[] = $tblName;
        }
{'fraction_non_alphanumeric': 0.11579943235572375, 'fraction_numerical': 0.0, 'mean_word_length': 2.4147286821705425, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4867754', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1565, 'n_words': 357}