Determine the action.

@param EnvironmentInterface $environment The environment.

@return string|null
978409
private function determineAction(EnvironmentInterface $environment)
    {
        foreach (['delete', 'cut', 'copy', 'override', 'edit'] as $action) {
            if ($environment->getInputProvider()->hasValue($action)
                || $environment->getInputProvider()->hasValue($action . '_save')
                || $environment->getInputProvider()->hasValue($action . '_saveNback')
            ) {
                $environment->getInputProvider()->setParameter('mode', $action);

                return $action;
            }
        }

        return null;
    }
1356724
private function getSelectContainer(EnvironmentInterface $environment)
    {
        $inputProvider  = $environment->getInputProvider();
        $sessionStorage = $environment->getSessionStorage();

        $sessionName = $environment->getDataDefinition()->getName() . '.' . $inputProvider->getParameter('mode');
        if (!$sessionStorage->has($sessionName)) {
            return [];
        }

        $selectAction = $inputProvider->getParameter('select');
        if (!$selectAction) {
            return [];
        }

        $session = $sessionStorage->get($sessionName);
        if (!\array_key_exists($selectAction, $session)) {
            return [];
        }

        return $session[$selectAction];
    }
1207440
private function process(Action $action, EnvironmentInterface $environment)
    {
        $inputProvider   = $environment->getInputProvider();
        $translator      = $environment->getTranslator();
        $editInformation = $GLOBALS['container']['dc-general.edit-information'];

        $renderInformation = new \ArrayObject();

        $propertyValueBag = new PropertyValueBag();
        foreach ($this->getOverrideProperties($action, $environment) as $property) {
            $propertyValueBag->setPropertyValue($property->getName(), $property->getDefaultValue());
        }

        if (false !== $inputProvider->hasValue('FORM_INPUTS')) {
            foreach ($inputProvider->getValue('FORM_INPUTS') as $formInput) {
                $propertyValueBag->setPropertyValue($formInput, $inputProvider->getValue($formInput));
            }
        }

        $this->invisibleUnusedProperties($action, $environment);
        $this->handleOverrideCollection($action, $renderInformation, $propertyValueBag, $environment);
        $this->renderFieldSets($action, $renderInformation, $propertyValueBag, $environment);
        $this->updateErrorInformation($renderInformation);

        if (!$editInformation->hasAnyModelError()) {
            $this->handleSubmit($action, $environment);
        }

        return $this->renderTemplate(
            $action,
            [
                'subHeadline' =>
                    $translator->translate('MSC.' . $inputProvider->getParameter('mode') . 'Selected') . ': ' .
                    $translator->translate('MSC.all.0'),
                'fieldsets'   => $renderInformation->offsetGet('fieldsets'),
                'table'       => $environment->getDataDefinition()->getName(),
                'error'       => $renderInformation->offsetGet('error'),
                'breadcrumb'  => $this->renderBreadcrumb($environment),
                'editButtons' => $this->getEditButtons($action, $environment),
                'noReload'    => (bool) $editInformation->hasAnyModelError($action, $environment)
            ]
        );
    }
981204
protected function detectWebEnvironment($environments)
    {
        // If the given environment is just a Closure, we will defer the environment check
        // to the Closure the developer has provided, which allows them to totally swap
        // the webs environment detection logic with their own custom Closure's code.
        if ($environments instanceof Closure) {
            return call_user_func($environments);
        }

        foreach ($environments as $environment => $hosts) {
            // To determine the current environment, we'll simply iterate through the possible
            // environments and look for the host that matches the host for this request we
            // are currently processing here, then return back these environment's names.
            foreach ((array) $hosts as $host) {
                if ($this->isMachine($host)) return $environment;
            }
        }

        return 'production';
    }
720982
public function setup(string $environment = null)
    {
        if (isset($this->initialized['setup'])) {
            return $this;
        }

        $this->initialized['setup'] = true;

        $this->measureTime('_setup', 'Site Setup', function () use ($environment) {
            // Force environment if passed to the method.
            if ($environment) {
                Setup::$environment = $environment;
            }

            $this['setup'];
            $this['streams'];
        });

        return $this;
    }
232328
protected function getFlatCollection(EnvironmentInterface $environment)
    {
        $inputProvider = $environment->getInputProvider();

        $previousItem = null;
        $collection   = [];
        foreach ($this->getClipboardItems($environment) as $clipboardItem) {
            if ('create' === $clipboardItem->getAction()) {
                continue;
            }
            $pasteAfter =
                $previousItem ? $previousItem->getModelId()->getSerialized() : $inputProvider->getParameter('after');

            $collection[$clipboardItem->getModelId()->getSerialized()] = [
                'item'       => $clipboardItem,
                'pasteAfter' => $pasteAfter,
                'pasteMode'  => 'after'
            ];

            $previousItem = $clipboardItem;
        }

        return $collection;
    }
