abstract class Package implements LocalizablePackageInterface (View source)

Constants

E_PACKAGE_NOT_FOUND

Error code: Invalid Package.

E_PACKAGE_INSTALLED

Error code: You've already installed that package.

E_PACKAGE_VERSION

Error code: This package requires concrete5 version %s or greater.

E_PACKAGE_DOWNLOAD

Error code: An error occurred while downloading the package.

E_PACKAGE_SAVE

Error code: concrete5 was not able to save the package after download.

E_PACKAGE_UNZIP

Error code: An error occurred while trying to unzip the package.

E_PACKAGE_INSTALL

Error code: An error occurred while trying to install the package.

E_PACKAGE_MIGRATE_BACKUP

Error code: Unable to backup old package directory to %s.

E_PACKAGE_INVALID_APP_VERSION

Error code: This package isn't currently available for this version of concrete5.

E_PACKAGE_THEME_ACTIVE

Error code: This package contains the active site theme, please change the theme before uninstalling.

Properties

protected string $DIR_PACKAGES_CORE

Absolute path to the /concrete/packages directory.

protected string $DIR_PACKAGES

Absolute path to the /packages directory.

protected string $REL_DIR_PACKAGES_CORE

Path to the /concrete/packages directory relative to the web root.

protected string $REL_DIR_PACKAGES

Path to the /concrete/packages directory relative to the web root.

protected Package|null $entity

Associated package entity.

protected Application $app

The Application instance.

protected Liaison|null $config

The database configuration liaison.

protected Liaison|null $fileConfig

The file configuration liaison.

protected bool deprecated $pkgEnableLegacyNamespace
protected array $pkgAutoloaderRegistries

The custom autoloader prefixes to be automatically added to the class loader.

protected string $appVersionRequired

The minimum concrete5 version compatible with the package.

protected bool $pkgAllowsFullContentSwap

Override this value and set it to true if your package clears all existing website content when it's being installed.

protected bool $pkgContentProvidesFileThumbnails

Override this value and set it to true if your package provides the file thumbnails.

protected string|null $backedUpFname

The full path of the package directory moved to the trash folder.

protected array $packageDependencies

An array describing the package dependencies.

Methods

__construct(Application $app)

Initialize the instance.

Package|null
getPackageEntity()

Get the associated package entity (if available).

setPackageEntity(Package $entity)

Set the associated package entity.

getApplication()

Get the Application instance.

getContentSwapper()

Get the content swapper.

installContentFile(string $file)

Import a concrete5-cif XML file.

bool
shouldEnableLegacyNamespace()

Should this package enable legacy namespaces?

getConfig()

Get the default configuration liaison.

getDatabaseConfig()

Get the database configuration liaison.

getFileConfig()

Get the filesystem configuration liaison.

array
getPackageAutoloaderRegistries()

Get the custom autoloader prefixes to be automatically added to the class loader.

string
getPackageHandle()

Get the package handle.

string
getPackageName()

Get the translated name of the package.

string
getPackageDescription()

Get the translated package description.

string
getPackageVersion()

Get the installed package version.

string
getApplicationVersionRequired()

Get the minimum concrete5 version compatible with the package.

bool
showInstallOptionsScreen()

Should the install options page be shown? The install options page may be for install notes and/or full contents swap confirmation.

bool
hasInstallNotes()

Does this package have install notes?

bool
hasUninstallNotes()

Does this package have uninstall notes?

bool
hasInstallPostScreen()

Does this package have a post-install page?

bool
allowsFullContentSwap()

Does this package clear all existing website content when it's being installed?

string
getPackagePath()

Get the absolute path to the package.

string
getRelativePath()

Get the path to the package relative to the web root.

string
getRelativePathFromInstallFolder()

Get the path to the package relative to the concrete5 installation folder.

getTranslationFile($locale)

No description

bool
contentProvidesFileThumbnails()

Does this package provide the file thumbnails? If false, the file thumbnails are generated during the install process.

install()

Install the package info row and the database (doctrine entities and db.xml).

uninstall()

Uninstall the package:

  • delete the installed items associated to the package
  • destroy the package proxy classes of entities
  • remove the package info row.

string
getChangelogContents()

Get the contents of the package's CHANGELOG file.

static Package[]
getInstalledList() deprecated

No description

static string[]
getInstalledHandles() deprecated

No description

static Package|null
getByHandle(string $pkgHandle) deprecated

No description

static Package[]
getLocalUpgradeablePackages() deprecated

No description

static Package[]
getRemotelyUpgradeablePackages() deprecated

No description

static Package[]
getAvailablePackages(bool $filterInstalled = true) deprecated

No description

static Package|null
getByID(int $pkgID) deprecated

No description

static Package
getClass(string $pkgHandle) deprecated

No description

ErrorList|true
testForInstall(bool $testForAlreadyInstalled = true)

Perform tests before this package is installed.

ErrorList|true
testForUpgrade()

Perform tests before this package is upgraded.

ErrorList|true
testForUninstall()

Perform tests before this package is uninstalled.

backup()

