Returns all available definitions for a specific environment.

@param Environment $environment

@return Transformation[]
3340
public function getEnvironmentTransformations(Environment $environment)
    {
        return array_filter(
            $this->environmentManager->readEnvironmentCallees($environment),
            function (Callee $callee) {
                return $callee instanceof Transformation;
            }
        );
    }
695692
final protected function getEnv() : array
    {
        $envMask = $this->contexts['env'];
        $env = empty($envMask)
            ? $_SERVER
            : array_intersect_key($_SERVER, array_flip($envMask));

        return $env;
    }
1125828
private function _translateRoles(
        $environmentInfo,
        RoleInstance $currentInstance,
        $currentRole
    ) {
        $rolesMap = [];

        $rolesInfo = Utilities::tryGetKeysChainValue(
            $environmentInfo,
            'Roles',
            'Role'
        );

        if (!is_null($rolesInfo)) {
            if (array_key_exists('@attributes', $rolesInfo)) {
                $rolesInfo = [0 => $rolesInfo];
            }

            foreach ($rolesInfo as $roleInfo) {
                $roleInstances = $this->_translateRoleInstances($roleInfo);

                if ($roleInfo['@attributes']['name'] == $currentRole) {
                    $roleInstances[$currentInstance->getId()] = $currentInstance;
                }

                $role = new Role($roleInfo['@attributes']['name'], $roleInstances);

                foreach ($roleInstances as $instance) {
                    $instance->setRole($role);
                }

                $rolesMap[$roleInfo['@attributes']['name']] = $role;
            }
        }

        if (!array_key_exists($currentRole, $rolesMap)) {
            $roleInstances = [];
            $roleInstances[$currentInstance->getId()] = $currentInstance;

            $singleRole = new Role($currentRole, $roleInstances);
            $currentInstance->setRole($singleRole);

            $rolesMap[$currentRole] = $singleRole;
        }

        return $rolesMap;
    }
1324772
public static function determineAuthorization(Environment $environment)
    {
        $authorization = $environment->get('HTTP_AUTHORIZATION');
        if (!empty($authorization) || !is_callable('getallheaders')) {
            return $environment;
        }

        $headers = getallheaders();
        if (!is_array($headers)) {
            return $environment;
        }

        $headers = array_change_key_case($headers, CASE_LOWER);
        if (isset($headers['authorization'])) {
            $environment->set('HTTP_AUTHORIZATION', $headers['authorization']);
        }

        return $environment;
    }
1184150
private function getEnvironmentVariables()
    {
        // Initialize from globals, allow override of special keys via putenv calls.
        $variables = $this->inheritEnvironment
            ? array_replace($_ENV, $_SERVER, $this->environment)
            : $this->environment;

        foreach (array_keys($variables) as $name) {
            if (false !== ($value = getenv($name))) {
                $variables[$name] = $value;
            }
        }

        return $variables;
    }
887091
public static function setEnvironment($environment) {
        if (!empty($environment)) {
            foreach (array_values(static::$registeredInstances) as $instance) {
                $instance->setEnvironment($environment);
            }
            static::$ENVIRONMENT = $environment;
        } 
        
    }
1153712
private function isSortable(EnvironmentInterface $environment)
    {
        return ((true === (bool) ViewHelpers::getManualSortingProperty($environment))
                && (true === $environment->getDataDefinition()->getBasicDefinition()->isEditable()));
    }
251433
public function getEnvironmentsForCheckout()
    {
        $project = $this->getWelcomeCommand()->getCurrentProject();
        if (!$project) {
            return [];
        }
        try {
            $currentEnvironment = $this->getWelcomeCommand()->getCurrentEnvironment($project, false);
        } catch (\Exception $e) {
            $currentEnvironment = false;
        }
        $environments = $this->api->getEnvironments($project, false, false);
        if ($currentEnvironment) {
            $environments = array_filter(
                $environments,
                function ($environment) use ($currentEnvironment) {
                    return $environment->id !== $currentEnvironment->id;
                }
            );
        }

        return array_keys($environments);
    }
1027210
private function findDirectoriesFromEnvironment(Environment $environment) : array
    {
        $finderBlacklist = $this->finderFactory->build();
        $finderBlacklist->in($environment->getRootDirectory())->directories();
        foreach ($environment->getBlacklistedDirectories() as $blacklistedDirectory) {
            $finderBlacklist->path('/' . preg_quote($blacklistedDirectory, '/') . '$/')
                ->notPath('/' . preg_quote($blacklistedDirectory, '/') . './');
        }
        $rawExcludePathsByBlacklist = $this->finderToRealPathConverter->finderToArrayOfPaths($finderBlacklist);
        return $rawExcludePathsByBlacklist;
    }
1374393
protected function getSearchDirs(/*# string */ $env)/*# : array */
    {
        if (!isset($this->sub_dirs[$env])) {
            $this->sub_dirs[$env] = $this->buildSearchDirs($env);
        }
        return $this->sub_dirs[$env];
    }
484637
public static function parseAllEnvironmentParameters(): array
	{
		$parameters = [];
		foreach ($_SERVER as $key => $value) {
			// Ensure value
			$value = getenv($key);
			if ($value !== false) {
				$parameters[$key] = $value;
			}
		}

		return $parameters;
	}
983531
public function parseHeaders(EnvironmentInterface $environment)
    {
        foreach ($environment as $key => $value) {
            $key = strtoupper($key);

            if (strpos($key, 'HTTP_') === 0 || in_array($key, $this->special)) {
                if ($key === 'HTTP_CONTENT_TYPE' || $key === 'HTTP_CONTENT_LENGTH') {
                    continue;
                }

                parent::set($this->normalizeKey($key), array($value));
            }
        }
    }
