[PR #357] [CLOSED] Persistent and Called First ClassName #8072

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

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/357
Author: @bpanahij
Created: 5/25/2012
Status: Closed

Base: masterHead: master


📝 Commits (10+)

  • 7e0799b -NamingStrategy
  • 227e0f0 -stub in setClassName interface
  • 94cf7ca -Stub in interface for new setClassName
  • fbdba44 Move className parameter to each method as optional
  • eb95a92 -Suggestion taken to add $className to each method as an optional parameter
  • c32447d -Remove self-deprecated function
  • a9b7a0d -remove self-deprecating setClassName function
  • ea579f3 -need to make both params for joinColumnName optional
  • c0333fb -make optional param propertyName for propertyToColumnName
  • 1c1ff29 -Must be compatible with new NamingStrategy class definition

📊 Changes

4 files changed (+39 additions, -33 deletions)

View changed files

📝 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (+14 -14)
📝 lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php (+8 -7)
📝 lib/Doctrine/ORM/Mapping/NamingStrategy.php (+11 -6)
📝 lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php (+6 -6)

📄 Description

--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()));
}

}


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/357 **Author:** [@bpanahij](https://github.com/bpanahij) **Created:** 5/25/2012 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`7e0799b`](https://github.com/doctrine/orm/commit/7e0799b34796736577c6ddb63c0d18a670ea6c76) -NamingStrategy - [`227e0f0`](https://github.com/doctrine/orm/commit/227e0f052121dc92ec871332a4868f4822527b71) -stub in setClassName interface - [`94cf7ca`](https://github.com/doctrine/orm/commit/94cf7caf302fc67d7b5c23d5c298b1502a77e371) -Stub in interface for new setClassName - [`fbdba44`](https://github.com/doctrine/orm/commit/fbdba44917548f9bef39bf6ed9b2575e6af68764) Move className parameter to each method as optional - [`eb95a92`](https://github.com/doctrine/orm/commit/eb95a92bfd4318f029f654308587d00487089f2a) -Suggestion taken to add $className to each method as an optional parameter - [`c32447d`](https://github.com/doctrine/orm/commit/c32447de082f976e81ff861bc64fdeef791a3f3b) -Remove self-deprecated function - [`a9b7a0d`](https://github.com/doctrine/orm/commit/a9b7a0d62fa2d339d9021e9f3acaac3ace5d9ab3) -remove self-deprecating setClassName function - [`ea579f3`](https://github.com/doctrine/orm/commit/ea579f3550bfed3de2feb85b0ed46c2509051f78) -need to make both params for joinColumnName optional - [`c0333fb`](https://github.com/doctrine/orm/commit/c0333fb524aa89d9925bc945a6944e4424daabe8) -make optional param propertyName for propertyToColumnName - [`1c1ff29`](https://github.com/doctrine/orm/commit/1c1ff29b0e760cf82cf63ef8c6aee3a75f2b64ef) -Must be compatible with new NamingStrategy class definition ### 📊 Changes **4 files changed** (+39 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php` (+14 -14) 📝 `lib/Doctrine/ORM/Mapping/DefaultNamingStrategy.php` (+8 -7) 📝 `lib/Doctrine/ORM/Mapping/NamingStrategy.php` (+11 -6) 📝 `lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php` (+6 -6) </details> ### 📄 Description --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())); } ``` } --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 15:58:15 +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#8072