Die Flagge des Marasek

Dekostreifen

English

Aktuell Texte Der Comic Impressum Kalender Suche PHP-Klassen Container-Wizard main.s21

Kategorien

Buch
Computer
Computerspiele
Film
Geschichte
Gesellschaft
Idee
Kunst
Natur
Persönlich
Politik
Programmieren
Religion & Philosophie
Weblog
Weltpolitik
Weltsicht
{{login}}

Container Generator Help

The Container Wizard generates typical Container classes consisting mainly of getters/setters. This is a logical consequence of not wanting to resort to __get/__set, but being to lazy to write the same over and over again.
Personally, I always write every (or now: have it written) getter/setter, as the code then starts to document itself, as seen in the fact that ie. Eclipse offers you what's there instead of leaving you to figure out which values the container expects or having to read the documentation.

Type

Offers two choices as of yet:

Simple Container
The simple container is a standalone class that will store all values within class properties.
Child of Registry
This container will extend Registry (it is part of a bigger package that is not available as of yet, but can be used standalone). All values will then be stored within a private property of Registry. This allows for extended exception handling:
  • Registry::lock()
    Once Registry is locked, calling setters will raise an Exception. This effectively counters the threat of the "Action at a distance" anti-pattern that is prone to happen when team members override Singleton/Registry values for the sake of a "quick fix".
    When locking, Registry also checks whether all required values have been set or not.
  • Registry::setRequired()
    setRequired() defines an array of values that have to be set to have a completed class (I've seen people accessing global variables without even caring whether they have been set or not). It is to be called in the constructor of the inheriting class.
    An Exception will be cast when lock() or ANY getter is called AND the requirements are not met.
Class name
Pretty straightforward: enter the name of your desire here.
Visibility
When using Simple Container, the visibility controls whether the properties should be private (sane default), protected or public
Singleton
  • Standard
    Class is no Singleton
  • Singleton
    Class is a Singleton
  • Singleton static getters
    The getters are static, so instead of writing Class::getInstance()->getParameter(); you can have it shorter with Class::getParameter();.
Paranoid Singleton
Makes the Singleton paranoid in a way that you have to discern between first call (getFirstInstance) and subsequent calls (getInstance); Doing so, you cannot receive a "virgin instance" when you're expecting a usable singleton.
Values
Enter the desired values here. When using "Child of Registry", these will be set as required using setRequired in the class constructor, when using Simple Container, they will be defined as properties.

Things left to do (for you):

You should make use of PHP's type hinting within the setters where appropriate and do further plausibility checks within the method's body.
Also, setRequired() might be too strict for you in some cases.