31992
private function _translateConfigurationSettings($environmentInfo)
    {
        $configurationSettings = [];

        $settingsInfo = Utilities::tryGetKeysChainValue(
            $environmentInfo,
            'CurrentInstance',
            'ConfigurationSettings',
            'ConfigurationSetting'
        );

        if (!is_null($settingsInfo)) {
            if (array_key_exists('@attributes', $settingsInfo)) {
                $settingsInfo = [0 => $settingsInfo];
            }

            foreach ($settingsInfo as $settingInfo) {
                $configurationSettings
                    [$settingInfo['@attributes']['name']] = $settingInfo
                        ['@attributes']['value'];
            }
        }

        return $configurationSettings;
    }
1194796
public function getKeys($env, $prefix = null)
	{
		$this->validateEnvironment($env);

		$env  = $env === self::APP ? self::EXT : self::APP;
		$keys = array_keys($this->definitions[$env]);

		if ($prefix !== null) {
			$keys = array_map(function ($key) use ($prefix) {
				return $prefix . $key;
			}, $keys);
		}

		return $keys;
	}
638029
private function doLocateFiles(string $path, string $environment): array
    {
        $fullPaths = array_filter(array_map(static function (string $fixturePath) use ($environment, $path): string {
            return '' !== $environment
                ? sprintf('%s/%s/%s', $path, $fixturePath, $environment)
                : sprintf('%s/%s', $path, $fixturePath);
        }, $this->fixturePaths), function ($fullPath) {
            return $fullPath && file_exists($fullPath);
        });

        if ([] === $fullPaths) {
            return [];
        }

        $files = SymfonyFinder::create()->files()->in($fullPaths)->depth(0)->name('/.*\.(ya?ml|php)$/i');

        // this sort helps to set an order with filename
        // ( "001-root-level-fixtures.yml", "002-another-level-fixtures.yml", ... )
        $files = $files->sort(function ($a, $b) {
            return strcasecmp($a, $b);
        });

        $fixtureFiles = [];

        foreach ($files as $file) {
            $fixtureFiles[$file->getRealPath()] = true;
        }

        return array_keys($fixtureFiles);
    }
873827
public function getMigrations($environment)
    {
        if ($this->migrations === null) {
            $phpFiles = $this->getMigrationFiles();

            if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
                $this->getOutput()->writeln('Migration file');
                $this->getOutput()->writeln(
                    array_map(
                        function ($phpFile) {
                            return "    <info>{$phpFile}</info>";
                        },
                        $phpFiles
                    )
                );
            }

            // filter the files to only get the ones that match our naming scheme
            $fileNames = [];
            /** @var \Phinx\Migration\AbstractMigration[] $versions */
            $versions = [];

            foreach ($phpFiles as $filePath) {
                if (Util::isValidMigrationFileName(basename($filePath))) {
                    if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
                        $this->getOutput()->writeln("Valid migration file <info>{$filePath}</info>.");
                    }

                    $version = Util::getVersionFromFileName(basename($filePath));

                    if (isset($versions[$version])) {
                        throw new \InvalidArgumentException(sprintf('Duplicate migration - "%s" has the same version as "%s"', $filePath, $versions[$version]->getVersion()));
                    }

                    $config = $this->getConfig();
                    $namespace = $config instanceof NamespaceAwareInterface ? $config->getMigrationNamespaceByPath(dirname($filePath)) : null;

                    // convert the filename to a class name
                    $class = ($namespace === null ? '' : $namespace . '\\') . Util::mapFileNameToClassName(basename($filePath));

                    if (isset($fileNames[$class])) {
                        throw new \InvalidArgumentException(sprintf(
                            'Migration "%s" has the same name as "%s"',
                            basename($filePath),
                            $fileNames[$class]
                        ));
                    }

                    $fileNames[$class] = basename($filePath);

                    if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
                        $this->getOutput()->writeln("Loading class <info>$class</info> from <info>$filePath</info>.");
                    }

                    // load the migration file
                    $orig_display_errors_setting = ini_get('display_errors');
                    ini_set('display_errors', 'On');
                    /** @noinspection PhpIncludeInspection */
                    require_once $filePath;
                    ini_set('display_errors', $orig_display_errors_setting);
                    if (!class_exists($class)) {
                        throw new \InvalidArgumentException(sprintf(
                            'Could not find class "%s" in file "%s"',
                            $class,
                            $filePath
                        ));
                    }

                    if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
                        $this->getOutput()->writeln("Running <info>$class</info>.");
                    }

                    // instantiate it
                    $migration = new $class($environment, $version, $this->getInput(), $this->getOutput());

                    if (!($migration instanceof AbstractMigration)) {
                        throw new \InvalidArgumentException(sprintf(
                            'The class "%s" in file "%s" must extend \Phinx\Migration\AbstractMigration',
                            $class,
                            $filePath
                        ));
                    }

                    $versions[$version] = $migration;
                } else {
                    if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
                        $this->getOutput()->writeln("Invalid migration file <error>{$filePath}</error>.");
                    }
                }
            }

            ksort($versions);
            $this->setMigrations($versions);
        }

        return $this->migrations;
    }
1310287
public function environment(...$environments)
    {
        $env = \env('APP_ENV', 'production');

        if (\func_num_args() > 0) {
            $patterns = \is_array($environments[0]) ? $environments[0] : $environments;

            foreach ($patterns as $pattern) {
                if (Str::is($pattern, $env)) {
                    return true;
                }
            }

            return false;
        }

        return $env;
    }