@param Environment $environment

@return int
178398
protected function listProperties(Environment $environment)
    {
        $headings = [];
        $values = [];
        foreach ($environment->getProperties() as $key => $value) {
            $headings[] = new AdaptiveTableCell($key, ['wrap' => false]);
            $values[] = $this->formatter->format($value, $key);
        }
        /** @var \Platformsh\Cli\Service\Table $table */
        $table = $this->getService('table');
        $table->renderSimple($values, $headings);

        return 0;
    }
744697
public static function is($environment = null)
    {
        $current = Configure::read('Environment.name');

        if (! $environment) {
            return $current;
        }

        return $current === $environment;
    }
1247052
private function collectIntersectModelProperties(CollectionInterface $collection, EnvironmentInterface $environment)
    {
        $palettesDefinition = $environment->getDataDefinition()->getPalettesDefinition();

        $properties = [];
        foreach ($collection->getIterator() as $model) {
            $palette = $palettesDefinition->findPalette($model);

            $modelProperties = $this->getVisibleAndEditAbleProperties($palette, $model);
            foreach ($modelProperties as $modelProperty) {
                if (!$properties[$modelProperty]) {
                    $properties[$modelProperty] = 0;
                }

                ++$properties[$modelProperty];
            }
        }

        return \array_filter(
            $properties,
            function ($count) use ($collection) {
                return $count === $collection->count();
            }
        );
    }
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;
    }
946844
protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->bootstrap($input, $output);

        $environment = $input->getOption('environment');
        $environment = is_scalar($environment) ? (string)$environment : null;

        if ($environment === null) {
            $environment = $this->getConfig()->getDefaultEnvironment();
            $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
        } else {
            $output->writeln('<info>using environment</info> ' . $environment);
        }

        if (!is_string($environment)) {
            throw new RuntimeException('Invalid or missing environment');
        }

        $envOptions = $this->getConfig()->getEnvironment($environment);
        if (isset($envOptions['adapter']) && $envOptions['adapter'] != 'mysql') {
            $output->writeln('<error>adapter not supported</error> ' . $envOptions['adapter']);

            return 1;
        }
        if (isset($envOptions['name'])) {
            $output->writeln('<info>using database</info> ' . $envOptions['name']);
        } else {
            $output->writeln('<error>Could not determine database name! Please specify a database name in your config file.</error>');

            return 1;
        }

        // Load config and database adapter
        $manager = $this->getManager();

        if (!$manager) {
            throw new RuntimeException('Manager not found');
        }

        $config = $manager->getConfig();

        $configFilePath = $config->getConfigFilePath();
        $output->writeln('<info>using config file</info> ' . $configFilePath);

        // First, try the non-interactive option:
        $migrationsPaths = $input->getOption('path');
        if (empty($migrationsPaths)) {
            $migrationsPaths = $config->getMigrationPaths();
        }

        $migrationsPaths = is_array($migrationsPaths) ? $migrationsPaths : (array)$migrationsPaths;

        // No paths? That's a problem.
        if (empty($migrationsPaths[0])) {
            throw new RuntimeException('No migration paths set in your Phinx configuration file.');
        }

        $migrationsPath = (string)$migrationsPaths[0];
        $this->verifyMigrationDirectory($migrationsPath);

        $output->writeln('<info>using migration path</info> ' . $migrationsPath);

        $schemaFile = $migrationsPath . DIRECTORY_SEPARATOR . 'schema.php';
        $output->writeln('<info>using schema file</info> ' . $schemaFile);

        // Gets the database adapter.
        $dbAdapter = $manager->getEnvironment($environment)->getAdapter();

        $pdo = $this->getPdo($manager, $environment);

        $foreignKeys = $config->offsetExists('foreign_keys') ? $config->offsetGet('foreign_keys') : false;

        $defaultMigrationTable = $envOptions['default_migration_table'] ?? 'phinxlog';

        $name = $input->getOption('name');
        $overwrite = $input->getOption('overwrite');

        $settings = [
            'pdo' => $pdo,
            'manager' => $manager,
            'environment' => $environment,
            'adapter' => $dbAdapter,
            'schema_file' => $schemaFile,
            'migration_path' => $migrationsPaths[0],
            'foreign_keys' => $foreignKeys,
            'config_file' => $configFilePath,
            'name' => $name,
            'overwrite' => $overwrite,
            'mark_migration' => true,
            'default_migration_table' => $defaultMigrationTable,
        ];

        $dba = new MySqlSchemaAdapter($pdo, $output);
        $generator = new MigrationGenerator($settings, $input, $output, $dba);

        return $generator->generate();
    }
