dlite922 1,584
Recognized Expert Top Contributor
(My ultimate question is not PHP related, but since its programmed in PHP, here it goes)
I'm working on a PHP class that will read a semi-standard style of config file. I'm stuck at a point on how to expand to a three level deep value.
Config file right now looks like any other config file you've seen, such as PHP's php.ini or Apache's http.conf Example File -
-
# comments begin with a hash symbol
-
#
-
[section_name]
-
setting=value
-
multi=value1,value2,value3
-
-
# this is the second section
-
[second_section]
-
foo=false
-
bar=true
-
-
This file will be passed to the class constructor and then it can be used, using the above config file, like so: Final Goal: -
-
$config = new Config('myFile.cfg');
-
-
// outputs "value"
-
echo $config->section_name->setting
-
-
// outputs an array of values (not just comma separated)
-
echo $config->section_name->multi
-
-
// throws error, cannot override value of foo
-
$config->second_section->foo = true
-
-
As you can see, this is 2 dimensional and works fine for most cases, but I have a different config need: what I call 2.5 dimensional :P (stop laughing, it's five o'clock and I'm burnt out)
Everything better by example:
I have an app that get's it data source from multiple places that the user selects from the drop down. Those two places are separate mysql database with identical schema, one for "live" production feed, one for "offline" testing feed.
I want to put these sources in a config along with their mysql login WITHOUT making the source name the "section_na me". Reason: I don't want the app to know what those source names are, (e.g. if they change or add a third source, i'd have to change my code)
So to build my drop down, i'd have to read the entire config directory and parse through all the sections (there are others that are not 'sources') and see which ones are sections, then get their names, and display it in the drop down menu for the user to select (BLEGH! ugly!)
I'd like a config layout that simply gives me the source names (that can later be used as a key to get the MySQL login, etc)
something like.... -
-
$sourceArray = array_keys($config->sources);
-
// build <select><options>
-
-
then alter access it with the selected source:
-
$sourceSettings = $config->sources->$selectedSource;
-
-
// then VOILA!! we have:
-
mysql_connect($sourceSettings->db_user, $soruceSettings->db_pass, etc);
-
-
Wheew!! sorry for long post.
So! Any Ideas for a (standard-style) config file layout my fried brain can't think of?
Da
3 1627 Atli 5,058
Recognized Expert Expert
Hi.
Couldn't you just do something like: -
[db_section]
-
sources='live server','test server'
-
hosts='db.example.com','localhost'
-
schemas='liveDbName','localDbName'
-
loginNames='liveUser','localUser'
-
loginPasswords='livePass','localPass'
It's not exactly perfect but it's simple, and it fits into the configuration syntax you posted.
Would be easy to work with in PHP.
Or you could go with something more like how an array would be written: -
[db_section]
-
sources = {
-
'live server' : {
-
'host' : 'db.example.com',
-
'schema' : 'liveDbName',
-
# etc...
-
},
-
'testserver' : {
-
'host' : 'db.localhost',
-
'schema' : 'localDbName',
-
# etc...
-
}
-
}
A lot more flexible, but more complex. Perhaps not something you would want to see in a config file.
Or you could do something like sub-sections: -
[db_section::live_server]
-
name="Live server of DOOM"
-
host="db.example.com"
-
#etc...
-
-
[db_section::local_server]
-
name="Local server"
-
host="db.localhost"
-
#etc...
-
Endless possibilities :P
dlite922 1,584
Recognized Expert Top Contributor
:P to you too.
For the sake of not making my post into a novel, I didn't post what I had already thought about and reasons why it might* not work.
The two I tried were your first and last one.
Reasons for first one:
Users would mess up and trying to align, which password goes with which. The values are not clearly apparent as they are in your example, also there might be more than two, which gets even gets messier. But If I had to choose one, I think, I'd go this route.
second one:
How would I easily parse through and the all the source names (to display in the drop down), without having to get all the db_sections with a regex then parse out the db_sections.
I gotta go, but I'll come back in a bit to continue.... @Atli dlite922 1,584
Recognized Expert Top Contributor
....i'm back...
I'm thinking more about coding the third one. Specifically about how I would put that into PHP code for the program to use WITHOUT hard coding the sub_section/source into the data.
maybe: $config->db_section->$selectedSourc e->host
Yes! that will work. I think I touched this in the OP and didn't connect the dots.
Thanks Atli for making me brainstorm this. I'll attack it, create a class and maybe put an article in about it.
See ya,
Dan
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: chokk |
last post by:
All,
I am getting the following error when I try to run a form page. Can someone
tell me what this is about and show me how to fix it. Thnaks.
Server Error in '/' Application
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a configuration file
required to service this request. Please review the specific error details
below and...
|
by: rdcpro |
last post by:
Hi all,
I've been building a nifty deserializing configuration handler that I use in
conjunction with my web.config in an ASP.NET web app. This is working quite
well, but I'm planning on servicing a number of different web service
operations from a single application, and because it's all XML, I've been
scoping everything to a specific namespace targeting a specific application
(these are all InfoPath forms).
It seems that the...
|
by: Ramanfromoz |
last post by:
Hi,
Developing a new we application. Everything okay on my local WIN XP
PROFESSIONAL, IIS 5.0 running locally. The website is running smoothly.
Now, the same code I am copying over to a WINDOWS 2003 SERVER, I
created a new website, allocated port number 6000. Created a release
version on my local machine and copied the WEB project from my local to
http://ACTYD003:6000
|
by: Rider |
last post by:
Hi, simple(?) question about asp.net configuration..
I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm
first start application the follow message shown.
=========
Server Error in '/QuickStartv20' Application.
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a configuration file
|
by: js |
last post by:
I am getting the following error when enter my web site's url in the
browser address bar. I could not even get to the first default page of
my web site. All this happened after I recompiled the
Microsoft.Practices.EnterpriseLibrary with newer minor version number
and my public key token. I added the new DLL in the server's Assembly
Cache using .Net Framework 1.1 Configuration utility. Here is what my
new Assembly Cache look like. The...
| |
by: Alan T |
last post by:
I want to store some values so that the application can read from a file,
eg. ini file, configuration file.
If I add a Application Configuration File, to store the name of files:
key = "sales"
value = "sales.ini"
key = "account"
value = "account.ini"
|
by: metaperl |
last post by:
A Comparison of Python Class Objects and Init Files for Program
Configuration
=============================================================================
Terrence Brannon
bauhaus@metaperl.com
http://www.livingcosmos.org/Members/sundevil/python/articles/a-comparison-of-python-class-objects-and-init-files-for-program-configuration/view
|
by: Jay |
last post by:
I want to store various text settings in a configuration file, that I will read into C# and make use
of. Here's a simplified example of the file:
#comment
loop(var=1:5){
deviceundertest freq:5.6e6 power:3.7
analyser freq:5.6e6 span:1e3 resbw:100 atten:20
}
As you can see, the configuration file will define:
|
by: aSoundMind |
last post by:
Hi there, I recieve this error
Server Error in '/integrate' Application.
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
|
by: abiclub |
last post by:
This is the error im getting,Is it a problem with versions, Im using the .net framework express edition (3.5) ,if so how do i change it
Server Error in '/Test' Application.
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |