Book Image

TYPO3 Extension Development

Book Image

TYPO3 Extension Development

Overview of this book

Table of Contents (13 chapters)

PHP Classes and Files


There are certain conventions concerning file and class naming in TYPO3. They must be used in extensions too and knowing these conventions helps to locate files quickly.

Each class file starts with class. and is followed by a class name in lower case. The file ends with a .php extension. There are certain exceptions to this rule, and they will be described in this book. These exceptions exist due to historical reasons, and no new class may become an exception.

Classes have a certain prefix that declares where they belong in the TYPO3 class hierarchy. The following system prefixes are defined:

  • t3lib_

  • tslib_

  • tx_

  • ux_

  • user_

Each prefix corresponds to a "library" if it ends with "lib_", and to a "namespace" otherwise. "Library" is just a way to say that a "namespace" belongs to TYPO3. In other words, library classes are TYPO3 classes. Extensions cannot introduce new library classes.

t3lib_

t3lib stands for "TYPO3 library". This name is historical, and everyone just calls it t3lib (tee-three-lib). t3lib is the largest collection of classes in TYPO3. It includes most Common, FE, and BE classes. It is easy to say that a class belongs to t3lib by looking at its name. Here are some examples:

  • t3lib_DB

  • t3lib_div

  • t3lib_TCEmain

We will look at some t3lib classes later in this chapter.

tslib_

tslib stands for "TypoScript Library", The name has historical reasons as well and everyone calls this library tslib (tee-es-lib). It is located in the typo3/sysext/cms/tslib directory (inside the cms system extension). Most of these classes are already included when code runs in FE. So there is no need to include them explicitly in extensions.

The library classes are responsible for the rendering of the website and most of the FE logic. The base class for FE plugins (modules that extend TYPO3 Frontend functionality) is also located here.

We will discuss tslib classes in the Frontend API section.

Here is a list of some classes in tslib:

  • tslib_fe

    This is the main FE class in TYPO3. It represents a page that a website visitor sees in the browser. There is only one instance of this class in TYPO3 FE, and it is available as and generally referred as "TSFE".

  • tslib_cobj

    This is one of the exclusions to generic naming rule mentioned earlier. This class is located in the file named class.tslib_content.php, but the class name is different. This class implements content objects. Content objects is a TYPO3 way of generating different types of content. There are many content objects, for example, TEXT, IMAGE, or HMENU. They are the same content objects as found in TypoScript. FE plugins from extensions are USER or USER_INT content objects. Instances of this class can either be created directly (see later in this chapter), or by calling .

  • tslib_fetce

    This is an attempt to bring some BE functions (such as clear_cacheCmd) to the FE. While this class exists, it is not really updated and should not be used.

  • tslib_feuserauth

    This is an internal class that authenticates website visitors ("Frontend users"). This class is created and used by TSFE. An instance of this class is always available as .

  • tslib_pibase

    This is a base class for FE plugins. We will cover it in detail in Chapter 5.

tx_

This namespace is reserved for extensions ("tx" stands for "TYPO3 Extensions"). All extension classes must begin with tx_ (with the exception of "ux" classes).

ux_

This namespace is reserved for XCLASSes. XCLASS is a way to subclass a class in TYPO3 and make use of the subclass instead of the parent class in a way that is transparent to all the other classes in the system. Normally, XCLASSes are provided by extensions. XCLASSes take the class and file name of the parent class but prepend it with ux_, as in class.ux_tslib_fe.php or class.ux_t3lib_tcemain.php.

While XCLASSes may seem the easiest way to modify system behavior, they should be avoided and used only if there is absolutely no other way to change system behavior. The fundamental limitations of XCLASSes is that there can be only one XCLASS for a given class in the system. If two extensions try to XCLASS the same class, only the last one will succeed.

user_

This namespace is reserved for PHP functions outside of a class. TYPO3 will refuse to call any function outside of a class that is not prefixed with user_. If an extension key has this prefix, it means that the extension is private. Such extensions cannot be sent to the TYPO3 Extension Repository. Typically, such extensions are created for testing purposes.