<?xml version="1.0"?>
<?xml-stylesheet 
 href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"
?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel rdf:about="http://pear.php.net/bugs/3256/bug">
    <title>PEAR Bug #3256</title>
    <link>http://pear.php.net/bugs/3256</link>
    <description>[Verified] Allow custom file and class naming conventions</description>
    <dc:language>en-us</dc:language>
    <dc:creator>pear-webmaster@lists.php.net</dc:creator>
    <dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
    <admin:generatorAgent rdf:resource="http://pear.php.net/bugs"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <items>
     <rdf:Seq>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-10-05+04%3A53%3A42#2005-10-05+04%3A53%3A42"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-18+00%3A53%3A07#2005-05-18+00%3A53%3A07"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-17+23%3A21%3A55#2005-05-17+23%3A21%3A55"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-17+19%3A16%3A09#2005-05-17+19%3A16%3A09"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-14+17%3A41%3A07#2005-05-14+17%3A41%3A07"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-14+17%3A35%3A42#2005-05-14+17%3A35%3A42"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-13+23%3A36%3A02#2005-05-13+23%3A36%3A02"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-05-13+23%3A07%3A21#2005-05-13+23%3A07%3A21"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/3256/2005-01-20+18%3A56%3A23#2005-01-20+18%3A56%3A23"/>
     </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://pear.php.net/bugs/3256">
      <title>db_dataobjects-bugs-2005@... [2005-01-20 18:46:07]</title>
      <link>http://pear.php.net/bugs/3256</link>
      <description><![CDATA[<pre>DB_DataObject Feature/Change Request
Reported by db_dataobjects-bugs-2005@...
2005-01-20T23:46:07-00:00
PHP: Irrelevant OS: Irrelevant Package Version: 

Description:
------------
There is code in DB_DataObjects which computes the name to 
be used for each data object class and its PHP file. In 
Generator.php it looks like this:


$this-&gt;classname = $class_prefix.preg_replace('/[^A-Z0-9]/
i','_',ucfirst($this-&gt;table));
$i = '';
$outfilename = &quot;{$base}/&quot;.preg_replace('/[^A-Z0-9]/
i','_',ucfirst($this-&gt;table)).&quot;.php&quot;;


Code like this is also duplicated in other places in 
DB_DataObjects.

I would like to see these preg_replace()s moved out into 
new methods, like computeClassName($table) and 
computeFileName($table), so that I could override these in 
a child class to implement different behavior.

The reason for this is that I do not subscribe to the PEAR 
notion that the first character of a class name should be 
uppercase, and do not want this naming convention for 
files in my project.

Furthermore all my table names begin with a version of my 
project's name, followed by two underscores. This practice 
is recommended by phpMyAdmin and has several advantages. 
But I would like to dispense with these prefixes when 
dealing with the data objects within my project.


The numerous places within the DB_DataObjects code where 
changes would need to be made currently make it 
impractical for me to implement differing behavior without 
having to copy large sections of the DB_DataObjects code, 
which is undesirable from a maintenance standpoint as new 
versions of DB_DataObjects are released. By abstracting 
these tasks into separate methods you would enable me to 
achieve my desired result in the most effective way.


See also bugs 3013 and 2740 for similar requests. 
Implementing the above suggestion may take care of those 
users' needs as well.


I am using DB_DataObjects 1.7.2 with PHP 5.0.3, Apache 
1.3.33 and Mac OS X 10.3.7.</pre>]]></description>
      <content:encoded><![CDATA[<pre>DB_DataObject Feature/Change Request
Reported by db_dataobjects-bugs-2005@...
2005-01-20T23:46:07-00:00
PHP: Irrelevant OS: Irrelevant Package Version: 

Description:
------------
There is code in DB_DataObjects which computes the name to 
be used for each data object class and its PHP file. In 
Generator.php it looks like this:


$this-&gt;classname = $class_prefix.preg_replace('/[^A-Z0-9]/
i','_',ucfirst($this-&gt;table));
$i = '';
$outfilename = &quot;{$base}/&quot;.preg_replace('/[^A-Z0-9]/
i','_',ucfirst($this-&gt;table)).&quot;.php&quot;;


Code like this is also duplicated in other places in 
DB_DataObjects.

I would like to see these preg_replace()s moved out into 
new methods, like computeClassName($table) and 
computeFileName($table), so that I could override these in 
a child class to implement different behavior.

The reason for this is that I do not subscribe to the PEAR 
notion that the first character of a class name should be 
uppercase, and do not want this naming convention for 
files in my project.

Furthermore all my table names begin with a version of my 
project's name, followed by two underscores. This practice 
is recommended by phpMyAdmin and has several advantages. 
But I would like to dispense with these prefixes when 
dealing with the data objects within my project.


The numerous places within the DB_DataObjects code where 
changes would need to be made currently make it 
impractical for me to implement differing behavior without 
having to copy large sections of the DB_DataObjects code, 
which is undesirable from a maintenance standpoint as new 
versions of DB_DataObjects are released. By abstracting 
these tasks into separate methods you would enable me to 
achieve my desired result in the most effective way.


See also bugs 3013 and 2740 for similar requests. 
Implementing the above suggestion may take care of those 
users' needs as well.


I am using DB_DataObjects 1.7.2 with PHP 5.0.3, Apache 
1.3.33 and Mac OS X 10.3.7.</pre>]]></content:encoded>
      <dc:date>2005-01-20T23:46:07-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-10-05+04%3A53%3A42#2005-10-05+04%3A53%3A42">
      <title>pearuser@... [2005-10-05 08:53]</title>
      <link>http://pear.php.net/bugs/3256#1128502422</link>
      <description><![CDATA[<pre>FWIW:
simple patch to have control of filename prefix (ini option class_filename_prefix.

--- /usr/lib/php/DB/DataObject/Generator.php    2005-10-05 03:48:09.000000000 -0500
+++ Generator.php       2005-10-05 03:46:07.000000000 -0500
@@ -495,6 +495,7 @@
             System::mkdir(array('-p',$base));
         }
         $class_prefix  = $options['class_prefix'];
+        $class_filename_prefix  = $options['class_filename_prefix'];
         if ($extends = @$options['extends']) {
             $this-&gt;_extends = $extends;
             $this-&gt;_extendsFile = $options['extends_location'];
@@ -506,9 +507,9 @@
             $i = '';

             if (strpos($options['class_location'],'%s') !== false) {
-                $outfilename   = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i','_',ucfirst($this-&gt;table)));
+                $outfilename   = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i','_',$class_filename_prefix.ucfirst($this-&gt;table)));
             } else {
-                $outfilename = &quot;{$base}/&quot;.preg_replace('/[^A-Z0-9]/i','_',ucfirst($this-&gt;table)).&quot;.php&quot;;
+                $outfilename = &quot;{$base}/&quot;.preg_replace('/[^A-Z0-9]/i','_',$class_filename_prefix.ucfirst($this-&gt;table)).&quot;.php&quot;;
             }
             $oldcontents = '';
             if (file_exists($outfilename)) {</pre>]]></description>
      <content:encoded><![CDATA[<pre>FWIW:
simple patch to have control of filename prefix (ini option class_filename_prefix.

--- /usr/lib/php/DB/DataObject/Generator.php    2005-10-05 03:48:09.000000000 -0500
+++ Generator.php       2005-10-05 03:46:07.000000000 -0500
@@ -495,6 +495,7 @@
             System::mkdir(array('-p',$base));
         }
         $class_prefix  = $options['class_prefix'];
+        $class_filename_prefix  = $options['class_filename_prefix'];
         if ($extends = @$options['extends']) {
             $this-&gt;_extends = $extends;
             $this-&gt;_extendsFile = $options['extends_location'];
@@ -506,9 +507,9 @@
             $i = '';

             if (strpos($options['class_location'],'%s') !== false) {
-                $outfilename   = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i','_',ucfirst($this-&gt;table)));
+                $outfilename   = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i','_',$class_filename_prefix.ucfirst($this-&gt;table)));
             } else {
-                $outfilename = &quot;{$base}/&quot;.preg_replace('/[^A-Z0-9]/i','_',ucfirst($this-&gt;table)).&quot;.php&quot;;
+                $outfilename = &quot;{$base}/&quot;.preg_replace('/[^A-Z0-9]/i','_',$class_filename_prefix.ucfirst($this-&gt;table)).&quot;.php&quot;;
             }
             $oldcontents = '';
             if (file_exists($outfilename)) {</pre>]]></content:encoded>
      <dc:date>2005-10-05T08:53:42-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-18+00%3A53%3A07#2005-05-18+00%3A53%3A07">
      <title>alan_k [2005-05-18 04:53]</title>
      <link>http://pear.php.net/bugs/3256#1116391987</link>
      <description><![CDATA[<pre>This would be the ideal solution eg. implemented by the ini setting:

name_provider_class = DB_DataObject_Namer

The default class could implement all the current naming rules, and Custom classes could either extend or replace it.</pre>]]></description>
      <content:encoded><![CDATA[<pre>This would be the ideal solution eg. implemented by the ini setting:

name_provider_class = DB_DataObject_Namer

The default class could implement all the current naming rules, and Custom classes could either extend or replace it.</pre>]]></content:encoded>
      <dc:date>2005-05-18T04:53:07-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-17+23%3A21%3A55#2005-05-17+23%3A21%3A55">
      <title>jrhernandez05@... [2005-05-18 03:21]</title>
      <link>http://pear.php.net/bugs/3256#1116386515</link>
      <description><![CDATA[<pre>From my experience, the XML approach is not cumbersome to maintain (our production J2EE server uses this same approach, and we've been using it for about 4 years now with no complaints). But I do see that with your approach, there would be less code to write. I would actually go further and have a class which implements the &quot;namer&quot; methods. The DB_DataObject class could use one standard namer class, DB_DataObject_Namer, and implement two static methods, &quot;getNamer&quot; and &quot;setNamer&quot;. Users could extend the DB_DataObject_Namer class and override whichever namer methods they need. Here's an example:


DB_DATAOBJECT_NAMER
-------------------------
class DB_DataObject_Namer
{
    function getClassName($tableName)
    {
        return $tableName;
    }

    function getFileName($tableName)
    {
        return $tableName . '.php';
    }

    function getPropertyName($tableName, $columnName)
    {
        return $columnName;
    }

    function getLinkPropertyName($table1, $column1, $table2, $column2)
    {
        return '_' . str_replace( '.', '_', $column1 );
    }
};


MY_NAMER
--------
class MyNamer extends DB_DataObject_Namer
{
    function getClassName($tableName)
    {
        return substr( $tableName, strpos( $tableName, '_'
) + 1 );
    }

    function getFileName($tableName)
    {
        // in this case, the class and file names are the same
        return $this-&gt;getClassName( $tableName ) . '.php';
    }

    /* NOTE: By not overriding the other methods, the default behavior will be used. */
};


SAMPLE USAGE
------------

require_once( 'DB/DataObject.php' );
require_once( 'MyCompany/MyNamer.php' );

DB_DataObject::setNamer( new MyNamer() );

// use DB_DataObject as usual...</pre>]]></description>
      <content:encoded><![CDATA[<pre>From my experience, the XML approach is not cumbersome to maintain (our production J2EE server uses this same approach, and we've been using it for about 4 years now with no complaints). But I do see that with your approach, there would be less code to write. I would actually go further and have a class which implements the &quot;namer&quot; methods. The DB_DataObject class could use one standard namer class, DB_DataObject_Namer, and implement two static methods, &quot;getNamer&quot; and &quot;setNamer&quot;. Users could extend the DB_DataObject_Namer class and override whichever namer methods they need. Here's an example:


DB_DATAOBJECT_NAMER
-------------------------
class DB_DataObject_Namer
{
    function getClassName($tableName)
    {
        return $tableName;
    }

    function getFileName($tableName)
    {
        return $tableName . '.php';
    }

    function getPropertyName($tableName, $columnName)
    {
        return $columnName;
    }

    function getLinkPropertyName($table1, $column1, $table2, $column2)
    {
        return '_' . str_replace( '.', '_', $column1 );
    }
};


MY_NAMER
--------
class MyNamer extends DB_DataObject_Namer
{
    function getClassName($tableName)
    {
        return substr( $tableName, strpos( $tableName, '_'
) + 1 );
    }

    function getFileName($tableName)
    {
        // in this case, the class and file names are the same
        return $this-&gt;getClassName( $tableName ) . '.php';
    }

    /* NOTE: By not overriding the other methods, the default behavior will be used. */
};


SAMPLE USAGE
------------

require_once( 'DB/DataObject.php' );
require_once( 'MyCompany/MyNamer.php' );

DB_DataObject::setNamer( new MyNamer() );

// use DB_DataObject as usual...</pre>]]></content:encoded>
      <dc:date>2005-05-18T03:21:55-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-17+19%3A16%3A09#2005-05-17+19%3A16%3A09">
      <title>db_dataobjects-bugs-2005@... [2005-05-17 23:16]</title>
      <link>http://pear.php.net/bugs/3256#1116371769</link>
      <description><![CDATA[<pre>I personally wouldn't want to have to create and
maintain such an XML file. My table names follow a
convention, always. I'd much rather define a short PHP
function to map those table names to the corresponding
class and file names than have to maintain an
umpteen-line XML file over the lifetime of my
application.

It seems to me like I should be able to do it like this:

require_once 'DB/DataObject.php';
DB_DataObject::setClassNamer(create_function('$x',
  'return strtolower(substr($x, strpos($x, &quot;__&quot;)+2));'
));
DB_DataObject::setFileNamer(create_function('$x',
  'return strtolower(substr($x, strpos($x, &quot;__&quot;)+2)) '
    . '. &quot;.class&quot;;'));

This would implement the naming strategy I want, which
is to say that I have a table called
&quot;myDatabase__myTable&quot; and I want the class to be
&quot;mytable&quot; and the PHP file to be &quot;mytable.class.php&quot;.

Then, after that initial setup, any PHP file, any
3rd-party library like DB_DataObjects_FormBuilder, can
call the factory method or whatever, and internally,
DB_DataObject can call
DB_DataObject::getClassName($tableName) to get the class
name and DB_DataObject::getFileName($tableName) to get
the file name.

Here's how these four new functions might be implemented
in DB_DataObject:

class DB_DataObject {
  function setClassNamer($function) {
    global $_DB_DATAOBJECT;
    $_DB_DATAOBJECT['classNamer'] = $function;
  }
  function setFileNamer($function) {
    global $_DB_DATAOBJECT;
    $_DB_DATAOBJECT['fileNamer'] = $function;
  }
  function getClassName($tableName) {
    global $_DB_DATAOBJECT;
    return $_DB_DATAOBJECT['classNamer']($tableName);
  }
  function getFileName($tableName) {
    global $_DB_DATAOBJECT;
    return $_DB_DATAOBJECT['fileNamer']($tableName)
      . '.php';
  }
}

Column names could be handled in a similar way.

I have no comment on how this could work in DBDO as I've
never worked with PECL.</pre>]]></description>
      <content:encoded><![CDATA[<pre>I personally wouldn't want to have to create and
maintain such an XML file. My table names follow a
convention, always. I'd much rather define a short PHP
function to map those table names to the corresponding
class and file names than have to maintain an
umpteen-line XML file over the lifetime of my
application.

It seems to me like I should be able to do it like this:

require_once 'DB/DataObject.php';
DB_DataObject::setClassNamer(create_function('$x',
  'return strtolower(substr($x, strpos($x, &quot;__&quot;)+2));'
));
DB_DataObject::setFileNamer(create_function('$x',
  'return strtolower(substr($x, strpos($x, &quot;__&quot;)+2)) '
    . '. &quot;.class&quot;;'));

This would implement the naming strategy I want, which
is to say that I have a table called
&quot;myDatabase__myTable&quot; and I want the class to be
&quot;mytable&quot; and the PHP file to be &quot;mytable.class.php&quot;.

Then, after that initial setup, any PHP file, any
3rd-party library like DB_DataObjects_FormBuilder, can
call the factory method or whatever, and internally,
DB_DataObject can call
DB_DataObject::getClassName($tableName) to get the class
name and DB_DataObject::getFileName($tableName) to get
the file name.

Here's how these four new functions might be implemented
in DB_DataObject:

class DB_DataObject {
  function setClassNamer($function) {
    global $_DB_DATAOBJECT;
    $_DB_DATAOBJECT['classNamer'] = $function;
  }
  function setFileNamer($function) {
    global $_DB_DATAOBJECT;
    $_DB_DATAOBJECT['fileNamer'] = $function;
  }
  function getClassName($tableName) {
    global $_DB_DATAOBJECT;
    return $_DB_DATAOBJECT['classNamer']($tableName);
  }
  function getFileName($tableName) {
    global $_DB_DATAOBJECT;
    return $_DB_DATAOBJECT['fileNamer']($tableName)
      . '.php';
  }
}

Column names could be handled in a similar way.

I have no comment on how this could work in DBDO as I've
never worked with PECL.</pre>]]></content:encoded>
      <dc:date>2005-05-17T23:16:09-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-14+17%3A41%3A07#2005-05-14+17%3A41%3A07">
      <title>jrhernandez05@... [2005-05-14 21:41]</title>
      <link>http://pear.php.net/bugs/3256#1116106867</link>
      <description><![CDATA[<pre>The XML code above looks cluttered due to wrapping. Hope the following is a bit clearer to read:


&lt;database-structure&gt;
	&lt;table name=&quot;t1001_customers&quot;
		id-column-names=&quot;c1001_customer_id&quot;
		sequence-key=&quot;c1001_customer_id,false,s1001_customer_id&quot;
		class-name=&quot;Customer&quot;&gt;

		&lt;column name=&quot;c1001_customer_id&quot;
			data-type=&quot;integer&quot;
			nullable=&quot;false&quot;
			property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1001_name&quot;
			data-type=&quot;string&quot;
			nullable=&quot;false&quot;
			property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1001_phone&quot;
			data-type=&quot;string&quot;
			nullable=&quot;true&quot;
			property-name=&quot;phone&quot; /&gt;
		&lt;column name=&quot;c1002_state_id&quot;
			data-type=&quot;integer&quot;
			nullable=&quot;true&quot;
			property-name=&quot;stateID&quot; /&gt;

		&lt;link property-name=&quot;state&quot;
			column-name=&quot;c1002_state_id&quot;
			table-name=&quot;t1002_states&quot;
			table-column-name=&quot;c1002_state_id&quot; /&gt;
	&lt;/table&gt;

	&lt;table name=&quot;t1002_states&quot;
		id-column-names=&quot;c1002_state_id&quot;
		sequence-key=&quot;c1002_state_id,false,c1002_state_id&quot;
		class-name=&quot;State&quot;&gt;

		&lt;column name=&quot;c1002_state_id&quot;
			data-type=&quot;integer&quot;
			nullable=&quot;false&quot;
			property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1002_name&quot;
			data-type=&quot;string&quot;
			nullable=&quot;false&quot;
			property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1002_abbreviation&quot;
			data-type=&quot;string&quot;
			nullable=&quot;false&quot;
			property-name=&quot;abbreviation&quot; /&gt;
	&lt;/table&gt;
&lt;/database-structure&gt;</pre>]]></description>
      <content:encoded><![CDATA[<pre>The XML code above looks cluttered due to wrapping. Hope the following is a bit clearer to read:


&lt;database-structure&gt;
	&lt;table name=&quot;t1001_customers&quot;
		id-column-names=&quot;c1001_customer_id&quot;
		sequence-key=&quot;c1001_customer_id,false,s1001_customer_id&quot;
		class-name=&quot;Customer&quot;&gt;

		&lt;column name=&quot;c1001_customer_id&quot;
			data-type=&quot;integer&quot;
			nullable=&quot;false&quot;
			property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1001_name&quot;
			data-type=&quot;string&quot;
			nullable=&quot;false&quot;
			property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1001_phone&quot;
			data-type=&quot;string&quot;
			nullable=&quot;true&quot;
			property-name=&quot;phone&quot; /&gt;
		&lt;column name=&quot;c1002_state_id&quot;
			data-type=&quot;integer&quot;
			nullable=&quot;true&quot;
			property-name=&quot;stateID&quot; /&gt;

		&lt;link property-name=&quot;state&quot;
			column-name=&quot;c1002_state_id&quot;
			table-name=&quot;t1002_states&quot;
			table-column-name=&quot;c1002_state_id&quot; /&gt;
	&lt;/table&gt;

	&lt;table name=&quot;t1002_states&quot;
		id-column-names=&quot;c1002_state_id&quot;
		sequence-key=&quot;c1002_state_id,false,c1002_state_id&quot;
		class-name=&quot;State&quot;&gt;

		&lt;column name=&quot;c1002_state_id&quot;
			data-type=&quot;integer&quot;
			nullable=&quot;false&quot;
			property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1002_name&quot;
			data-type=&quot;string&quot;
			nullable=&quot;false&quot;
			property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1002_abbreviation&quot;
			data-type=&quot;string&quot;
			nullable=&quot;false&quot;
			property-name=&quot;abbreviation&quot; /&gt;
	&lt;/table&gt;
&lt;/database-structure&gt;</pre>]]></content:encoded>
      <dc:date>2005-05-14T21:41:07-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-14+17%3A35%3A42#2005-05-14+17%3A35%3A42">
      <title>jrhernandez05@... [2005-05-14 21:35]</title>
      <link>http://pear.php.net/bugs/3256#1116106542</link>
      <description><![CDATA[<pre>Actually, I wasn't considering the generator portion, although the generator can also use this XML approach. I am primarily concerned on how the DataObject itself gets its database structure info. There could be an additional setting named &quot;xml_config_file&quot;, or something to that effect, and that file would have the database structure information (it would consolidate the information for the &quot;table()&quot;, &quot;keys()&quot;, &quot;sequenceKey()&quot;, and &quot;links()&quot; methods.

Below is an example of how the XML file could look like. Before viewing it, keep in mind that where I work we have a naming convention of TXXXX_NAME for tables and CXXXX_NAME for columns.


&lt;database-structure&gt;
	&lt;table name=&quot;t1001_customers&quot; id-column-names=&quot;c1001_customer_id&quot; sequence-key=&quot;c1001_customer_id,false,s1001_customer_id&quot; class-name=&quot;Customer&quot;&gt;
		&lt;column name=&quot;c1001_customer_id&quot; data-type=&quot;integer&quot; nullable=&quot;false&quot; property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1001_name&quot; data-type=&quot;string&quot; nullable=&quot;false&quot; property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1001_phone&quot; data-type=&quot;string&quot; nullable=&quot;true&quot; property-name=&quot;phone&quot; /&gt;
		&lt;column name=&quot;c1002_state_id&quot; data-type=&quot;integer&quot; nullable=&quot;true&quot; property-name=&quot;stateID&quot; /&gt;

		&lt;link property-name=&quot;state&quot; column-name=&quot;c1002_state_id&quot; table-name=&quot;t1002_states&quot; table-column-name=&quot;c1002_state_id&quot; /&gt;
	&lt;/table&gt;

	&lt;table name=&quot;t1002_states&quot; id-column-names=&quot;c1002_state_id&quot; sequence-key=&quot;c1002_state_id,false,c1002_state_id&quot; class-name=&quot;State&quot;&gt;
		&lt;column name=&quot;c1002_state_id&quot; data-type=&quot;integer&quot; nullable=&quot;false&quot; property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1002_name&quot; data-type=&quot;string&quot; nullable=&quot;false&quot; property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1002_abbreviation&quot; data-type=&quot;string&quot; nullable=&quot;false&quot; property-name=&quot;abbreviation&quot; /&gt;
	&lt;/table&gt;
&lt;/database-structure&gt;


    Some notes on the above:

1) id-column-names maps is used by &quot;keys()&quot;.
2) sequence-key is used by &quot;sequenceKey()&quot;.
3) The class-name attribute contains the name of the class to use. If not specified, then the table name will be used.
4) The data-type attribute contains a primitive PHP type. It might be useful if it could also contain the name of a class (if it's not a primitive type, then it would be assumed that it's a class and the property would be initialized as $this-&gt;$p = new $dataType($columnValue)).
5) Each &quot;link&quot; tag under a table would specify the links under each table. In the example above, there would be an additional property for the Customer class named &quot;state&quot;, which would be an instance of the State class, which has three other properties: &quot;ID&quot;, &quot;name&quot;, and &quot;abbreviation&quot;.

Let me know what you think and if you have any suggestions.</pre>]]></description>
      <content:encoded><![CDATA[<pre>Actually, I wasn't considering the generator portion, although the generator can also use this XML approach. I am primarily concerned on how the DataObject itself gets its database structure info. There could be an additional setting named &quot;xml_config_file&quot;, or something to that effect, and that file would have the database structure information (it would consolidate the information for the &quot;table()&quot;, &quot;keys()&quot;, &quot;sequenceKey()&quot;, and &quot;links()&quot; methods.

Below is an example of how the XML file could look like. Before viewing it, keep in mind that where I work we have a naming convention of TXXXX_NAME for tables and CXXXX_NAME for columns.


&lt;database-structure&gt;
	&lt;table name=&quot;t1001_customers&quot; id-column-names=&quot;c1001_customer_id&quot; sequence-key=&quot;c1001_customer_id,false,s1001_customer_id&quot; class-name=&quot;Customer&quot;&gt;
		&lt;column name=&quot;c1001_customer_id&quot; data-type=&quot;integer&quot; nullable=&quot;false&quot; property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1001_name&quot; data-type=&quot;string&quot; nullable=&quot;false&quot; property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1001_phone&quot; data-type=&quot;string&quot; nullable=&quot;true&quot; property-name=&quot;phone&quot; /&gt;
		&lt;column name=&quot;c1002_state_id&quot; data-type=&quot;integer&quot; nullable=&quot;true&quot; property-name=&quot;stateID&quot; /&gt;

		&lt;link property-name=&quot;state&quot; column-name=&quot;c1002_state_id&quot; table-name=&quot;t1002_states&quot; table-column-name=&quot;c1002_state_id&quot; /&gt;
	&lt;/table&gt;

	&lt;table name=&quot;t1002_states&quot; id-column-names=&quot;c1002_state_id&quot; sequence-key=&quot;c1002_state_id,false,c1002_state_id&quot; class-name=&quot;State&quot;&gt;
		&lt;column name=&quot;c1002_state_id&quot; data-type=&quot;integer&quot; nullable=&quot;false&quot; property-name=&quot;ID&quot; /&gt;
		&lt;column name=&quot;c1002_name&quot; data-type=&quot;string&quot; nullable=&quot;false&quot; property-name=&quot;name&quot; /&gt;
		&lt;column name=&quot;c1002_abbreviation&quot; data-type=&quot;string&quot; nullable=&quot;false&quot; property-name=&quot;abbreviation&quot; /&gt;
	&lt;/table&gt;
&lt;/database-structure&gt;


    Some notes on the above:

1) id-column-names maps is used by &quot;keys()&quot;.
2) sequence-key is used by &quot;sequenceKey()&quot;.
3) The class-name attribute contains the name of the class to use. If not specified, then the table name will be used.
4) The data-type attribute contains a primitive PHP type. It might be useful if it could also contain the name of a class (if it's not a primitive type, then it would be assumed that it's a class and the property would be initialized as $this-&gt;$p = new $dataType($columnValue)).
5) Each &quot;link&quot; tag under a table would specify the links under each table. In the example above, there would be an additional property for the Customer class named &quot;state&quot;, which would be an instance of the State class, which has three other properties: &quot;ID&quot;, &quot;name&quot;, and &quot;abbreviation&quot;.

Let me know what you think and if you have any suggestions.</pre>]]></content:encoded>
      <dc:date>2005-05-14T21:35:42-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-13+23%3A36%3A02#2005-05-13+23%3A36%3A02">
      <title>alan_k [2005-05-14 03:36]</title>
      <link>http://pear.php.net/bugs/3256#1116041762</link>
      <description><![CDATA[<pre>[copy of email on the subject]

If I understand correctly, the idea is that you have a map, used by the
code generator that creates a Class name which may be different to the
table name:

eg. 

class MyClass extends DB_DataObject {
        var $_table = &quot;someothername&quot;;
}

and you would need the generator to use some kind of map:
ClassName    TableName
_________    _________
MyClass      someothername
XXXXXXX      YYYYYYYYYYYYY
.....

- From DataObjects perspective, the best way to handle this would be to do
something like:

generator_classtable_map = ........


where the value of generator_classtable_map could be
a)  A string - probably a filename of a wddx formated file
b)  An array - which could be loaded from an xml file or whatever using
a modified createTables.php script..

DBDO doesnt have a generator yet.. ;) - It's not actually 'as' esential,
although it would probably be a usefull tool..

Let me know you thoughts..
Regards
Alan</pre>]]></description>
      <content:encoded><![CDATA[<pre>[copy of email on the subject]

If I understand correctly, the idea is that you have a map, used by the
code generator that creates a Class name which may be different to the
table name:

eg. 

class MyClass extends DB_DataObject {
        var $_table = &quot;someothername&quot;;
}

and you would need the generator to use some kind of map:
ClassName    TableName
_________    _________
MyClass      someothername
XXXXXXX      YYYYYYYYYYYYY
.....

- From DataObjects perspective, the best way to handle this would be to do
something like:

generator_classtable_map = ........


where the value of generator_classtable_map could be
a)  A string - probably a filename of a wddx formated file
b)  An array - which could be loaded from an xml file or whatever using
a modified createTables.php script..

DBDO doesnt have a generator yet.. ;) - It's not actually 'as' esential,
although it would probably be a usefull tool..

