On Fri, Aug 3, 2012 at 2:50 PM, Andrew Ballard <[email protected]> wrote:
> I am trying to streamline application configuration and bootstrapping
> in our projects to make deployment and updates easier. As I look at
> the format for resources in configuration files, I wonder whether
> there is some way that a property of one resource could be pointed
> toward another reference directly in the configuration without having
> to write custom resource plugins, modifying the bootstrap, or
> duplicating settings in multiple sections. Is there a way to do
> something like this?
>
> resources.mail.transport.type = smtp
> resources.mail.transport.host = my-smtp-host
>
>
> resources.db.params.host = my-db-host
> resources.db.params.username = testuser
> resources.db.params.password = ********
> resources.db.profiler.enabled = true
> resources.db.profiler.class = Zend_Db_Profiler_Firebug
>
>
> resources.log.db.writerName = Db
> resources.log.db.writerParams.db = <<<<<<<<<<<<<<<<< REFERENCE TO
> resources.db
> resources.log.db.writerParams.table = logTable
> resources.log.db.writerParams.columnMap.timestamp = timestamp
> resources.log.db.writerParams.columnMap.priority = priority
> resources.log.db.writerParams.columnMap.priorityName = priorityName
> resources.log.db.writerParams.columnMap.message = message
> resources.log.db.filterName = Priority
> resources.log.db.filterParams.priority = Zend_Log::INFO
>
> resources.log.mail.writerName = Mail
> resources.log.mail.writerParams.charset = UTF-8
> resources.log.mail.writerParams.subjectPrependText = Application Error
> resources.log.mail.writerParams.transport <<<<<<<<<<<<<<<<< REFERENCE
> TO resources.mail
> resources.log.mail.filterName = Priority
> resources.log.mail.filterParams.priority = Zend_Log::WARN
>
>
>
> resources.session.use_only_cookies = true
> resources.session.cookie_httponly = true
> resources.session.name = app_session
> resources.session.saveHandler.class = My_Session_SaveHandler_CustomDb
> resources.session.saveHandler.params.db = <<<<<<<<<<<<<<<<< REFERENCE
> TO resources.db
>
>
>
> Andrew
I have a start to a solution that looks like it might work. As it
turns out, the mail transport portion is unnecessary. (I thought it
should be, but didn't see it in the code until recently. That leaves
the DB adapter in Zend_Log and Zend_Session_SaveHandler_*. Here is
what I've done to get the log portion working. Something similar
should work for the session save handler, but I wanted to get some
feedback on the approach so far.
Given that this must all happen at such an early, low-level part of
the request cycle, what is the best approach for handling errors?
Is this something that might be useful enough to propose adding to the core?
<?php
class My_Application_Resource_Log extends Zend_Application_Resource_Log
{
/**
* Initializes the plugin
*/
public function init()
{
$options = $this->getOptions();
foreach ($options as $key => $logwriter) {
if (isset($logwriter['writerName'])) {
$writerName = strtolower($logwriter['writerName']);
switch ($writerName) {
case 'db':
if (isset($logwriter['writerParams']) &&
is_array($logwriter['writerParams']) &&
isset($logwriter['writerParams']['db'])) {
$db_config =
$logwriter['writerParams']['db'];
if ('resources.db' ==
$db_config) {
// resources.db
resource plugin
$this->getBootstrap()->bootstrap('Db');
$resource =
$this->getBootstrap()->getPluginResource('Db');
$dbAdapter =
$resource->getDbAdapter();
} elseif (0 ===
stripos($logwriter['writerParams']['db'],
'resources.multidb.')) {
// resources.multidb.*
resource plugin
$this->getBootstrap()->bootstrap('MultiDb');
if (false !== ($db_id =
substr($logwriter['writerParams']['db'], 18))) {
$resource =
$this->getBootstrap()->getPluginResource('multidb');
$dbAdapter =
$resource->getDb($db_id);
}
} else {
$dbAdapter =
Zend_Db::factory($logwriter['writerParams']['db']);
}
$options[$key]['writerParams']['db'] = $dbAdapter;
}
break;
}
}
}
$this->setOptions($options);
return parent::init();
}
}
?>
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]