views:

322

answers:

2

Hello,

I have tried many PHP MVC frameworks and I noticed that in many frameworks you can do things like this:

$this->security->encodeForHTML();

So, basically there is a class Security, which contains a method encodeForHTML(). Isn't this Security class a singleton? Is there a specific name for this kind of "internal" singleton class?

Because there are other classes that are not singletons:

$form = new Form;

In this case, you can create as many forms as you want. I understand the point of this, it clearly doesn't make sense to initialize many security classes, but I am wondering, are there names for these classes (other than singleton and non-singleton)? One guy suggested to use word "plugins" for those classes that can be created and "libraries" for those, which are built in the framework. Does that make sense?

Thanks for your reply!

+3  A: 

Current MVC fashion/naming convention calls these Helper Classes/Objects, which is orthogonal to singleton/non-singleton, (helpers often are create as a singleton and/or class with static methods, but they don't have to be)

See Zend Documentation for an example.

A plugin isn't quite the right description. Typically plugins are code/programs written by outside parties to leverage and/or extend functionality within a system. A plugin would be more if the system you were using provided a way for YOU to write a security class and have it automatically instantiated and it's methods available to call, and if your security class could call on System APIs in a standard, non-hack way.

Alan Storm
A: 

I agree with that 'one guy' you mentioned in your post.

IMO, it really depends on what kind of MVC framework you are using. I haven't tried other frameworks yet, but in CodeIgniter, this falls under two things, models or libraries. Since models are commonly used to handle informations from the database, I would call this 'security' class you mentioned, a library.

andyk