Chapter 4. Packages

FLOW3 is a package-based system. In fact, FLOW3 itself is just a package as well - but obviously an important one. Packages act as a container for different matters: Most of them contain PHP code which adds certain functionality, others only contain documentation and yet other packages consist of templates, images or other resources. The TYPO3 project hosts a package repository which acts as a convenient hub for interchanging FLOW3 based packages with other community members.

Note

At the time of this writing the package repository for FLOW3 is still in the planning phase.

4.1. Package Locations

Global and Local Packages

FLOW3 packages are located in a sub folder of the Packages directory. A typical application (such as TYPO3 for example) will use the core packages which are bundled with FLOW3 and use additional packages which are specific to the application. The core packages are kept in a directory called Global while the application specific packages reside in the Local directory:

Configuration/

The global configuration folder

Data/

The various data folders

Packages/
Global/

The Global directory contains packages of the FLOW3 distribution (just examples):

FLOW3/

The FLOW3 package

Fluid/

The Fluid package (Template Engine)

Local/

The Local directory contains your own / application specific packages:

TYPO3/

For example the TYPO3 package

Coffee/

Or the coffee package

The reason for separating packages into Global / Local directories is that the core packages residing in Global/ can reside in a different, shared location and be symlinked from the application using it. Just delete the Global directory and replace it with a symlink pointing to the Packages/Global/ directory of the FLOW3 distribution.

We recommend that you keep a version of the FLOW3 distribution in /var/lib/flow3/flow3-x.y.z/ and flag all its content read-only for the web server's user. By doing that you can assure that no FLOW3 package (or other PHP script) can tamper with the FLOW3 package and its built-in security framework.

Additional Package Locations

Apart from the Local and Global packages you may define your very own additional package locations by just creating another directory or symlink in the application's Packages directory.

Loading Order

If multiple package locations exist, the Package Manager will assure that packages from the location FLOW3 itself is located will be loaded first. The loading order of all other package locations is undefined.

4.2. Package Directory Layout

The FLOW3 package directory structure follows a certain convention which has the advantage that you don't need to care about any package-related configuration. If you put your files into the right directories, everything will just work.

The suggested directory layout of a FLOW3 package is as follows:

[PackageName]
Classes

This directory contains the actual source code for the package. Package authors are free to add (only!) class or interface files directly to this directory or add subdirectories to organize the content if necessary. All classes or interfaces below this directory are handled by the autoloading mechanism and will be registered at the object manager automatically (and will thus be considered "registered objects").

Configuration

All kinds of configuration which are delivered with the package reside in this directory. The configuration files are immutable and must not be changed by the user or administrator. The most prominent configuration files are the Objects.yaml file which may be used to configure the package's objects and the Settings.yaml file which contains general user-level settings.

Documentation

Holds the package documentation. The English manual must be located in a subdirectory called Manual/en/. The format for manuals is DocBook. Please refer to the Documentor's Guide for more details about the directories and files within this directory.

Meta

A folder which provides some meta information about the package.

Package.xml

This mandatory file contains some basic information about the package, such as title, description, author, constraints, version number and more. You should take great care to keep this information updated.

Resources

Contains static resources the package needs, such as library code, template files, graphics, ... In general, there is a distinction between public and private resources. While public resources will be mirrored into FLOW3's Web directory by the Resource Manager (and therefore become accessible from the web) all resources in the Private directory remain protected.

Private

Contains private resources for the package.

Public

Contains public resources for the package.

Although it is up to the package author to name the directories, we suggest the following conventions for directories below Private and Public:

Media

This directory holds images, PDF, Flash, CSS and other files that will be delivered to the client directly without further processing.

Templates

Template files used by the package should go here. If a user wants to modify the template it will end up elsewhere and should be pointed to by some configuration setting.

PHP

Should hold any PHP code that is an external library which should not be handled by the object manager (at least not by default), is of procedural nature or doesn't belong into the classes directory for any other reason.

Java

Should hold any Java code needed by the package. Repeat and rinse for Smalltalk, Modula, Pascal, ... ;)

More directories can be added as needed.

Tests

Holds the unit tests for the package. Test cases will be recognized by the Testing package if they follow the required naming convention.

As already mentioned, all classes which are found in the Classes directory will be detected and registered. However, this only works if you follow the naming rules equally for the class name as well as the file name. An example for a valid class name is \F3\MyPackage\Controller\StandardController while the file containing this class would be named StandardController.php and is expected to be in a directory MyPackage/Classes/Controller.

All details about naming files, classes, methods and variables correctly can be found in the FLOW3 Coding Guidelines. You're highly encouraged to read (and follow) them.

4.3. Package Keys

Package keys are used to uniquely identify packages and provide them with a namespace for different purposes. They save you from conflicts between packages which were provided by different parties.

Any public package needs to have a unique package key which you need to register at forge.typo3.org prior to use. But even if you develop a package for private use only, it's clever to register a package key for it.

