====== General adjustment for Website Baker ====== Since WebsiteBaker existed before the appearance of the PHP FIG standards a few adjustments to the standards are required, which are described below. Further adjustments to adhere are included in the chapters on the individual WB versions / WB version groups!
{{:warning.png?nolink&32 |Warning}} **Caution:** For all new Code the principle of electronic data processing, valid since the invention of the computer and which has often been disregarded in WB in the past, from now on has to be followed in WB as well: * **I**nput » **P**rocessing » **O**utput These 3 areas must be strictly separated and always occur in the exact order. New modules that do not adhere to this basic rule are no longer included in future in the repository, or they are marked as '//**not compatible**//'.
===== PHP File Formatting ===== ==== General ==== For files with the extension *.php which include only PHP code or end with PHP code, the closing tag **?>** is not allowed. It is not required by the web server nor by PHP and omitting it prevents from accidentally including blank lines which would may prematurely trigger that headers are sent.\\ If a file starts with PHP code, the opening **{{:info.png?nolink&32 |Note}} **Note:** Strict compliance with these conventions is imperative so that there can be no homonyms of classes and functions / methods in different modules. The core is thus able to clearly determine the location of the class file based on the class name to reload them using the autoloader optimized on WB. An explicit inclusion of the class files via include () or require () is superfluous. Website Baker from v2.8.4 on requires PHP 5.4.x as a minimum requirement. For a transitional period 2 different naming conventions for classes are permitted. However, the stated objective is to convert entirely to namespaces to utilize their advantages and also to reduce the cost significantly when naming classes. ==== Classes ==== Class names must be declared in **StudlyCaps** (also called //**UpperCamelCase**//) and correspond to the following RegEx rule: '/[A-Z][a-zA-Z0-9]+/'. Numbers are permitted in class names, but should be limited to what is necessary and do not pose any risk of confusion with letters. If the class name consists of more than one word, the respective first letter of a word has to be in uppercase. Several consecutive uppercase letters are not allowed. Example based on a name: ^Identifier ^ Status | |smtp_mailer | [color=red]wrong[/color] | |Smtp_Mailer | [color=red]wrong[/color] | |SMTPmailer | [color=red]wrong[/color] | |SmtpMailer | [color=green]correct[/color] | ==== Abstract classes and interfaces ==== In general, abstract classes and interfaces follow the same conventions as classes, with an additional rule: The names of abstract classes and interfaces should end with the term "**Abstract**" or "**Interface**", and the term must not be preceded by an underscore. As an example //**Plugin_Abstract**// is considered invalid, but **PluginAbstract** or **m_MyModul_PluginAbstract** would be valid names. ==== Emulated namespaces ==== In this mode in class names the underscore '_' is permitted additionally as special/functional character. However, it is intended solely as path separator. Class names in this context do not only consist of the name defined so far, but they must also contain a well-defined prefix. Only then it is possible to find the correct file out of the class name, so that the appropriate file can be loaded automatically (included) when accessing a class. The class libraries of WebsiteBaker are divided into several groups:\\ **The core classes**: reside in the directory **''wb/framework/''** or one of its subdirectories. For these no prefix is needed at all.\\ **Classes of modules**: classes of modules in the appropriate module directory **''wb/modules/%module_name%/''** or one of its subdirectories. The identifier must necessarily get the prefix '**m_**'. **Example:** m_MyModule_PluginInterface \\ **Classes of ACP**: (AdminControlPanel => Former backend) are located in the directory **''wb/admin/''** or one of its subdirectories. The ClassIdentifier must necessarily get the prefix '**a_**'. **Example:** a_Pages_PageTree\\ **Classes of third-party libraries**: lying in the directory **''wb/include/''** and its subdirectories are not automatically covered by the autoloader. However, each library has the ability to carry out its own registration in the SPL autoloader stack. More on this can be found in the description of the autoloader the respective WB version. ==== Filenames ==== As far as the above-mentioned rules for class names have been complied with, the filename would clearly result from the class name. The class **m_MyModul_PluginAbstract** accordingly can be found in the file **''wb/modules/MyModul/PluginAbstract.php''**.\\ For all other files, only alphanumeric characters and the dash (**-**) are allowed. Spaces are strictly prohibited.\\ Each file which contains executable PHP code should end with the extension **.php** and be carried out in UpperCamelCase. ==== Directories ==== For naming directories the same basis as for files apply. Only alphanumeric characters and a few special characters of standard 7-bit ASCII range <128 (**[color=blue] ! # - . @ ~ [/color]**) are allowed. As with file names, spaces, and the underscore are prohibited. ==== Functions and Methods ==== Function and method names may only contain alphanumeric characters. Underscores are not permitted. Numbers are however permitted in function names in most cases however not recommended. Verbosity is generally encouraged. Function names should be as verbose as possible to describe their purpose and behavior as precisely as possible. Functions or methods have to be written whenever possible in //**lowerCamelCase**// (or simply //**camelCase**//). This means they should begin with a lowercase verb like //get//, //set//, //add//, //delete//, //load//, //save//, //execute// etc. followed by a noun in StudlyCaps that describes the object to be processed. Example: $oMyObject->saveItemList(); or reloadAllModules(); :!: **Warning:** doulble underscores may never be used as a prefix for method, function, or variable names. There is the danger that it overlaps with current or future, PHP's intrinsic Magic Functions etc..