Вход Регистрация
Файл: vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php
Строк: 88
<?php

namespace DoctrineDBALPlatformsKeywords;

use 
DoctrineDBALSchemaColumn;
use 
DoctrineDBALSchemaForeignKeyConstraint;
use 
DoctrineDBALSchemaIndex;
use 
DoctrineDBALSchemaSchema;
use 
DoctrineDBALSchemaSequence;
use 
DoctrineDBALSchemaTable;
use 
DoctrineDBALSchemaVisitorVisitor;

use function 
implode;
use function 
str_replace;

class 
ReservedKeywordsValidator implements Visitor
{
    
/** @var KeywordList[] */
    
private $keywordLists = [];

    
/** @var string[] */
    
private $violations = [];

    
/**
     * @param KeywordList[] $keywordLists
     */
    
public function __construct(array $keywordLists)
    {
        
$this->keywordLists $keywordLists;
    }

    
/**
     * @return string[]
     */
    
public function getViolations()
    {
        return 
$this->violations;
    }

    
/**
     * @param string $word
     *
     * @return string[]
     */
    
private function isReservedWord($word)
    {
        if (
$word[0] === '`') {
            
$word str_replace('`'''$word);
        }

        
$keywordLists = [];
        foreach (
$this->keywordLists as $keywordList) {
            if (! 
$keywordList->isKeyword($word)) {
                continue;
            }

            
$keywordLists[] = $keywordList->getName();
        }

        return 
$keywordLists;
    }

    
/**
     * @param string   $asset
     * @param string[] $violatedPlatforms
     *
     * @return void
     */
    
private function addViolation($asset$violatedPlatforms)
    {
        if (! 
$violatedPlatforms) {
            return;
        }

        
$this->violations[] = $asset ' keyword violations: ' implode(', '$violatedPlatforms);
    }

    
/**
     * {@inheritdoc}
     */
    
public function acceptColumn(Table $tableColumn $column)
    {
        
$this->addViolation(
            
'Table ' $table->getName() . ' column ' $column->getName(),
            
$this->isReservedWord($column->getName())
        );
    }

    
/**
     * {@inheritdoc}
     */
    
public function acceptForeignKey(Table $localTableForeignKeyConstraint $fkConstraint)
    {
    }

    
/**
     * {@inheritdoc}
     */
    
public function acceptIndex(Table $tableIndex $index)
    {
    }

    
/**
     * {@inheritdoc}
     */
    
public function acceptSchema(Schema $schema)
    {
    }

    
/**
     * {@inheritdoc}
     */
    
public function acceptSequence(Sequence $sequence)
    {
    }

    
/**
     * {@inheritdoc}
     */
    
public function acceptTable(Table $table)
    {
        
$this->addViolation(
            
'Table ' $table->getName(),
            
$this->isReservedWord($table->getName())
        );
    }
}
Онлайн: 2
Реклама