*importing* creole into ZenMagick
Today I spend some time massaging Creole to properly load in ZenMagick using either ZMLoader or as part of core.php.
There were a number of issues I ran into:
includeandrequirestatements in Creole sources rely on the PHP include_path- Some files are missing the closing ‘?>’
- DebugConnection.php does not include/require Connection.php, breaking the otherwise perfect dependencies
- Record.php includes a require for QueryDataSet.php which actually creates some sort of circular dependency loop, since QueryDataSet.php also depends on Record.php…
#1 was to be expected in one form or another, so it wasn’t really an issue.
#2 is actually something I do not really understand, but then, I never had the time/energy to read the PHP specs to figure out why this is working at all. If you know, feel free to leave a comment…
#3 turned out to be a problem, because in order to be able to include all files in core.php I had to rearrange all source files based on dependency. A short script that build a simple dependency tree was easily done based on include/require statements, except for this one file (which I ended up hardcoding in the script…)
#4 was really annoying because it meant that initially I had to patch Record.php in order to get all files loaded at all using the include_path solution (which is the documented way of installing Creole!) . Eventually I changed my *import* script to load the files from a non ZenMagick folder, so no initial loading was done.
One thing that might come out of this exercise is that hopefully I will have time to split ZMCoreCompressor into a generic class and a ZenMagick specific subclass. That should allow me to easily build a single file Creole version that can then be included in ZenMagick versions instead of the full 90 odd single files (this is version 1.1). I might strip this down, though, excluding all non MySql drivers as there is currently no point loading them…
One really nice thing I discovered was that Creole follows a concept of filename-classname relationship very similar to ZenMagick. That definitely made it a lot easier!

#2 I seem to recall just reading somewhere that if the end closing tag is left out it will be assumed and automatically closed.
The rest I have no idea about!
I’m in around PHP 202 and MySQL 101 right now, learning-wise. I’m reading Larry Ullman’s PHP and MySQL For Websites, plus about 8 other programming books. I went nuts at Amazon and bought a shed load of programming books instead of paying a ton of money on tuition somewhere!
I am very impressed by what you have accomplished and I am determined that in the next couple of years I will be able to work similar wonders with code!
Keep up the great work!
Matt
Comment by lankeeyankee — April 3, 2008 @ 1:10 am
The missing trailing PHP tags are by design. Spurious whitespace after the closing tag can wind up becoming part of the page output, making it harder to do things like issue headers.
It’s a fairly common practice to leave them off in frameworks and in multi-developer projects where different editors are being used by different developers. Tracking down some file with whitespace after the closing tag is a lot harder than having PHP assume the close at EOF.
Comment by instance — April 6, 2008 @ 11:24 pm
Hey, that makes sense! Thanks to both of you.
In fact, I have suffered from those whitespace issues a few times and they are really a big pain.
Thankfully, it was relatively easy to apply a *fix* for this problem during my import. That means if you want to you can have Creole automatically compressed and merged into a single file
One other thing that actually came out only after I posted this article is that due to the fact that I change the directory structure, Creoles ‘dot-notation’ does not work any more. So right now the setup code to obtain a zen-cart database connection looks like this:
Creole::registerDriver(’mysql’, ‘MySQLConnection’);
$dsn = array(’phptype’ => ‘mysql’,
‘hostspec’ => DB_SERVER,
‘username’ => DB_SERVER_USERNAME,
‘password’ => DB_SERVER_PASSWORD,
‘database’ => DB_DATABASE);
$this->conn_ = Creole::getConnection($dsn);
Comment by DerManoMann — April 7, 2008 @ 1:30 am