New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

terminal42/contao-namespace-class-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terminal42/contao-namespace-class-loader

Namespace class loader for Contao Open Source CMS

contao-module
Source
Packagist
This package is abandoned and is no longer maintained.
The author recommends using true instead.
This version has been yanked by its maintainers and should not be used.
Version
1.0.3
Version published
Total downloads
8.4K
Maintainers
1
Created
Source

Namespace Class Loader for Contao 3

This extension implements a valid PSR-0 class loader for Contao 3. The implementation is based on the Composer\Autoload\ClassLoader.

This extension is outdated, see the Upgrade information!

Usage

Place all files in system/modules/_autoload in your Contao installation.

Usage works similar to the Contao class loader, except that you do not need to include every class file if you follow PSR-0 standards. Use the following example to implement the class loader in your config/autoload.php:

<?php

/**
 * Register namespace
 */
NamespaceClassLoader::add('Isotope', 'system/modules/isotope/library');

Upgrade to Contao 4

In Contao 4, the only way to install extensions is using Composer. Therefore, you will not need this extension but should use Composer's class loader.

To be compatible with Contao 3 extension repository and Contao 4, you will need to require at least Contao 3.3 and set it up as follow:

  • Define your namespaces or classes in composer.json.

  • Remove the dependency for terminal42/contao-namespace-class-loader from your composer.json

  • Keep the dependency in the old Extension Repository

  • Make _autoload an optional dependency in your autoload.ini like so:

    requires[] = "*_autoload"
    
  • Only call NamespaceClassLoader in your autoload.php if the class is actually available:

    if (class_exists('NamespaceClassLoader')) {
        NamespaceClassLoader::add( ... );
    }
    

If the extension is installed via Composer, the classes will be loaded by the Composer autoloader. When installed using the old extension repository, the _autoload extension will be added and the classes will work like before.

See our commit on how we accomplished this in Isotope eCommerce.

Keywords

classloader

FAQs

Package last updated on 18 Apr 2018

Related posts