Pimcore\Config::getEnvironment PHP Method

getEnvironment() public static method

public static getEnvironment ( ) : string
return string
    public static function getEnvironment()
    {
        // null means that it wasn't checked, false means it was checked already, but not environment available
        if (self::$environment === null) {
            // check environment variables
            self::$environment = getenv("PIMCORE_ENVIRONMENT") ?: (getenv("REDIRECT_PIMCORE_ENVIRONMENT") ?: false);
            if (!self::$environment && isset($_SERVER["argv"]) && is_array($_SERVER["argv"])) {
                // check CLI option: --environment[=ENVIRONMENT]
                foreach ($_SERVER["argv"] as $argument) {
                    if (preg_match("@\\-\\-environment=(.*)@", $argument, $matches)) {
                        self::$environment = $matches[1];
                        break;
                    }
                }
            }
        }
        return self::$environment;
    }

Usage Example

示例#1
0
 /**
  * @param $documentId
  * @param $config
  * @throws \Exception
  */
 public function preparePdfGeneration($documentId, $config)
 {
     $document = $this->getPrintDocument($documentId);
     if (Model\Tool\TmpStore::get($document->getLockKey())) {
         throw new \Exception("Process with given document alredy running.");
     }
     Model\Tool\TmpStore::add($document->getLockKey(), true);
     $jobConfig = new \stdClass();
     $jobConfig->documentId = $documentId;
     $jobConfig->config = $config;
     $this->saveJobConfigObjectFile($jobConfig);
     $this->updateStatus($documentId, 0, "prepare_pdf_generation");
     $args = ["-p " . $jobConfig->documentId];
     $env = \Pimcore\Config::getEnvironment();
     if ($env !== false) {
         $args[] = "--environment=" . $env;
     }
     $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " web2print:pdf-creation " . implode(" ", $args);
     Logger::info($cmd);
     if (!$config['disableBackgroundExecution']) {
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "web2print-output.log");
     } else {
         Processor::getInstance()->startPdfGeneration($jobConfig->documentId);
     }
 }
All Usage Examples Of Pimcore\Config::getEnvironment