1190583
protected function process(EnvironmentInterface $environment)
    {
        $inputProvider = $environment->getInputProvider();
        $modelId       = ModelId::fromSerialized($inputProvider->getParameter('id'));
        $dataProvider  = $environment->getDataProvider($modelId->getDataProviderName());

        $view = $environment->getView();
        if (!$view instanceof BaseView) {
            return false;
        }

        $this->checkRestoreVersion($environment, $modelId);

        if (!($model = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId())))) {
            throw new DcGeneralRuntimeException('Could not retrieve model with id ' . $modelId->getSerialized());
        }

        $clone = clone $model;
        $clone->setId($model->getId());

        if ('select' !== $inputProvider->getParameter('act')) {
            $this->handleGlobalCommands($environment);
        }

        return (new EditMask($view, $model, $clone, null, null, $view->breadcrumb()))->execute();
    }
428003
private function checkPermission(EnvironmentInterface $environment)
    {
        $dataDefinition = $environment->getDataDefinition();

        if (true === $dataDefinition->getBasicDefinition()->isCreatable()) {
            return true;
        }

        return \sprintf(
            '<div style="text-align:center; font-weight:bold; padding:40px;">
                You have no permission for create model in %s.
            </div>',
            $dataDefinition->getName()
        );
    }
530561
protected function activateMultiple(array $environments, InputInterface $input, OutputInterface $output)
    {
        $parentId = $input->getOption('parent');
        if ($parentId && !$this->api()->getEnvironment($parentId, $this->getSelectedProject())) {
            $this->stdErr->writeln(sprintf('Parent environment not found: <error>%s</error>', $parentId));
            return false;
        }

        $count = count($environments);
        $processed = 0;
        // Confirm which environments the user wishes to be activated.
        $process = [];
        /** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
        $questionHelper = $this->getService('question_helper');
        foreach ($environments as $environment) {
            if (!$environment->operationAvailable('activate', true)) {
                if ($environment->isActive()) {
                    $output->writeln("The environment " . $this->api()->getEnvironmentLabel($environment) . " is already active.");
                    $count--;
                    continue;
                }

                $output->writeln(
                    "Operation not available: The environment " . $this->api()->getEnvironmentLabel($environment, 'error') . " can't be activated."
                );
                continue;
            }
            $question = "Are you sure you want to activate the environment " . $this->api()->getEnvironmentLabel($environment) . "?";
            if (!$questionHelper->confirm($question)) {
                continue;
            }
            $process[$environment->id] = $environment;
        }
        $activities = [];
        /** @var Environment $environment */
        foreach ($process as $environmentId => $environment) {
            try {
                if ($parentId && $parentId !== $environment->parent && $parentId !== $environmentId) {
                    $output->writeln(sprintf(
                        'Setting parent of environment <info>%s</info> to <info>%s</info>',
                        $environmentId,
                        $parentId
                    ));
                    $result = $environment->update(['parent' => $parentId]);
                    $activities = array_merge($activities, $result->getActivities());
                }
                $output->writeln(sprintf(
                    'Activating environment <info>%s</info>',
                    $environmentId
                ));
                $activities[] = $environment->activate();
                $processed++;
            } catch (\Exception $e) {
                $output->writeln($e->getMessage());
            }
        }

        $success = $processed >= $count;

        if ($processed) {
            if ($this->shouldWait($input)) {
                /** @var \Platformsh\Cli\Service\ActivityMonitor $activityMonitor */
                $activityMonitor = $this->getService('activity_monitor');
                $result = $activityMonitor->waitMultiple($activities, $this->getSelectedProject());
                $success = $success && $result;
            }
            $this->api()->clearEnvironmentsCache($this->getSelectedProject()->id);
        }

        return $success;
    }
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));
            }
        }
    }
892103
protected function getCollection(EnvironmentInterface $environment)
    {
        $dataDefinition = $environment->getDataDefinition();
        $relationShip   = $dataDefinition->getModelRelationshipDefinition();

        if (!$relationShip->getChildCondition($dataDefinition->getName(), $dataDefinition->getName())) {
            return $this->getFlatCollection($environment);
        }

        return $this->getHierarchyCollection($this->getClipboardItems($environment), $environment);
    }