Move the current package directory to the trash directory, and rename it with the package handle and a date code.

bool
restore()

If a package was just backed up by this instance of the package object and the packages/package handle directory doesn't exist, this will restore the package from the trash.

getPackageEntityPaths() deprecated

No description

installDatabase()

Installs the packages database through doctrine entities and db.xml database definitions.

installEntitiesDatabase()

No description

static bool|stdClass
installDB(string $xmlFile)

Installs a package database from an XML file.

upgradeCoreData()

Updates the package entity name, description and version using the current class properties.

upgrade()

Upgrades a package's database and refreshes all blocks.

Result[]
upgradePackageThemes()

Upgrade the values of the customizable styles of the themes provided by the package.

upgradeDatabase()

Updates a package's database using entities and a db.xml.

string
getNamespace(bool $withLeadingBackslash = false)

Get the namespace of the package by the package handle.

EntityManager|null
getPackageEntityManager()

Create an entity manager used for the package install, upgrade and unistall process.

EntityManagerInterface
getEntityManager() deprecated

No description

int|null
getPackageID() deprecated

No description

getTranslatableStrings(Translations $translations)

Override this method in your package controller to add strings to the translator, so that you can translate dynamically generated strings.

array
getPackageDependencies()

Return the package dependencies.

string
getErrorText(array|int $errorCode)

Get the error text corresponsing to an error code.

destroyProxyClasses(EntityManagerInterface $em)

Destroys all proxies related to a package.

int
getStyleCustomizerUpdateFlags()

Get the flags to be passed to AvailableVariablesUpdater when upgrading the package themes.

Details

__construct(Application $app)

Initialize the instance.

Parameters

Application $app

the application instance

Package|null getPackageEntity()

Get the associated package entity (if available).

Return Value

Package|null

May return NULL if the package is invalid and/or if it's not installed

setPackageEntity(Package $entity)

Set the associated package entity.

Parameters

Package $entity

Application getApplication()

Get the Application instance.

Return Value

Application

ContentSwapperInterface getContentSwapper()

Get the content swapper.

installContentFile(string $file)

Import a concrete5-cif XML file.

Parameters

string $file

the path to the file, relative to the package directory

bool shouldEnableLegacyNamespace()

Should this package enable legacy namespaces?

This returns true IF:

  1. $this->pkgAutoloaderMapCoreExtensions is false or unset
  2. The required package version > 7.9.9 meaning version 8 or newer
  3. $this->pkgEnableLegacyNamespace is true

Return Value

bool

Liaison getConfig()

Get the default configuration liaison.

Return Value

Liaison

Liaison getDatabaseConfig()

Get the database configuration liaison.

Return Value

Liaison

Liaison getFileConfig()

Get the filesystem configuration liaison.

Return Value

Liaison

array getPackageAutoloaderRegistries()

Get the custom autoloader prefixes to be automatically added to the class loader.

Array keys are the locations (relative to the package directory). Array values are the paths (not relative to the package namespace).

Return Value

array

Examples