4.4. Importing and Installing Packages

At this time the features for import and installation of packages have not been implemented fully. The current behavior is that all directories which are found below the Packages folder are assumed to be packages. Just make sure that you created a Package.xml file in the Meta directory of your package.

If no PackageStates.yaml exists in your Configuration folder, it will be created and all found packages will be activated. If PackageStates.yaml exists, you can use the package manager to activate and deactivate packages through the FLOW3 command line script. The script flow3 resides in the main directory of the FLOW3 distribution. From a Unix shell you should be able to run the script by entering ./flow3:

myhost:tutorial johndoe$ ./flow3 
FLOW3 Command Line Interface

usage: flow3 <options> <command>

Options:

  -h, --help        - print this message
  -p, --production  - execute in production context

Available commands:

  package list available           - list available packages
  package list active              - list active packages
  package create <package-key>     - create a new package
  package activate <package-key>   - activate a package
  package deactivate <package-key> - deactivate a package
  package delete <package-key>     - delete a package

Depending on your FLOW3 version you'll see more or less the above available commands listed.

Note

We haven't developed a Windows batch script yet so for the time being you'll have to call FLOW3 manually. Before you can run the FLOW3 command line script you need to set some environment variables:

c:\> set FLOW3_CONTEXT=Development
c:\> set FLOW3_ROOTPATH=C:\xampp\htdocs\tutorial
c:\> set FLOW3_WEBPATH=C:\xampp\htdocs\tutorial\Web

If you like to make those variable settings permanent, so they are valid for more than just the current shell session, you can use the setx command:

c:\> setx FLOW3_CONTEXT Development
c:\> setx FLOW3_ROOTPATH C:\xampp\htdocs\tutorial
c:\> setX FLOW3_WEBPATH C:\xampp\htdocs\tutorial\Web

Listing the available packages is then as easy as typing:

c:\> (php Packages\Framework\FLOW3\Scripts\FLOW3.php
         FLOW3 Package PackageManager listavailable)

4.5. Package Manager

The Package Manager is in charge of downloading, installing, configuring and activating packages and registers their objects and resources.

Note

In its current form, the package manager only provides the basic functionality which is necessary to use packages and their objects. More advanced features like installing or configuring packages are of course planned.

4.6. Creating a New Package

Just create the package folder and subdirectories manually and copy & adapt a Package.xml file from one of the other packages. Apart from that no further steps are necessary.

4.7. Package Meta Information

All packages need to provide some meta information to the package manager. This data is stored in a file called Package.xml which resides in the Meta directory of a package. The format of this file follows a RelaxNG schema which is available at http://typo3.org/ns/2008/flow3/package/Package.rng.

Note

If you are working with Eclipse, you might want to install the DEV3 plug-in which - among other tools - provides you with a convenient Package.xml editor

Here is an example of a valid Package.xml file:

Example 4.1. Package.xml

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://typo3.org/ns/2008/flow3/package" version="1.0">
   <key>TestPackage</key>
   <title>Test Package</title>
   <description>Test to demonstrate the features of Package.xml</description>
   <version>0.0.1</version>
   <categories>
      <category>System</category>
      <category>Testing</category>
   </categories>
   <parties>
      <person role="LeadDeveloper">
         <name>David Brühlmeier</name>
         <email>typo3@bruehlmeier.com</email>
      </person>
      <person role="Maintainer">
         <name>John Smith</name>
         <email>john@smith.com</email>
         <organisation>Smith Ltd.</organisation>
         <repositoryUserName>jsmith</repositoryUserName>
      </person>
      <organisation role="Sponsor">
         <name>John Doe Co.</name>
         <email>info@johndoe.com</email>
         <website>www.johndoe.com</website>
      </organisation>
   </parties>
   <constraints>
      <depends>
         <package minVersion="1.0.0" maxVersion="1.9.9">FLOW3</package>
         <system type="PHP" minVersion="5.1.0" />
         <system type="PHPExtension">xml</system>
         <system type="PEAR" minVersion="1.5.1">XML_RPC</system>
      </depends>
      <conflicts>
         <system type="OperatingSystem">Windows_NT</system>
      </conflicts>
      <suggests>
         <system type="Memory">16M</system>
      </suggests>
   </constraints>

   <!-- The following elements are only used and generated by the repository -->
   <repository>
      <downloads>
         <total>3929</total>
         <thisVersion>444</thisVersion>
      </downloads>
      <uploads>
         <upload>
            <comment>Just a comment...</comment>
            <repositoryUserName>jsmith</repositoryUserName>
            <timestamp>2008-04-22T17:23:09Z</timestamp>
         </upload>
         <upload>
            <comment/>
            <repositoryUserName>jsmith</repositoryUserName>
            <timestamp>2008-04-19T03:54:13Z</timestamp>
         </upload>
      </uploads>
   </repository>
</package>