[PR #357] Persistent and Called First ClassName #8077

Open
opened 2026-01-22 15:58:16 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/357

State: closed
Merged: No


--Allow the use of the ClassName in Naming functions other than just setting the table name

I am using it to add a table name prefix to all of my columns within the table;
as follows:

<?php
/**
* Author: Brian P Johnson
* Date: 5/24/12
* Time: 8:23 AM
*/
require_once('/usr/src/doctrine2-orm/lib/Doctrine/ORM/Mapping/NamingStrategy.php'); 
use Doctrine\ORM\Mapping\NamingStrategy;

class rateGeniusNamingStrategy implements NamingStrategy
{
    public $className = '';
    public $prefix = '';

    public function setClassName($className) {

        $this->className = $className;

        $className = 'AdverseActionNaming';
        $capString = preg_replace('/[^A-Z]/','',$className);
        if(strlen($capString) < 4)
        {
            $capString = substr($capString,0,1).substr($className,1,4-strlen($capString)).substr($capString,1,3);
        }

        $this->prefix = strtoupper($capString);
    }

public function classToTableName($className)
{
    $wordArray = preg_split('/(?=\p{Lu})/u', $className);
    $table_name_body = '';
    $count = 0;
    $word = "";
    foreach($wordArray as $word)
    {
        $table_name_body .= '_'.strtoupper($word);
        $count++;
    }
    return $this->prefix.$table_name_body;
}

public function propertyToColumnName($propertyName)
{
    $wordArray = preg_split('/(?=\p{Lu})/u', $propertyName);
    $column_name_body = '';
    foreach($wordArray as $word)
    {
        $column_name_body .= '_'.strtoupper($word);
    }
    return $this->prefix.$column_name_body;
}

public function referenceColumnName()
{
    return $this->prefix.'_ID';
}

public function joinColumnName($propertyName)
{
    $table_name_parts = preg_split('/_/',$this->joinTableName());
    return $this->prefix .'_' . $table_name_parts[0] . '_' . $this->referenceColumnName();
}

public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
{
    return strtoupper($this->classToTableName($sourceEntity) . '_' .
        $this->classToTableName($targetEntity));
}

public function joinKeyColumnName($entityName, $referencedColumnName = null)
{
    return strtoupper($this->classToTableName($entityName) . '_' .
        ($referencedColumnName ?: $this->referenceColumnName()));
}

}

**Original Pull Request:** https://github.com/doctrine/orm/pull/357 **State:** closed **Merged:** No --- --Allow the use of the ClassName in Naming functions other than just setting the table name I am using it to add a table name prefix to all of my columns within the table; as follows: ``` <?php /** * Author: Brian P Johnson * Date: 5/24/12 * Time: 8:23 AM */ require_once('/usr/src/doctrine2-orm/lib/Doctrine/ORM/Mapping/NamingStrategy.php'); use Doctrine\ORM\Mapping\NamingStrategy; class rateGeniusNamingStrategy implements NamingStrategy { public $className = ''; public $prefix = ''; public function setClassName($className) { $this->className = $className; $className = 'AdverseActionNaming'; $capString = preg_replace('/[^A-Z]/','',$className); if(strlen($capString) < 4) { $capString = substr($capString,0,1).substr($className,1,4-strlen($capString)).substr($capString,1,3); } $this->prefix = strtoupper($capString); } public function classToTableName($className) { $wordArray = preg_split('/(?=\p{Lu})/u', $className); $table_name_body = ''; $count = 0; $word = ""; foreach($wordArray as $word) { $table_name_body .= '_'.strtoupper($word); $count++; } return $this->prefix.$table_name_body; } public function propertyToColumnName($propertyName) { $wordArray = preg_split('/(?=\p{Lu})/u', $propertyName); $column_name_body = ''; foreach($wordArray as $word) { $column_name_body .= '_'.strtoupper($word); } return $this->prefix.$column_name_body; } public function referenceColumnName() { return $this->prefix.'_ID'; } public function joinColumnName($propertyName) { $table_name_parts = preg_split('/_/',$this->joinTableName()); return $this->prefix .'_' . $table_name_parts[0] . '_' . $this->referenceColumnName(); } public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) { return strtoupper($this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity)); } public function joinKeyColumnName($entityName, $referencedColumnName = null) { return strtoupper($this->classToTableName($entityName) . '_' . ($referencedColumnName ?: $this->referenceColumnName())); } ``` }
admin added the pull-request label 2026-01-22 15:58:16 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#8077