Home » Database » DB_DataObject » Bug #7005
class_prefix will be ignored
Details
| Submitted | 2006-03-03 09:07 UTC |
|---|---|
| From | skr at condero dot com |
| Status | Bogus |
| Package | DB_DataObject |
| PHP Version | 5.0.3 |
| OS | Suse Linux 10.0 |
| Roadmaps | (Not assigned) |
Comments
[2006-03-03 09:07 UTC] skr at condero dot com
Description:
------------
If i set a class_prefix, then DataObject/Generator will be ignore this.
Test script:
---------------
My dbms.ini:
[DB_DataObject]
database=mysql://xxx:xxx@xxx/xxx
schema_location = /home/skr/svn_work_copy/cms/trunk/classes
class_location = /home/skr/svn_work_copy/cms/trunk/classes
require_prefix = classes/
class_prefix = CMS_
Expected result:
----------------
I expect generated classes in directory "classes" with class_prefic "CMS_" such as "CMS_Language" for database-table "language"
Actual result:
--------------
I got generated classes without class_prefix.
The simple reason : file Generator.php of package DB_DataObject contains fowwow code:
function generateClasses()
{
//echo "Generating Class files: \n";
$options = &PEAR::getStaticProperty('DB_DataObject','options');
$base = $options['class_location'];
if (strpos($base,'%s') !== false) {
$base = dirname($base);
}
if (!file_exists($base)) {
require_once 'System.php';
System::mkdir(array('-p',$base));
}
$class_prefix = $options['class_prefix'];
if ($extends = @$options['extends']) {
$this->_extends = $extends;
$this->_extendsFile = $options['extends_location'];
}
foreach($this->tables as $this->table) {
$this->table = trim($this->table);
$this->classname = $class_prefix.preg_replace('/[^A-Z0-9]/i','_',ucfirst($this->table));
$i = '';
if (strpos($options['class_location'],'%s') !== false) {
$outfilename = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i','_',ucfirst($this->table)));
} else {
$outfilename = "{$base}/".preg_replace('/[^A-Z0-9]/i','_',ucfirst($this->table)).".php";
}
$oldcontents = '';
if (file_exists($outfilename)) {
// file_get_contents???
$oldcontents = implode('',file($outfilename));
}
$out = $this->_generateClassTable($oldcontents);
$this->debug( "writing $this->classname\n");
$fh = fopen($outfilename, "w");
fputs($fh,$out);
fclose($fh);
}
//echo $out;
}
this means , class_prefix is processed ($class_prefix = $options['class_prefix'];), but never used ($outfilename = "{$base}/".preg_replace('/[^A-Z0-9]/i','_',ucfirst($this->table)).".php";