TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-17-2009, 02:35 PM   #1 (permalink)
The Contributor
 
Ross's Avatar
 
Join Date: Jan 2008
Location: England, UK
Posts: 83
Thanks: 3
Ross is on a distinguished road
Default Some contributions (Registry, application configuration)

I've got some classes that I was previously developing for a personal framework but I think would make a good addition to the app that I'd like to contribute.

Registry
This is a common solution to the globals anti-pattern.

Basically, rather than keeping variables as globals and risk overwriting them, you have a singleton instance of this class created in your bootstrap file. This remembers itself so everytime you call it it knows what's been set in it's datastore.

Class code (pastebin'ed as it's fairly long)
Example usage:
PHP Code:
$registry Registry::getInstance();
$registry->configuration $config// Some config array/object
unset($registry);

// later
$registry->getInstance();
var_dump($registry->configuration);
$dbAdapter = new Database($registry->configuration->database);
$registry->database $dbAdapter;
unset(
$registry); 
This also includes some static methods, such as a class/interface autoloader.

Configuration
This isn't the same as the other config class which appears to load options from the database.

This is a two-parter. It has an abstract base class that is extended based on the file format you want to retrieve data from.

It allows you to use constants in configuration files. However the configuration files must be placed above the document root otherwise they will be publically viewable (and since they will likely contain database data this is bad!). See below.

Abstract Class
INI File extension
Example
PHP Code:
$configuration = new Phlox_Config_Ini(APPLICATION_PATH '/config/app.ini');
var_dump($configuration->database); 
Sample INI File
Code:
[database]
adapter = 'MySQL'
params.dbname = 'phlox'
params.user = 'phlox_user'
params.password = 'password'
params.host' = 'localhost'
Files above document root
Really, all of the includes, etc. should be above the Document Root and publically accessible files (index.php, /js/, /css/) should be the only things below it. This is available on nearly all hosts (including shared hosts - all of mine have done this).

What I suggest is that we have a public directory for front-facing files.
__________________
Ross » Blog » Twitter
Ross is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:36 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design