829729
public function populate(EnvironmentInterface $environment)
    {
        if (!$this->scopeDeterminator->currentScopeIsBackend()) {
            return;
        }

        $this->populateView($environment);
        $this->populatePanel($environment);
    }
1190556
public function environment(...$environments)
    {
        if (count($environments) > 0) {
            $patterns = is_array($environments[0]) ? $environments[0] : $environments;

            return Str::is($patterns, $this['env']);
        }

        return $this['env'];
    }
148904
protected function loadCollection(EnvironmentInterface $environment)
    {
        $dataConfig    = $environment->getBaseConfigRegistry()->getBaseConfig();
        $listingConfig = $this->getViewSection($environment->getDataDefinition())->getListingConfig();
        $panel         = $environment->getView()->getPanel();

        ViewHelpers::initializeSorting($panel, $dataConfig, $listingConfig);

        return $environment->getDataProvider()->fetchAll($dataConfig);
    }
1361855
public function patch(
        EnvironmentInterface $environment
    ) {
        $this->copyDirectory(
            $environment->getDefaultsFilesystem(),
            $environment->getIdeConfigFilesystem(),
            'fileTemplates'
        );

        $this->patchWorkspaceConfig(
            $environment->getIdeConfigFilesystem()
        );
    }
1050934
public function evaluate(EnvironmentInterface $env)
    {
        $qb = $env->queryBuilder;
        
        $value = $env->newParamName();

        $joins = $qb->getDqlPart('join');
        if (!isset($joins[$this->relation])) {
            $qb->leftJoin('a.'.$this->relation, $this->relation);
        }

        switch ($this->operator) {
            case 'equals':
                $qb->andWhere($this->relation.'.'.$this->attribute.' = :'.$value);
                $qb->setParameter($value, $this->getRight()->getValue());
                break;
            case 'notequals':
                $qb->andWhere($this->relation.'.'.$this->attribute.' <> :'.$value);
                $qb->setParameter($value, $this->getRight()->getValue());
                break;
            case 'contains':
                $qb->andWhere($this->relation.'.'.$this->attribute.' LIKE :'.$value);
                $qb->setParameter($value, '%'. $this->getRight()->getValue().'%');
                break;
            case 'greaterthan':
                $qb->andWhere($this->relation.'.'.$this->attribute.' > :'.$value);
                $qb->setParameter($value, $this->getRight()->getValue());
                break;
            case 'lessthan':
                $qb->andWhere($this->relation.'.'.$this->attribute.' < :'.$value);
                $qb->setParameter($value, $this->getRight()->getValue());
                break;
        }
    }
792734
public function evaluate(EnvironmentInterface $env)
    {
        $qb = $env->queryBuilder;

        $paramName = $env->newParamName();
        $paramValue = $env->newParamName();

        $paramContent = $env->newParamName();
        $paramVs = $env->newParamName();
        $paramValues = $env->newParamName();
        $paramAttribute = $env->newParamName();

        $subQuery = $env->cloneQueryBuilder();

        $rootAliases = $subQuery->getRootAliases();
        $subQuery
            ->innerJoin($rootAliases[0].'.valueSet', $paramVs)
            ->innerJoin($paramVs.'.values', $paramValues)
            ->innerJoin($paramValues.'.attribute', $paramAttribute)
            ->andWhere($paramAttribute.'.name = :'.$paramName);

        switch ($this->operator) {
            case 'equals':
                $subQuery->andWhere($paramValues.'.value = :'.$paramValue);
                $qb->setParameter($paramValue, $this->getRight()->getValue());
                break;
            case 'notequals':
                $subQuery->andWhere($paramValues.'.value <> :'.$paramValue);
                $qb->setParameter($paramValue, $this->getRight()->getValue());
                break;
            case 'contains':
                $subQuery->andWhere($paramValues.'.value LIKE :'.$paramValue);
                $qb->setParameter($paramValue, '%'. $this->getRight()->getValue().'%');
                break;
        }

        $qb
            ->andWhere($qb->expr()->in('a', $subQuery->getDQL()))
            ->setParameter($paramName, $this->getAttribute())
        ;
    }
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;
    }