TYPO3/Overwrite bootstrapping

From Aimeos documentation

TYPO3
Other languages:
English 100%


It's the Aimeos concept that you can overwrite anything and adapt it to your needs. Thus, you can also replace almost every single piece of code that builds the TYPO3 environment for the Aimeos core.

Base classes

Aimeos requires a few classes that are necessary for bootstrapping. They include:

  • \Aimeos\Aimeos\Base\Aimeos (Core bootstrapping)
  • \Aimeos\Aimeos\Base\Config (Configuration settings)
  • \Aimeos\Aimeos\Base\Context (Dependency container)
  • \Aimeos\Aimeos\Base\I18n (Translation and internationalization)
  • \Aimeos\Aimeos\Base\Locale (Site, language and currency setup)
  • \Aimeos\Aimeos\Base\View (Template engine setup)

You can find these classes in the ./Classes/Base/ directory of the Aimeos TYPO3 extension. To overwrite their code, you should create your own class and extend from the original one if necessary. Afterwards, you need to configure the name of your new class in the ext_localconf.php file, e.g.

  1. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view'] = 'Myview';

You can use that kind of statements for all classes you want to overwrite:

  1. // core bootstrapping
  2. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos'] = '...';
  3. // configuration settings
  4. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_config'] = '...';
  5. // dependency container
  6. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context'] = '...';
  7. // translation and internationalization
  8. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_i18n'] = '...';
  9. // site, language and currency setup
  10. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_locale'] = '...';
  11. // Template engine setup
  12. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view'] = '...';

Since 2018.04 you can also use closures to extend the functionality of the Aimeos base classes. To add a new view helper you've implemented (requiring a TYPO3 object) to the view object for example, you can add this to the ext_localconf.php of your own TYPO3 extension:

  1. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view'] =
  2.     function( \Aimeos\MShop\Context\Item\Iface $context,
  3.         \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder $uriBuilder, array $templatePaths,
  4.         \TYPO3\CMS\Extbase\Mvc\RequestInterface $request = null, $langid = null
  5.     ) {
  6.         $view = \Aimeos\Aimeos\Base\View::get( $context, $uriBuilder, $templatePaths, $request, $langid );
  7.         $service = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'ImageService' );
  8.         $helper = new \Aimeos\MW\View\Helper\Request\ImageService( $view, $service );
  9.         $view->addHelper( 'imageservice', $helper );
  10.         return $view;
  11. }

Dependency container

The context class itself contains a lot of objects that are used by the Aimeos core to interact with TYPO3 or abstract from a concrete implementation. Those objects are:

  • Cache
  • Database
  • File system
  • Logging
  • Mail client
  • Message queue
  • Passwort hashing
  • Session
  • User
  • User groups

Please have a look into the default implementation of the context object setup to get a feeling for the necessary tasks. You can overwrite any injected object into the context by configuring your own anonymous function in the ext_localconf.php file:

  1. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_logger'] =
  2.     function( \Aimeos\MShop\Context\Item\Iface $context )
  3.     {
  4.         $loglevel = \Aimeos\MW\Logger\Base::DEBUG;
  5.         $logger = new \Aimeos\MW\Logger\File( '/tmp/aimeos.log', $loglevel );
  6.  
  7.         return $context->setLogger( $logger );
  8.     };

Your anonymous function receives the current context object, needs to set the new object you've created and returns the context object again. This works in the same way for all dependencies:

  1. // Cache infrastructure
  2. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_cache'] = ...
  3. // Database abstraction
  4. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_dbm'] = ...
  5. // File system abstraction
  6. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_fsm'] = ...
  7. // Password hashing algorithm
  8. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] = ...
  9. // Logging facility
  10. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_logger'] = ...
  11. // Sending e-mails
  12. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mailer'] = ...
  13. // Message queue
  14. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mqueue'] = ...
  15. // Common session
  16. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_session'] = ...
  17. // Authenticated user
  18. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] = ...
  19. // Groups the user is in
  20. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] = ...

View helper

In the same way as for the context object, you can use your own anonymous functions to overwrite the view helpers added to the Aimeos template engine. View helpers added by default are:

  • Group based access control
  • Configuration settings
  • Form parameter naming
  • Number format
  • Parameter retrieval
  • Request object access
  • Response object access
  • Translation and internationalization
  • URL generation

The default implementation reveals the details of the view object setup so you can change it according to your needs. Replacing a view helper is done by adding the configuration to the ext_localconf.php file for your anonymous function:

  1. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_access'] =
  2.     function( \Aimeos\MW\View\Iface $view )
  3.     {
  4.         $helper = new \Aimeos\MW\View\Helper\Access\All( $view );
  5.         return $view->addHelper( 'access', $helper );
  6.     };

Your anonymous function receives at least the current view object, needs to add the new object you've created and returns the view object again. Depending on the view helper, more than one argument is passed to your anonymous function. You can check in the default implementation if this is the case.

You can do this In the same way for all other view helpers:

  1. // Group based access control
  2. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_access'] = ...
  3. // Configuration settings
  4. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_config'] = ...
  5. // Form parameter naming
  6. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_formparam'] = ...
  7. // Number format
  8. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_number'] = ...
  9. // Parameter retrieval
  10. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_param'] = ...
  11. // Request object access
  12. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_request'] = ...
  13. // Response object access
  14. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_response'] = ...
  15. // Translation and internationalization
  16. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_translate'] = ...
  17. // URL generation
  18. $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_view_url'] = ...