|
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 -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
|
Hmm. Nothing? Is there a better way to do this then?
On Fri, Aug 3, 2012 at 2:50 PM, Andrew Ballard <[hidden email]> 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 -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
|
This is something that cannot really be done with application resources...
You'd have to override the application resource itself to allow that. Marco Pivetta http://twitter.com/Ocramius http://marco-pivetta.com On 14 August 2012 20:34, Andrew Ballard <[hidden email]> wrote: > Hmm. Nothing? Is there a better way to do this then? > > On Fri, Aug 3, 2012 at 2:50 PM, Andrew Ballard <[hidden email]> 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 > > -- > List: [hidden email] > Info: http://framework.zend.com/archives > Unsubscribe: [hidden email] > > > |
|
2012/8/14 Marco Pivetta <[hidden email]>
> This is something that cannot really be done with application resources... > You'd have to override the application resource itself to allow that. > > Marco Pivetta > I guess you might have more luck with php array configuration since you could store variables and use them at several places. Then the reuse of database credentials is not requiring duplicate values anymore. -- Jurian Sluiman |
|
On 14/08/12 21:52, Jurian Sluiman wrote:
> 2012/8/14 Marco Pivetta <[hidden email]> > >> This is something that cannot really be done with application resources... >> You'd have to override the application resource itself to allow that. > > I guess you might have more luck with php array configuration since you > could store variables and use them at several places. Then the reuse of > database credentials is not requiring duplicate values anymore. Hope I haven't misunderstood the problem, but aren't you using the registry to store the database credentials? That might be worth a look... If you're not doing that/tempted, how about instead just grabbing those database credentials into a function and calling that? // Database connection function function connect_db() { // Include() the Zend config so we can grab the db vars $path = realpath($_SERVER['DOCUMENT_ROOT'].'/../library/'); // we have already updated the include path... require_once 'library/Zend/Config/Ini.php'; $db_config = new Zend_Config_Ini('../config/databases.ini','production'); // Database Credentials $db_config_username = $db_config->db->mydb->config->username; $db_config_password = $db_config->db->mydb->config->password;; $db_config_dbname = $db_config->db->mydb->config->dbname; $db_config_host = $db_config->db->mydb->config->host; // use MySQL by default $cmsLink = mysql_connect($db_config_host,$db_config_username,$db_config_password); if($cmsLink) $dbConn = mysql_select_db($db_config_dbname,$cmsLink); return $dbConn; } This example assumes a functions file is sitting outside of (above) the docroot. You may need to adjust the paths as necessary. The corresponding config file (config/databases.ini) would look something like this: [production] ;; My database db.mydb.adapter = "PDO_MYSQL" db.mydb.config.host = "localhost" db.mydb.config.username = "username" db.mydb.config.password = "password" db.mydb.config.dbname = "your-db" db.mydb.config.port = 3306 You could then include() the functions file in your code. A call to connect_db() function would either return the database object or MySQL error. Then you could keep your db credentials in the one ZF config file but use them across the application. Kind regards, Steve -- Steve Dowe Warp Universal http://warp2.me/sd -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
|
On Thu, Aug 16, 2012 at 11:09 AM, Steve Dowe <[hidden email]> wrote:
> Hope I haven't misunderstood the problem, but aren't you using the > registry to store the database credentials? That might be worth a look... > > If you're not doing that/tempted, how about instead just grabbing those > database credentials into a function and calling that? > > // Database connection function > function connect_db() { > > // Include() the Zend config so we can grab the db vars > $path = realpath($_SERVER['DOCUMENT_ROOT'].'/../library/'); > // we have already updated the include path... > require_once 'library/Zend/Config/Ini.php'; > $db_config = new Zend_Config_Ini('../config/databases.ini','production'); > > // Database Credentials > $db_config_username = $db_config->db->mydb->config->username; > $db_config_password = $db_config->db->mydb->config->password;; > $db_config_dbname = $db_config->db->mydb->config->dbname; > $db_config_host = $db_config->db->mydb->config->host; > > // use MySQL by default > $cmsLink = > mysql_connect($db_config_host,$db_config_username,$db_config_password); > > if($cmsLink) > $dbConn = mysql_select_db($db_config_dbname,$cmsLink); > > return $dbConn; > > } > > This example assumes a functions file is sitting outside of (above) the > docroot. You may need to adjust the paths as necessary. > > The corresponding config file (config/databases.ini) would look > something like this: > > [production] > ;; My database > db.mydb.adapter = "PDO_MYSQL" > db.mydb.config.host = "localhost" > db.mydb.config.username = "username" > db.mydb.config.password = "password" > db.mydb.config.dbname = "your-db" > db.mydb.config.port = 3306 > > > You could then include() the functions file in your code. A call to > connect_db() function would either return the database object or MySQL > error. > > Then you could keep your db credentials in the one ZF config file but > use them across the application. > > Kind regards, > Steve > > -- > Steve Dowe Steve, I'm trying to work with the config structure used by Zend_Application_Resource plugins during the bootstrap process. I've been able to load nearly all of the configurable information with settings in that file, completely eliminating the need for editing files when we move code through our change management process from development to production. There are just these couple instances, though, where I need to inject one resource into another where I have had to rely on creating custom resource plugins. I was hoping to get to reduce the amount of custom core extensions I need to use, but it doesn't look like what I want to do is possible. Andrew -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
|
In reply to this post by Andrew Ballard
> Hmm. Nothing? Is there a better way to do this then?
You could take a look at Yaml and use the Symfony Yaml parser for loading configuration files. I've used it in recent ZF1 projects as Zend_Config_Yaml doesn't work with keys that contain backspaces and it works well. As far as I know, there's the concept of anchors in Yaml. Can't tell though if the Symfony parser supports it. Best regards, Andreas -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
|
In reply to this post by Andrew Ballard
On Fri, Aug 3, 2012 at 2:50 PM, Andrew Ballard <[hidden email]> 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: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
| Powered by Nabble | Edit this page |
