Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Teisi opened this issue Aug 10, 2021 · 0 comments
Open

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

Teisi opened this issue Aug 10, 2021 · 0 comments

Comments

@Teisi
Copy link

Teisi commented Aug 10, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant