Skip to content

[FEATURE][QUESTION] Operation "GetApplicationContext" #26

@Teisi

Description

@Teisi

Why do you return for TYPO3 >= 11 only the three static ApplicationContexts (Production, Development, Testing)?

You have changed it to:

if (version_compare(TYPO3_version, '11.0.0', '>=')) {
    $applicationContext = Environment::getContext();
    if ($applicationContext->isDevelopment()) {
        return new OperationResult(true, 'Development');
    }
    if ($applicationContext->isTesting()) {
        return new OperationResult(true, 'Testing');
    }
    if ($applicationContext->isProduction()) {
        return new OperationResult(true, 'Production');
    }
    return new OperationResult(true, $applicationContext->__toString());
}

$applicationContext = GeneralUtility::getApplicationContext();
return new OperationResult(true, $applicationContext->__toString());

but wouldn't it be better to return custom ApplicationContexts too? Like e. g. :

if (version_compare(TYPO3_version, '11.0.0', '>=')) {
    $applicationContext = Environment::getContext();
    return new OperationResult(true, $applicationContext->__toString());
}

$applicationContext = GeneralUtility::getApplicationContext();
return new OperationResult(true, $applicationContext->__toString());

And the class "Environment" exists since TYPO3 9.5 so it should be possible to write something like:
(https://api.typo3.org/9.5/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_core_1_1_environment.html#a6a0c7770cada6b990d22855b04639698)

if (version_compare(TYPO3_version, '9.5.0', '>=')) { ....

And constant "TYPO3_version" is depricated since TYPO3 10.3 so i think the code could look like this (yes?):
(https://docs.typo3.org/c/typo3/cms-core/10.4/en-us/Changelog/10.3/Deprecation-90007-GlobalConstantsTYPO3_versionAndTYPO3_branch.html)

if(defined(TYPO3_version)) {
    $typo3Version = TYPO3_version;
} else {
    $typo3VersionClass = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
    $typo3Version = $typo3VersionClass->getVersion();
}

if (version_compare($typo3Version, '9.5.0', '>=')) {
    $applicationContext = Environment::getContext();
    return new OperationResult(true, $applicationContext->__toString());
}

$applicationContext = GeneralUtility::getApplicationContext();
return new OperationResult(true, $applicationContext->__toString());

Changed this allready at our fork: https://github.com/Teisi/zabbix_client/blob/master/Classes/Operation/GetApplicationContext.php

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions