Table of Contents
This chapter illustrates several of the predefined classes that the language makes available to the programmer. Biferno offers a large number of primitive classes describing the main data types used in the language in addition to specific classes representing arrays, files, dates and times. Very specialized classes are also available to support Internet protocols and to interact with databases.
A detailed reference for all methods and properties of Biferno predefined classes can be found in the "Biferno: Reference Guide" document (see Chapter 2, Documentation).
As common in programming languages, Biferno implements classes supporting the most commonly used data types.
The boolean class describes the Boolean values (i.e. true or false) resulting from expressions of the Boolean logic.
The int class describes positive or negative integer numbers (natural numbers) with values ranging from -2,147,483,647 to 2,147,483,648 (4 byte representation).
Numeric values can also be written in hexadecimal notation as follows:
<?
a = 0xA8FF
?>
The unsigned class describes positive integer numbers with values ranging from 0 to 4,294,967,295 (4 byte representation).
The long describes positive or negative integer numbers with values ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (8 byte representation).
The double describes positive or negative real numbers with values ranging from 1.7E-308 to 1.7E+308 (8 byte representation).
All numerical classes support methods implementing the most commonly used mathematic and trigonometric functions.
The string class describes arbitrary length text strings. A string
is represented as a sequence of characters enclosed in single or double
quotes (e.g. "this is a string"). The string that contains no characters
is called the null string, and is represented by "" or ''. If a string
enclosed in double quotes contains the double quote character ", the
latter has to be escaped by using the \ character (backslash), as in the
string "<a href=\"page.bfr\">". Escaping double quotes is not
necessary if the string is enclosed in single quotes, e.g. '<a
href="page.bfr">' is correct. Similarly, if a string enclosed in
single quotes contains the single quote character ', the latter has to
be escaped by using a backslash. Escaping single quotes is not necessary
if the string is enclosed in double quotes. The special characters tab,
vertical tab, <CR> (carriage return) and <LF> (line feed)
can be represented in a string as "\t", "\v", "\r", "\n". The "\"
character itself must be escaped as "\\".
Finally, it is possible to write a string on multiple lines by using a backslash as the last character of the line before the line break (the line break inserted by our text editor will not appear in the resulting string). The same string can be written as
'string \ one'
or: 'string one'
The char class describes single characters. The read-only property
ascii of the char class contains the decimal ASCII code of the character
assigned to the object.
This class contains many generally useful methods for string manipulation derived from the ANSI standard libraries, as well as a couple of methods for the generation of random numbers. The ansi class is a "static" class, which means that only method invocation is allowed. It is not to possible to create variables of the ansi class.
The array class describes one-dimensional ordered lists of elements all belonging to the same class. We will see this class in further detail in Chapter 6, Arrays.
The file and folder classes allow creating, reading, and modifying files and directories. We will see these classes in further detail in Chapter 13, File Management.
The time class allows manipulating dates and times. We will see this class in further detail in Chapter 14, Date and Time Functionality.
The methods of these classes allow interaction with a database (often indicated with the DBMS acronym: DataBase Management System) via the SQL query language (SQL stands for Structured Query Language). The interface with the most common DBMS (Oracle, MySQL, PostgreSQL, etc.) is implemented via special-purpose native drivers or via ODBC. A number of native drivers are available and more are under development.
We will discuss these two classes in further detail in Chapter 15, Database Interaction.
When Biferno executes a script, a global variable named err belonging to
the error class is initialized. If a runtime error occurs, the err
variable contains precise information on the nature of the error itself.
We will describe the error class and error handling in Biferno in Chapter 16, Error Handling and Debugging.
Biferno implements a number of classes providing support for Internet protocols (HTTP, SMTP), for data transfer between Web pages and for client-server interaction. Here we will only touch upon the characteristics of these classes. In the following we will demonstrate their use within an application.
The multipart class describes data captured in a HTML form in the "multipart/form-data" encoding when a file is uploaded from a Web page. Chapter 18, Passing Parameters between Pages illustrates how to use properties and methods of this class.
The smtp class allows managing and sending email messages using a Biferno script. We will discuss in Chapter 19, E-mail Handling the use of methods of this class.
The header class describes the header of the HTTP protocol. The methods of this class support reading and manipulating fields in the HTTP header. Properties and methods of this class are analyzed in detail in Chapter 20, HTTP Protocol Interaction.
The httpPage class describes a Web page in the form used by the HTTP protocol during client-server communication. A HTTP page can be seen as a structured data packet composed by a header and a body. When a server sends such a packet in answer to a client request, the body of the packet contains the HTML code describing the content of the Web page, which will be visualized by the browser. In the query packet sent by the client to the server, the body can contain parameters transmitted via the HTTP protocol POST method. Properties and methods of this class will be analyzed in detail in Chapter 20, HTTP Protocol Interaction.
The request class describes a page request to the server. Its properties allow to obtain information such as the name of the requested file, its absolute path, which method was used for the request (POST or GET), the list of parameters (arguments) used in the invocation, etc. Properties and methods of this class will be analyzed in detail in Chapter 20, HTTP Protocol Interaction.
The client class allows to obtain information about the client, i.e. on the user that sent to the server a page request with extension ".bfr". Properties and methods of this class will be analyzed in detail in Chapter 20, HTTP Protocol Interaction.
The serverInfo class allows obtaining information on the Web
server, such as the application name (e.g. Apache, IIS), the
software version, the host domain name, the path of the server's root
directory etc.
A detailed reference for all properties of this class can be found in the "Biferno: Reference Guide" document (see Chapter 2, Documentation.
The cacheItem class describes a Biferno cache element. We will discuss this class in more detail in Chapter 22, Cache Management.