Rewriting Symphony in Perl

Rewrite Symphony in Perl?

What a ridiculous idea.

Yeah. Pretty much. But if I’m going to spend some time learning how to program in PHP and Perl, what better way to pay homage to the best content management system I’ve ever had the pleasure to use. Problem is, it’s always a work in progress. I’ve been spending time with Symphony 2 Beta Revision 5, building XSLT templates for a number of applications. These can be saved as what are called “Ensembles”, a ZIP file containing all you need to install the application in seconds on the PHP, MySQL and XSL enabled server of your choice. Of course, they are all crippled, unfinished example applications of what can be developed with Symphony. As soon as I discovered that the Beta version will be incompatible with Release Candidate 1, I lost interest in continuing the development of these ensembles, at least for the moment.

Symphony Ensembles

I’d like to get to a point that I can build my own Symphony Extensions, so I’d like to understand what’s going on under the hood. If I can translate from one language to another, I think I’ll have a pretty good grasp of how the application works.

So, where to start. I figured the configuration file would be a good place to start. I first need to know how to translate the variables the will be necessary to interact with the database and file system.

Probably not the simplest place to start, since it appears that the configuration settings are stored as a multidimensional array in the configuration file. Consulting with Larry Wall’s book, Programming Perl, published by O’Reilly, I found a section on hashes of hashes. So, I came up with a couple ways I could generate code that could duplicate the Symphony configuration settings.

#!/opt/local/bin/perl
# Symperl Configuration File

# To simulate the multidimensional array used for Symphony's 
# configuration settings, use hashes of hashes to define values

# %settings = (
# 	admin => {
# 		max_upload_size => "5242880",
# 	},
# 	symphony => {
# 		pagination_maximum_rows => "17",
# 		allow_page_subscription => "1",
# 		lang => "en",
# 		build => "2000",
# 		cookie_prefix => "sym-",
# 	},
# 	log => {
# 		archive => "1",
# 		maxsize => "102400",
# 	},
# 	general => {
# 		sitename => "Symperl: Symphony in Perl",
# 		useragent => "Symperl/1000",
# 	},
# 	image => {
# 		cache => "1",
# 		quality => "90",
# 	},
# 	database => {
# 		driver => "mysql",
# 		character_set => "utf8",
# 		character_encoding => "utf8",
# 		runtime_character_set_alter => "0",
# 		disable_query_caching => "no",
# 		host => "localhost",
# 		port => "3306",
# 		user => "root",
# 		password => "",
# 		db => "sym2_beta",
# 		tbl_prefix => "sym_",
# 	},
# 	public => {
# 		maintenance_mode => "no",
# 	},
# 	region => {
# 		time_format => "g:i a",
# 		date_format => "j F Y",
# 		timezone => "America/Vancouver",
# 	},
# 	file => {
# 		write_mode => "0777",
# 	},
# 	directory => {
# 		write_mode => "0755",
# 	},
# );

# Hashes can also be created by defining values in this way
# $settings{admin}{username} = "stephen";

# To emulate Symphony's configuration settings
# declare $settings as above

$settings{admin}{max_upload_size} = '5242880';
$settings{symphony}{pagination_maximum_rows} = '17';
$settings{symphony}{allow_page_subscription} = '1';
$settings{symphony}{lang} = 'en';
$settings{symphony}{build} = '2000';
$settings{symphony}{cookie_prefix} = 'sym-';
$settings{log}{archive} = '1';
$settings{log}{maxsize} = '102400';
$settings{general}{sitename} = 'Spectrum: Symphony Theme';
$settings{general}{useragent} = 'Symphony/2000';
$settings{image}{cache} = '1';
$settings{image}{quality} = '90';
$settings{database}{driver} = 'mysql';
$settings{database}{character_set} = 'utf8';
$settings{database}{character_encoding} = 'utf8';
$settings{database}{runtime_character_set_alter} = '0';
$settings{database}{disable_query_caching} = 'no';
$settings{database}{host} = 'localhost';
$settings{database}{port} = '3306';
$settings{database}{user} = 'root';
$settings{database}{password} = '';
$settings{database}{db} = 'sym2_beta';
$settings{database}{tbl_prefix} = 'sym_';
$settings{public}{maintenance_mode} = 'no';
$settings{region}{time_format} = 'g:i a';
$settings{region}{date_format} = 'j F Y';
$settings{region}{timezone} = 'America/Vancouver';
$settings{file}{write_mode} = '0777';
$settings{directory}{write_mode} = '0755';


# Print configuration settings, Symphony style
# (Required a lot of character escaping for single quotes)
foreach $setting_type ( keys %settings ) {
	foreach $setting_value (keys %{ $settings{$setting_type} } ) {
		print '$settings[\'', "$setting_type", '\'][\'', "$setting_value", '\'] = \'', "$settings{$setting_type}{$setting_value}", '\';', "\n";
	}
}

# Awesome. It works!

Running this code on the command line produced output identical to the list of settings in the config.php file.


About this entry