361989
public static function getCurrentSorting(EnvironmentInterface $environment)
    {
        /** @var BackendViewInterface $view */
        $view = $environment->getView();

        foreach ($view->getPanel() as $panel) {
            /** @var PanelInterface $panel */
            $sort = $panel->getElement('sort');
            if ($sort) {
                /** @var SortElementInterface $sort */
                return $sort->getSelectedDefinition();
            }
        }

        /** @var Contao2BackendViewDefinitionInterface $viewSection */
        $viewSection = $environment->getDataDefinition()->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $definition  = $viewSection->getListingConfig()->getGroupAndSortingDefinition();
        if ($definition->hasDefault()) {
            return $definition->getDefault();
        }

        return null;
    }
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'];
    }
30802
public function getEnvironmentRole(Environment $environment)
    {
        $access = $environment->getUser($this->id);

        return $access ? $access->role : false;
    }
654259
public function configure(Environment $environment)
    {
        if ($this->debugMode) {
            $environment->enableDebug();
            $environment->enableAutoReload();
        } else {
            $environment->disableDebug();
            $environment->disableAutoReload();
            $environment->setCache($this->cache);
        }

        $this->applicationConfigure($environment);
    }
861019
public function evaluate(EnvironmentInterface $env)
    {
        $qb = $env->queryBuilder;

        $paramTemplate = $env->newParamName();
        $paramValue = $env->newParamName();
        $paramVs = $env->newParamName();

        $rootAliases = $qb->getRootAliases();
        
        $qb->innerJoin($rootAliases[0] . '.valueSet', $paramVs)
            ->innerJoin($paramVs . '.template', $paramTemplate);

        switch ($this->operator) {
            case 'in':
                $qb->andWhere($paramTemplate . '.id IN (:' . $paramValue . ')');
                break;
            case 'notin':
                $qb->andWhere($paramTemplate . '.id NOT IN (:' . $paramValue . ')');
                break;
        }

        $qb->setParameter($paramValue, $this->getRight()->getValue());
    }
366059
private function isPropertyAllowedByIntersectProperties(
        PropertyInterface $property,
        EnvironmentInterface $environment
    ) {
        $sessionStorage = $environment->getSessionStorage();
        $inputProvider  = $environment->getInputProvider();
        $dataDefinition = $environment->getDataDefinition();

        $session = $sessionStorage->get($dataDefinition->getName() . '.' . $inputProvider->getParameter('mode'));

        return \array_key_exists($property->getName(), $session['intersectProperties']);
    }
150631
protected function currentEnvironment($environment = null, $default = 'development')
    {
        $current = ($environment === null) ? $default : $environment;
        if (empty($environment)) {
            foreach ($this->environments as $name => $config) {
                if ($this->_match($name, $config['params'])) {
                    $current = $name;
                    break;
                }
            }
        }

        return $current;
    }
