How to force Doctrine to remove table prefixes from class names?

I am using Doctrine 1.1.5, and I would like to know if there is an option to remove the table prefix from files and class names when calling Doctrine :: generateModelsFromDb or Doctrine :: generateModelsFromYaml.

Edit: For example, I have tables like mo_article, mo_language, mo_article_text, etc. When Doctrine generates models (using the functions at the top), the class names will be MoArticle, MoLanguage, MoArticleText, ... but I want them to be Article, Language, ArticleText ... Is there any option in these functions to avoid adding table prefixes in class class names?

thanks

+3
source share
2 answers

, . YAML, className: .

:

const TABLE_PFX = 'tableName:';
const CLASS_PFX = 'className:';

function AddClassNames($yamlPath) {

  $tempFilePath = $yamlPath . '.old';
  rename($yamlPath, $tempFilePath);
  $tempFile = fopen($tempFilePath, 'r');
  $yamlFile = fopen($yamlPath, 'w');

  while (!feof($tempFile)) {
      $line = fgets($tempFile);
      fwrite($yamlFile, $line);
      if ($index = strpos($line, TABLE_PFX)) {
          $tableName = trim(substr($line, $index + strlen(TABLE_PFX) + 1));
          $className = substr($tableName, 4);
          $className = strtocamel($className);
          $classLine = str_replace(TABLE_PFX, CLASS_PFX, $line);
          $classLine = str_replace($tableName, $className, $classLine);
          fwrite($yamlFile, $classLine);
      }
  }
  fclose($tempFile);
  fclose($yamlFile);
  unlink($tempFilePath);
}

:

Doctrine_Core::generateYamlFromDb($yamlPath);
AddClassNames($yamlPath);
Doctrine_Core::generateModelsFromYaml($yamlPath, 'models',
    array('doctrine'), 
    array('generateTableClasses' => true,));

- Doctrine, database_table_name PHP ClassName, . strtocamel .

0

className: CorrectName

, schema.yml. Doctrine CorrectName, / .

0

Source: https://habr.com/ru/post/1724186/


All Articles