DK
unread,Oct 19, 2011, 8:36:34 AM10/19/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Alloy
Ok, so I have 3 custom objects I needed to integrate and decided not
to use the plugin architecture, since these are core functions of the
app.
1. My custom db layer that wraps extends PDO
2. My custom memcache client
3. My custom sessions object which leverages memcached for distributed
sessions (using web server cluster for this app)
I have placed these 3 class files in the app\lib\App folder directly
and decided to instantiate them at the bottom of the init.php script.
Which works fine.
So my questions are:
1. Should I be using a different technique to integrate these classes?
2. If this structure makes sense, is the init.php the right place add
them the Kernel?
Below is my init lines added to the bottom of the init.php script.
#Init MySQL db objects
#Get params from config
$masterHost = $kernel->config('app.database.master.host');
$dbName = $kernel->config('app.database.master.database');
$adapter = $kernel->config('app.database.master.adapter');
#Create master
$tmpdb = new App\Database("$adapter:host=$masterHost;dbname=$dbName"
,$kernel->config('app.database.master.username')
,$kernel->config('app.database.master.password')
);
$kernel->addMethod('master', function() use($tmpdb) {
return $tmpdb;
});
#Create a slave
$slaveHost = $kernel->config('app.database.slave.host');
$tmpdb = new Alloy\Database("mysql:host=$slaveHost;dbname=$dbName"
,$kernel->config('app.database.master.username')
,$kernel->config('app.database.master.password')
);
$kernel->addMethod('slave', function() use($tmpdb) {
return $tmpdb;
unset($tmpdb);
#Init memcache client obj
$tmpCache = new App\Cache($kernel->config('app.memcached.servers'));
$kernel->addMethod('cache', function() use($tmpCache) {
return $tmpCache;
});
unset($tmpCache);
#Init session mgt object
$tmpSession = new App\Session();
$kernel->addMethod('session', function() use($tmpSession) {
return $tmpSession;
});
unset($tmpSession);
Again, thanks much for any input.
DK