This is an old revision of the document!
This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)
Programming without global constants and variables.
In the medium term it is planned to build up a 'Registry' in WebsiteBaker. Until this is ready, the class 'WbAdaptor' will take over this task. First of all, the class provides properties that are more or less identical with the previous constants. At the same time, also the old constants are -still- available unchanged for old code, however they may no longer be used for new or revised Code!
Global constants show a fundamental characteristic which very much supports 'lazy' programming: Once declared, they are directly available at absolutely any location of the source code requiring no additional expense. Visibility and scope don't play any role for them. Absolutely 'lazy' programmers abuse constants as variables that, eventually set in sequence, and then are available at no extra transfer in the following functions. The apparent advantages, however, also face significant disadvantages. Security-critical data are never stored in constants. The best negative example in previous WB versions are the credentials for access to the database, which were available in each droplet, each piece of dynamic code of a template etc., absolutely freely accessible for everyone.
Global constants (as well as global variables), used within classes, break up their clear encapsulation and can prevent the reusability of the code. See 'Basics of object-oriented programming'.
Global constants are, as has long been stated, from this version on deprecated, that is undesirable. See: Deprecated-List Entry 10 from 12.2013.
Of course, discarding all previous constants without any replacement is clearly not a feasible approach. That's simply impossible. At least in the first step, the class 'WbAdaptor' makes properties available that are similar to the previous constants.
A significant change has arisen about the spelling of the identifier:
The identifiers have been written entirely in capital letters and separated several individual words with an underscore _, the new identifiers however still consist of the same sub strings, but now they are written in 'StudlyCaps' notation without delimiters between words.
Example: DEFAULT_TEMPLATE becomes DefaultTemplate now
The transformation of the identifier is performed automatically when reading in the class WbAdaptor.
So far so good. To make it not too simple, for about a dozen former constants the identifier (key) and also partially the content has completely changed!!
List of new identifiers and examples of the current contents.
(note: this list is not complete!)
old constant | new key | content (example) |
---|---|---|
{introduced} | Db | the current object for accessing the database |
{introduced} | Trans | the current translation object |
{introduced} | App | the current application/core object |
{introduced} | PageId | the ID of the current page |
{introduced} | BlockId | the ID of the current block |
{introduced} | SectionId | the ID of the current section |
WB_URL | AppUrl | http: ⁄⁄ example.com/wb/ |
WB_REL | AppRel | /wb/ |
WB_PATH | AppPath | /var/www/httpdocs/wb/ alternatively, in Windows ('c:/var/www/httpdocs/wb/') |
ADMIN_URL | AcpUrl | http: ⁄⁄ example.com/wb/admin/ |
ADMIN_REL | AcpRel | /wb/admin/ |
ADMIN_PATH | AcpPath | /var/www/httpdocs/wb/admin/ |
TMP_PATH | TempPath | /var/www/httpdocs/wb/temp/ |
TEMPLATE | Template | MyTemplate |
TEMPLATE_DIR | TemplateDir | templates/MyTemplate/ |
{introduced} | TemplateUrl | http: ⁄⁄ example.com/wb/templates/MyTemplate/ |
{introduced} | TemplateRel | /wb/templates/MyTemplate/ |
{introduced} | TemplatePath | /var/www/httpdocs/wb/templates/MyTemplate/ |
ADMIN_DIRECTORY | AcpDir | admin/ |
PAGES_DIRECTORY | PagesDir | pages/ |
MEDIA_DIRECTORY | MediaDir | media/ |
WB_VERSION | AppVersion | 2.8.4 |
WB_REVISION | AppRevision | 2060 |
WB_SP | AppServicePack | SP1 |
{introduced} | AppName | WebsiteBaker |
STRING_DIR_MODE | DirModeString | rwxrwxr-x (textual representation, corresponds to 0775 octal) |
OCTAL_DIR_MODE | DirModeOctal | 509 (stored integer, corresponds to 0775 written in octal) |
STRING_FILE_MODE | FileModeString | rw-rw-r-- (textual representation, corresponds to 0664 octal) |
OCTAL_FILE_MODE | FileModeOctal | 436 (stored integer, corresponds to 0664 written in octal) |
Who looks attentively at the list, will recognize a few new laws:
The string WB_ became App (has nothing to do with any of these App Stores !!), it's just the original abbreviation for application ⇒ program.
The string ADMIN_ became Acp which is the abbreviation for Admin Control Panel, because the functions and names 'backend' and 'admin tools' will be abolished or replaced in one of the subsequent versions.
Regardless of the changed prefixes, the following rules apply for extensions:
templates/myTemplate/images/logo.png
Was nach außen nicht sichtbar ist, ist der Umstand dass alle abrufbaren Werte in zwei Basis-Gruppen abgelegt sind:
* System ⇒ das sind alle Werte, die bei unveränderten Grundeinstellungen bei jedem Scriptaufruf immer gleich sind.
* Request ⇒ alle anderen Werte, die je nach Seite, Benutzer, Requestmodus oder sonstigen Kriterien unterschiedliche Werte haben können.
Die System-Werte sind geschützt und können nicht** durch Request-Werte oder anderes überschrieben werden.