HEX
Server: Apache
System: Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux
User: u112718762 (3890930)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //homepages/oneclick/WordPress/6.9/601/scripts/factory/configure.php
<?php
namespace Factory;

use \Core\Database;
use \Core\Environment;

use \Exception;

class Configure
{
    protected static $helpText = <<<EOT

    Usage: configure [OPTION]... <app>

        install                                 Install application
        remove                                  Delete application
        configure                               Switch between application modes
        upgrade <current-version> <version>     Upgrade application from <current-version> to <version>
        patch                                   Patch current installation

    Requires minimum PHP 5.5 & MySQL 5.5 versions to assure functionality
    Requires Debian like architectures to ensure maximum stability
    Report bugs to <webhostingapps-bu@1and1.ro>
    For internal use of 1&1 Internet AG application packaging


EOT;

    protected static $allowedCommands = array(
        'install',
        'remove',
        'configure',
        'upgrade',
        'patch',
        'ssl'
    );

    protected $appName;
    protected $commandName;
    protected $commandParams;

    protected $environment;

    public $database;

    public function run($argv)
    {
        try {
            $this->parseArguments($argv);
            $this->validateArguments();
            $this->init();
            $this->openDatabase();
            $this->action();

            print("\nRuntime: " . round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 0) . 's');
            print("\nStatus:  SUCCESS");
            exit(0);

        } catch (Exception $e) {
            print($e);
            print("\nRuntime: " . round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 0) . 's');
            print("\nStatus:  FAILED");
            exit(1);
        }
    }

    private function usage()
    {
        printf(self::$helpText);
        exit(1);
    }

    protected function init()
    {
        $this->initEnv();

        if (false === $this->environment->isLinux()) {
            throw new Exception('Environment is not linux.');
        }

        if (version_compare(preg_replace('/[^0-9.]/', '', PHP_VERSION), '5.5', '<')) {
            throw new Exception('PHP 5.5+ required.');
        }

        $this->environment->systemCheck();
    }

    protected function parseArguments($argv)
    {
        if (count($argv) < 2) {
            $this->usage();
        }

        $this->commandName = $argv[1];
        $this->commandParams = array_slice($argv, 2);
    }

    protected function validateArguments()
    {
        if (!in_array($this->commandName, self::$allowedCommands)) {
            throw new Exception("Command {$this->commandName} is not allowed");
        }
    }

    protected function initEnv()
    {
        $this->environment = new Environment();
    }

    public function openDatabase()
    {
        $this->database = new Database(
            $this->environment->get('DB_main_HOST'),
            $this->environment->get('DB_main_LOGIN'),
            $this->environment->get('DB_main_PASSWORD'),
            $this->environment->get('DB_main_NAME')
        );
    }

    protected function action()
    {
        $wrapperFactory = new Factory();

        $this->appName = strtolower($this->environment->get('applicationName'));

        $wrapper = $wrapperFactory->factory($this->appName, $this->environment, $this->database);

        if (!is_callable(array($wrapper, $this->commandName))) {
            throw new Exception("{$this->commandName} is not callable.");
        }

        call_user_func_array(array($wrapper, $this->commandName), $this->commandParams);
    }
}