Let me know you thoughts..
Regards
Alan</pre>]]></content:encoded>
      <dc:date>2005-05-14T03:36:02-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-05-13+23%3A07%3A21#2005-05-13+23%3A07%3A21">
      <title>jrhernandez05@... [2005-05-14 03:07]</title>
      <link>http://pear.php.net/bugs/3256#1116040041</link>
      <description><![CDATA[<pre>I'm currently facing the same issue as the original poster, in which all the tables in my database have a prefix (e.g. T5010_ARTICLES) which I do not want in my class name (I just want an &quot;Articles&quot; class).

The problem with having an overridable method such as &quot;className&quot; is that it won't be used in most cases. The reason is that the DataObjects are created through the &quot;factory&quot; method, which is static. Other packages such as DB_DataObject_FormBuilder (which I also use) instantiate objects through this method.

Hence, an overridable method is not the solution. What I propose is having another config option, such as &quot;xml_config_file&quot;, that when specified would instruct the DB_DataObject to get the settings from this XML file. This XML file would contain the following:

- Table to class name and file name mappings
- Column name mappings (would map a column name to a property name)
- Link information (no separate db.links.ini file)

I will be more than glad to provide this patch, but having just seen the DBDO PECL package (which looks very good, BTW), it would not seem reasonable to provide this functionality if DBDO, which will replace DB_DataObject, won't have something similar. I think DBDO should also have this feature, since all references to a table/column name will be in just one file, and abstracted elsewhere. If it could/will be included in DBDO, then I will start working on it...</pre>]]></description>
      <content:encoded><![CDATA[<pre>I'm currently facing the same issue as the original poster, in which all the tables in my database have a prefix (e.g. T5010_ARTICLES) which I do not want in my class name (I just want an &quot;Articles&quot; class).

The problem with having an overridable method such as &quot;className&quot; is that it won't be used in most cases. The reason is that the DataObjects are created through the &quot;factory&quot; method, which is static. Other packages such as DB_DataObject_FormBuilder (which I also use) instantiate objects through this method.

Hence, an overridable method is not the solution. What I propose is having another config option, such as &quot;xml_config_file&quot;, that when specified would instruct the DB_DataObject to get the settings from this XML file. This XML file would contain the following:

- Table to class name and file name mappings
- Column name mappings (would map a column name to a property name)
- Link information (no separate db.links.ini file)

I will be more than glad to provide this patch, but having just seen the DBDO PECL package (which looks very good, BTW), it would not seem reasonable to provide this functionality if DBDO, which will replace DB_DataObject, won't have something similar. I think DBDO should also have this feature, since all references to a table/column name will be in just one file, and abstracted elsewhere. If it could/will be included in DBDO, then I will start working on it...</pre>]]></content:encoded>
      <dc:date>2005-05-14T03:07:21-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/3256/2005-01-20+18%3A56%3A23#2005-01-20+18%3A56%3A23">
      <title>alan_k [2005-01-20 23:56]</title>
      <link>http://pear.php.net/bugs/3256#1106265383</link>
      <description><![CDATA[<pre>messing with the table/class case was an early design decision, that looks less clever in hindsight (DBDO wont be doing it..)

$string = $do-&gt;className($tablename);
$string = $do-&gt;fileName($tablename);

looks like a good addition. (patches welcome), otherwise you may have to wait a while.</pre>]]></description>
      <content:encoded><![CDATA[<pre>messing with the table/class case was an early design decision, that looks less clever in hindsight (DBDO wont be doing it..)

$string = $do-&gt;className($tablename);
$string = $do-&gt;fileName($tablename);

looks like a good addition. (patches welcome), otherwise you may have to wait a while.</pre>]]></content:encoded>
      <dc:date>2005-01-20T23:56:23-00:00</dc:date>
    </item>
</rdf:RDF>