['src/PortlandLabs' => \PortlandLabs']

string getPackageHandle()

Get the package handle.

Return Value

string

string getPackageName()

Get the translated name of the package.

Return Value

string

string getPackageDescription()

Get the translated package description.

Return Value

string

string getPackageVersion()

Get the installed package version.

Return Value

string

string getApplicationVersionRequired()

Get the minimum concrete5 version compatible with the package.

Return Value

string

bool showInstallOptionsScreen()

Should the install options page be shown? The install options page may be for install notes and/or full contents swap confirmation.

Return Value

bool

bool hasInstallNotes()

Does this package have install notes?

Return Value

bool

bool hasUninstallNotes()

Does this package have uninstall notes?

Return Value

bool

bool hasInstallPostScreen()

Does this package have a post-install page?

Return Value

bool

bool allowsFullContentSwap()

Does this package clear all existing website content when it's being installed?

Return Value

bool

string getPackagePath()

Get the absolute path to the package.

Return Value

string

string getRelativePath()

Get the path to the package relative to the web root.

Return Value

string

string getRelativePathFromInstallFolder()

Get the path to the package relative to the concrete5 installation folder.

Return Value

string

getTranslationFile($locale)

No description

bool contentProvidesFileThumbnails()

Does this package provide the file thumbnails? If false, the file thumbnails are generated during the install process.

Return Value

bool

Package install()

Install the package info row and the database (doctrine entities and db.xml).

Packages installing additional content should override this method, call the parent method (parent::install()).

Return Value

Package

uninstall()

Uninstall the package:

  • delete the installed items associated to the package
  • destroy the package proxy classes of entities
  • remove the package info row.

string getChangelogContents()

Get the contents of the package's CHANGELOG file.

Return Value

string

if no changelog is available an empty string is returned

static Package[] getInstalledList() deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getInstalledList()

No description

Return Value

Package[]

static string[] getInstalledHandles() deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getInstalledHandles()

No description

Return Value

string[]

static Package|null getByHandle(string $pkgHandle) deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getInstalledHandles()

No description

Parameters

string $pkgHandle

Return Value

Package|null

static Package[] getLocalUpgradeablePackages() deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getLocalUpgradeablePackages()

No description

Return Value

Package[]

static Package[] getRemotelyUpgradeablePackages() deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getRemotelyUpgradeablePackages()

No description

Return Value

Package[]

static Package[] getAvailablePackages(bool $filterInstalled = true) deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getAvailablePackages($filterInstalled)

No description

Parameters

bool $filterInstalled

Return Value

Package[]

static Package|null getByID(int $pkgID) deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getByID($pkgID)

No description

Parameters

int $pkgID

Return Value

Package|null

static Package getClass(string $pkgHandle) deprecated

deprecated Use $app->make('Concrete\Core\Package\PackageService')->getClass($pkgHandle)

No description

Parameters

string $pkgHandle

Return Value

Package

ErrorList|true testForInstall(bool $testForAlreadyInstalled = true)

Perform tests before this package is installed.

Parameters

bool $testForAlreadyInstalled

Set to false to skip checking if this package is already installed

Return Value

ErrorList|true

return true if the package can be installed, an ErrorList instance otherwise

ErrorList|true testForUpgrade()

Perform tests before this package is upgraded.

Return Value

ErrorList|true

return null if the package can be upgraded, an ErrorList instance otherwise

ErrorList|true testForUninstall()

Perform tests before this package is uninstalled.

Return Value

ErrorList|true

return true if the package can be uninstalled, an ErrorList instance otherwise

ErrorList|Package backup()

Move the current package directory to the trash directory, and rename it with the package handle and a date code.

Return Value

ErrorList|Package

return the Package instance if the package has been moved, an ErrorList instance otherwise

bool restore()

If a package was just backed up by this instance of the package object and the packages/package handle directory doesn't exist, this will restore the package from the trash.

Return Value

bool

getPackageEntityPaths() deprecated

deprecated This method was limited. It let you specify a location but in V8 with the Doctrine Entity Manager driver chain we also need to specify namespaces. Instead of specifying entity paths this way, update your package controller to implement the Concrete\Core\Database\EntityManager\Provider\ProviderAggregateInterface, and create a method named getEntityManagerProvider that returns an instance of the Concrete\Core\Database\EntityManager\Provider\ProviderInterface. For example, if I want to specify that my package has entities found at src/PortlandLabs\FooBar\Entity, with the namespace PortlandLabs\FooBar\Entity, my method is simply public function getEntityManagerProvider() { return new StandardPackageProvider($this->app, $this, ['src/MSM/Entity' => 'PortlandLabs\MSM\Entity']); }

No description

installDatabase()

Installs the packages database through doctrine entities and db.xml database definitions.

installEntitiesDatabase()

No description

static bool|stdClass installDB(string $xmlFile)

Installs a package database from an XML file.

Parameters

string $xmlFile

Path to the database XML file

Return Value

bool|stdClass

Returns false if the XML file could not be found

Exceptions

ConnectionException

upgradeCoreData()

Updates the package entity name, description and version using the current class properties.

upgrade()

Upgrades a package's database and refreshes all blocks.

Result[] upgradePackageThemes()

Upgrade the values of the customizable styles of the themes provided by the package.

Return Value

Result[]

array keys are the theme handles

upgradeDatabase()

Updates a package's database using entities and a db.xml.

Exceptions

ConnectionException
Exception

string getNamespace(bool $withLeadingBackslash = false)

Get the namespace of the package by the package handle.

Parameters

bool $withLeadingBackslash

Return Value

string

EntityManager|null getPackageEntityManager()

Create an entity manager used for the package install, upgrade and unistall process.

Return Value

EntityManager|null

EntityManagerInterface getEntityManager() deprecated

deprecated Use $app->make('Doctrine\ORM\EntityManagerInterface')

No description

Return Value

EntityManagerInterface

int|null getPackageID() deprecated

deprecated use the getPackageID method of the package entity

No description

Return Value

int|null

getTranslatableStrings(Translations $translations)

Override this method in your package controller to add strings to the translator, so that you can translate dynamically generated strings.

Parameters

Translations $translations

Examples

If you add to this method these two strings:

<code>
$translations->insert('', 'String without context');
$translations->insert('MyContext', 'String with context');
</code>

Then you'll be able to translate these two strings in the Translator and write translated strings with:

<code>
echo t('String without context');
echo tc('MyContext', 'String with context');
</code>

array getPackageDependencies()

Return the package dependencies.

Return Value

array

See also

Package::$packageDependencies

protected string getErrorText(array|int $errorCode)

Get the error text corresponsing to an error code.

Parameters

array|int $errorCode

one of the Package::EPACKAGE constants, or an array with the first value is one of the Package::EPACKAGE constants and the other values are used to fill in fields

Return Value

string

protected destroyProxyClasses(EntityManagerInterface $em)

Destroys all proxies related to a package.

Parameters

EntityManagerInterface $em

protected int getStyleCustomizerUpdateFlags()

Get the flags to be passed to AvailableVariablesUpdater when upgrading the package themes.

Return Value

int