Migrating from 1.6 to 1.7

1. Introduction

In version 1.7 the ApplicationManager was removed due to it's age. The component is now replaced by a Registry and a modificated initialization process. This guarantees more easy handling and mre efficient application design. The following chapter advices you how to migration from older versions to 1.7 and which new components are now included. The online documentation was updated, too.


2. Changes

Previously, the ApplicationManager created constants out of the INIT file entries. These constants were used within different parts of the framework and within your application. This style of initialization was now replaced by a Registry (see registry pattern), that stores all globally used configuration parameters, and a initialization process, that was relocated to the page controller. The framework now completely disclaims using constants and the INIT files are obsolete since version 1.7.

Due to these changes, some updates must be applied to the bootstrap files and thos components that used the predefined constants. The following chapters describe these changes and give hints on future handling.


2.1. Registry

The registry in version 1.7 is uses to store globally used parameters. Due to clearness, the registry store is separated in namespaces. The apf::core namespace contains the directives
  • URLRewriting: URL rewriting configuration.
  • URLBasePath: URL path of the current application.
  • Environment: Environment variable used for configuration issues.
  • LogDir: Path to the log directory.
The meaning and manipulation of these values is described in the next sections. Further, the namespace mentioned above contains another directive: LibPath. It stores the base path to your apf core base. During runtime, the content cannot be manipulated.


2.2. URL rewriting configuration

The constant APPS__URL_REWRITING was replaced by the registry entry URLRewriting in the namespace apf::core. The parameter is set to true (URL rewriting active) or false (URL rewriting deactivated). By default, the value is set to false by the page controller. In order to change this setting, the following code must be inserted into the bootstrap file after including the page controller:
PHP-Code
$Reg = &Singleton::getInstance('Registry'); $Reg->register('apf::core','URLRewriting',true|false);

2.3. URL path configuration

The constant APPS__URL_PATH was replaced by the registry entry URLBasePath in the namespace apf::core. The parameter is filled with the content of the HTTP_HOST offset of PHP's $_SERVER variable by default. In order to change this setting, the following code must be inserted into the bootstrap file after including the page controller:
PHP-Code
$Reg = &Singleton::getInstance('Registry'); $Reg->register('apf::core','URLBasePath','http://example.com/folder');

2.4. Environment configuration

The constant APPS__ENVIRONMENT was replaced by the registry entry Environment in the namespace apf::core. The parameter contains the value of the prefix, that is used by the ConfigurationManager. By default, the value is set to DEFAULT by the page controller. In order to change this setting, the following code must be inserted into the bootstrap file after including the page controller:
PHP-Code
$Reg = &Singleton::getInstance('Registry'); $Reg->register('apf::core','Environment','TESTSERVER');
This adaption should be done in order to use the "old" configuration file names. Otherwise, the prefixes of your configuration files must be renamed to DEFAULT or an adequate value.


2.5. Log directory configuration

The constant APPS__LOG_PATH was replaced by the registry entry LogDir in the namespace apf::core. The parameter contains the path, that is used as a log directory. By default, the value is set to ./logs by the page controller. In order to change this setting, the following code must be inserted into the bootstrap file after including the page controller:
PHP-Code
$Reg = &Singleton::getInstance('Registry'); $Reg->register('apf::core','LogDir','/path/to/my/log/dir');
This adaption should be done in order to use the "old" log path. Otherwise, the logger tries to write into the directory, where your bootstrap file is hosted.


2.6. Definition of the library path

In versions lower than 1.7 the framework needed the APPS__PATH to be defined as the root path to the software libraries. In version greater than 1.6 this is not necessary any more. This configuration was droped without substitution.


2.7. Separate PHP 4 and PHP 5 releases

In the future separated PHP version releases are shipped. PHP 4 users should download the releases with the "php4" suffix, PHP 5 users packages with the "php5" suffix. This separation means, that files containing PHP 5 only code must no longer be named *.php5. Now, all file extensions are .php. This step prepares the elimination of the PHP 4 branch.


3. A typical index.php

During migration from version lower than 1.7 to 1.7 the code block
PHP-Code
define('APPS__NAME','myapp'); define('APPS__PATH','./apps'); require_once(APPS__PATH.'/core/applicationmanager/ApplicationManager.php');
must be replaced by
PHP-Code
require_once('/path/to/core/pagecontroller/pagecontroller.php');
in your bootstrap file. The initialization of the framework is then done within the page controller. Thus, the configuration and initialization costs are reduced explicitly and the content of the "new" index.php looks like this:
PHP-Code
require_once('/path/to/core/pagecontroller/pagecontroller.php'); import('core::frontcontroller','Frontcontroller'); $fC = &Singleton::getInstance('Frontcontroller'); $fC->setContext('my::context'); $fC->setLanguage('de'); $fC->start('sites::mysite','pres/template/site');
In order to adjust the values of the standard parameters, the registry must be used. The following code box shows how to trim the parameters described in chapter 2 using the registry. Please note, that the readaption must take place before initializing the page or front controller:
PHP-Code
require_once('/path/to/core/pagecontroller/pagecontroller.php'); $Reg = &Singleton::getInstance('Registry'); $Reg->register('apf::core','LogDir','/path/to/my/log/dir'); import('core::frontcontroller','Frontcontroller'); $fC = &Singleton::getInstance('Frontcontroller'); $fC->setContext('my::context'); $fC->setLanguage('de'); $fC->start('sites::mysite','pres/templates/site');

Comments

Do you want to add a comment to the article above, or do you want to post additional hints? So please click here. Comments already posted can be found below.
There are no comments belonging to this article.