Package Dependencies

Since vesion 8.3.0, Concrete CMS implements a package dependency system.

For example, a Concrete package PackageA may require another Concrete package PackageB. In this case, PackageA can be installed only if PackageB is already installed, and PackageB can't be uninstalled if PackageAis installed.

The dependency systems let you also define packages that are incompatible (for example, PackageA can't be installed if PackageB is installed).

Where dependencies should be declared?

In order to define the dependencies, you can implement a getPackageDependencies public method in your package controller.php file:

namespace Concrete\Package\MyPackage;

use Concrete\Core\Package\Package;

defined('C5_EXECUTE') or die('Access denied.');

class Controller extends Package
{
    /**
     * {@inheritdoc}
     *
     * @see \Concrete\Core\Package\Package::getPackageDependencies()
     */
    public function getPackageDependencies()
    {
        return [];
    }
}

You can alternatively define a $packageDependencies protected property of the package controller.php file:

namespace Concrete\Package\MyPackage;

use Concrete\Core\Package\Package;

defined('C5_EXECUTE') or die('Access denied.');

class Controller extends Package
{
    /**
     * {@inheritdoc}
     *
     * @see \Concrete\Core\Package\Package::$packageDependencies
     */
    protected $packageDependencies = [];
}

How can a package require another package?

If your package requires another Concrete package with handle other_package_handle, it's enough to define the dependency array like this:

[
    'other_package_handle' => true,
]

that way, your package can be installed only if other_package_handle is already installed, and the other_package_handle package can't be uninstalled until your package is installed.

You can also define a minimum version for the other package. For example, if your package requires at least version 2.0.0 of other_package_handle, you can write this:

[
    'other_package_handle' => '2.0.0',
]

You can also define a maximum version of the other package. For example, if your package requires the package other_package_handle with a version between 2.0.0 and 2.2.99, you can write this:

[
    'other_package_handle' => ['2.0.0', '2.2.99'],
]

How to declare package incompatibilities?

If your package shouldn't be installed if another package with handle other_package_handle is already installed, you can write this:

[
    'other_package_handle' => false,
]

Of course, this also implies that the package with handle other_package_handle can't be installed if your package is already installed.

Complete example

Here's a full example that implements the following situation:

  • your package requires that another package with handle package_a is installed (any version)
  • your package requires that another package with handle package_b is installed (at least version 2.0.0)
  • your package requires that another package with handle package_c is installed (version between 2.0.0 amd 2.2.99, boundaries included)
  • your package can't be installed if another package with handle package_d is already installed
namespace Concrete\Package\MyPackage;

use Concrete\Core\Package\Package;

defined('C5_EXECUTE') or die('Access denied.');

class Controller extends Package
{
    /**
     * {@inheritdoc}
     *
     * @see \Concrete\Core\Package\Package::$packageDependencies
     */
    protected $packageDependencies = [
        'package_a' => true,
        'package_b' => '2.0.0',
        'package_c' => ['2.0.0', '2.2.99'],
        'package_d' => false,
    ];
}