1289991
public function run( $environment ) {
        $application = NULL;
        if ( class_exists('\App\Application') ) {
            $application = new \App\Application( $this->_container );
            $application->initialize();
        }
        
        $this->_environment = $environment === self::DEVELOPMENT ? self::DEVELOPMENT : self::PRODUCTION;
        
        /* @var $dispatcher \PowerOn\Routing\Dispatcher */
        $dispatcher = $this->_container['Dispatcher'];
        
        /* @var $request \PowerOn\Network\Request */
        $request = $this->_container['Request'];
        
        /* @var $response \PowerOn\Network\Response */
        $response = $this->_container['Response'];
        
        try {
            try {
                //Obtenemos el View del container
                /* @var $view \PowerOn\View\View */
                $view = $this->_container['View'];
                
                //Lanzamos el metodo beforeDispatch de la clase application solo si existe
                !$application ?: $application->beforeDispatch();
                
                //El dispatcher entrega el controlador en caso de que lo encuentre utilizando AltoRouter
                $controller = $dispatcher->handle( $this->_container['AltoRouter'], $request );
                
                //Lanzamos el metodo afterDispatch de la clase application solo si existe
                !$application ?: $application->afterDispatch();
                
                //Obtenemos el layout de la aplicación desde la configuración
                $layout = Config::get('View.layout');
                
                //Establecemos el layout obtenido, si no fue especificado se utilizará el default.phtml
                $view->setLayout($layout ? $layout : 'default');
                
                //Establecemos el template a utilizar por el controlador seleccionado
                $view->setTemplate($dispatcher->action, $dispatcher->controller);
                
                //Inicializamos el View cargando los helpers predefinidos y demás operaciones
                $view->initialize();
                
                //Registramos el container en el controlador cargado
                $controller->registerContainer($this->_container);
                
                //Lanzamos la acción capturada por el dispatcher y altorouter
                $controller->{ $dispatcher->action }();
                
                //Lanzamos el metodo beforeRender de la clase application solo si existe
                !$application ?: $application->beforeRender();
                
                //Renderizamos la respuesta luego de realizar el negocio
                $response->render( $view->getRenderedTemplate() );
                
                //Lanzamos el metodo afterRender de la clase application solo si existe
                !$application ?: $application->afterRender();
            } catch (PowerOnException $e) {
                
                $e->log( $this->_container['Logger'] );
                
                if ( $this->_environment == self::DEVELOPMENT ) {
                    $this->handleDevError($e);
                } else {
                    $message = $e instanceof LogicException ? 'Error interno' : $e->getMessage();
                    throw new InternalErrorException($message, $e->getCode() ? $e->getCode() : NULL, $e);
                }
                
            } catch (\Exception $e) {
                
                if ( $this->_environment == self::DEVELOPMENT ) {
                    $this->handleExternalError($e);
                } else {
                    $reflection = new \ReflectionClass($e);
                    $logger = $this->_container['Logger'];
                    $logger->error($e->getMessage(), [
                        'type' => $reflection->getShortName(),
                        'code' => $e->getCode(),
                        'line' => $e->getLine(),
                        'file' => $e->getFile(),
                        'trace' => $e->getTrace()
                    ]);
                    throw new InternalErrorException('Error interno', $e->getCode() ? $e->getCode() : NULL, $e);
                }
                
            }
        } catch (InternalErrorException $e) {
            $this->handleProdError($e);
        }
    }
115667
protected function getModel(EnvironmentInterface $environment)
    {
        $modelId      = ModelId::fromSerialized($environment->getInputProvider()->getParameter('id'));
        $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        if ($model) {
            return $model;
        }

        $eventDispatcher = $environment->getEventDispatcher();

        $eventDispatcher->dispatch(
            ContaoEvents::SYSTEM_LOG,
            new LogEvent(
                \sprintf(
                    'Could not find ID %s in %s. DC_General show()',
                    $modelId->getId(),
                    $environment->getDataDefinition()->getName()
                ),
                __CLASS__ . '::' . __FUNCTION__,
                TL_ERROR
            )
        );

        $eventDispatcher->dispatch(
            ContaoEvents::CONTROLLER_REDIRECT,
            new RedirectEvent('contao?act=error')
        );

        return null;
    }
1133298
public static function redirectHome(EnvironmentInterface $environment)
    {
        $input = $environment->getInputProvider();

        if ($input->hasParameter('table') && ($hasParentId = $input->hasParameter('pid'))) {
            if ($hasParentId) {
                $event = new RedirectEvent(
                    \sprintf(
                        'contao?do=%s&table=%s&pid=%s',
                        $input->getParameter('do'),
                        $input->getParameter('table'),
                        $input->getParameter('pid')
                    )
                );
            } else {
                $event = new RedirectEvent(
                    \sprintf(
                        'contao?do=%s&table=%s',
                        $input->getParameter('do'),
                        $input->getParameter('table')
                    )
                );
            }
        } else {
            $event = new RedirectEvent(
                \sprintf(
                    'contao?do=%s',
                    $input->getParameter('do')
                )
            );
        }

        $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_REDIRECT, $event);
    }
604327
protected function getSelectButtons(EnvironmentInterface $environment)
    {
        $languageDomain = 'contao_' . $environment->getDataDefinition()->getName();

        $confirmMessage = \htmlentities(
            \sprintf(
                '<h2 class="tl_error">%s</h2>' .
                '<p></p>' .
                '<div class="tl_submit_container">' .
                '<input class="%s" value="%s" onclick="%s">' .
                '</div>',
                StringUtil::specialchars($this->translate('MSC.nothingSelect', $languageDomain)),
                'tl_submit',
                StringUtil::specialchars($this->translate('MSC.close', $languageDomain)),
                'BackendGeneral.hideMessage(); return false;'
            )
        );
        $onClick        = 'BackendGeneral.confirmSelectOverrideEditAll(this, \'properties[]\', \'' .
                          $confirmMessage . '\'); return false;';

        $continueName        = $environment->getInputProvider()->getParameter('mode');
        $buttons['continue'] = \sprintf(
            '<input type="submit" name="%s" id="%s" class="tl_submit" accesskey="%s" value="%s" onclick="%s">',
            $continueName,
            $continueName,
            'c',
            StringUtil::specialchars($this->translate('MSC.continue', $languageDomain)),
            $onClick
        );

        return $buttons;
    }