DataObject: Working links.ini and Feature Request
| From: | Alan Knowles | Date: | Thu, 15 Aug 2002 04:10:01 +0000 |
| Subject: | DataObject: Working links.ini and Feature Request | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-8435@lists.php.net to get a copy of this message | ||
I've cc'd it to pear-dev, just in case anyone else wants to throw ideas in :)
comments inline:
Tim White wrote:
I've commited the code to cvs, the DB_DataObject::_staticGetDefinitions(), should autoload the links file, although I've not tested it so let me know if it has any issues.Hi! I've been working a lot more with DataObject, and its been working great. I implemented the links.ini that we discussed, and that you sketched out in the TODO. Attached are the working versions of getLinks and getLink that implement this. Below is what I had to do to set it up. Note that I had added a db_name option. I know you parse it out in the guts of DataObject, but that's after connection, and we need it in the option setting phase. Let me know if you have an idea on how to handle this more cleanly. For example, _staticGetDefinitions might just try and load it automatically. // initialize DataObject $options = &PEAR::getStaticProperty('DB_DataObject', 'options'); $config = parse_ini_file('config/conmaster.ini', true); $options = $config['DB_DataObject']; $db_name = $options['db_name']; $links = &PEAR::getStaticProperty('DB_DataObject', "{$db_name}.links"); $linkConfig = parse_ini_file("config/{$db_name}.links.ini", true); $links = $linkConfig;
basically it's the same code that staticGet uses.Feature Request - I find myself doing a lot of this type of thing: $this->included_table = $this->data['included_table']; require_once('./lib/DataObjects/' . ucwords($this->included_table) . '.php'); $incObjectName = 'DataObjects_' . ucwords($this->included_table); $this->incDataObject = new $incObjectName;try DB_DataObject::staticAutoloadTable($tablename);
I've added a production option to the class, mainly cause when I was profiling it, the debug(), call was getting hammered... I think there may be some way to do this.. if (!DB_DATAOBJECT_PRODUCTION) {Because I don't have the information yet to use staticGet, or more commonly, becuase I'm going to use find(). I'd really love a public factory method that didn't have to perform a search. Even better would be one that didn't require the prefix - i.e. I could just feed it the table name, and it would add on the 'DataObjects_' prefix (since DataObject has it in its config file). Something that you could call like this: $this->incDataObject = DB_DataObject::factory($this->included_table); I would suggest trying to find the class based on Generator's naming conventions and the specified prefix. You could even tweak the database.ini file like this to override the default naming: [note] id = 1 ... [note__keys] id = 1 [note__class] note = DataObjects_Note Finally, it has been somewhat frustrating during development to try and keep <database>.ini and the subclass files in sync with the database in regard to column names, especially since missing columns fail silently. :) I could regenerate everything regularly, I suppose, but then I'd have to paste in all my changes again every time, which would be no less frustrating. The best solution would be to come up with a way to use the class file's property list instead of <database>.ini, but I haven't come up with a perfect way to do this yet, since PHP vars are weakly typed. I'm investigating though.
require_once 'DB/DataObject/Generator.php';
DB_DataObject_Generator::start();
}
inside the staticDefineProduction(); ... - maybe rename this staticInitialize();
regards
alan
Thanks!!! Tim White