@TODO Bad code. :/

@param string $stage
486420
private function send404($stage = 'not set')
    {
        $msg = $stage . ' - Page not found';

        if ($this->router->isAjax()) {
            $cmd = new \Core\Ajax\Commands\Dom\HtmlCommand('#content', $msg);
            $ajax = $this->di->get('core.ajax');
            $ajax->addCommand($cmd);

            $result = $ajax->process();

            return $result;
        }

        $this->http->header->sendHttpError(404);

        return $msg;
    }
581883
public function writeToStage($stage, $forceInsert = false)
    {
        ReadingMode::validateStage($stage);
        $owner = $this->owner;
        return static::withVersionedMode(function () use ($stage, $forceInsert, $owner) {
            $oldParams = $owner->getSourceQueryParams();
            try {
                // Lazy load and reset version in current stage prior to resetting write stage
                $owner->forceChange();
                $owner->Version = null;

                // Migrate stage prior to write
                Versioned::set_stage($stage);
                $owner->setSourceQueryParam('Versioned.mode', 'stage');
                $owner->setSourceQueryParam('Versioned.stage', $stage);

                // Write
                $owner->invokeWithExtensions('onBeforeWriteToStage', $toStage, $forceInsert);
                return $owner->write(false, $forceInsert);
            } finally {
                // Revert global state
                $owner->invokeWithExtensions('onAfterWriteToStage', $toStage, $forceInsert);
                $owner->setSourceQueryParams($oldParams);
            }
        });
    }
20490
private void createStageIfNeeded() throws BindException
  {
    if (session.getArrayBindStage() != null)
    {
      return;
    }
    synchronized (session)
    {
      // another thread may have created the session by the time we enter this block
      if (session.getArrayBindStage() == null)
      {
        try
        {
          SFStatement statement = new SFStatement(session);
          statement.execute(CREATE_STAGE_STMT, null, null);
          session.setArrayBindStage(STAGE_NAME);
        }
        catch (SFException | SQLException ex)
        {
          // to avoid repeated failures to create stage, disable array bind stage
          // optimization if we fail to create stage for some reason
          session.setArrayBindStageThreshold(0);
          throw new BindException(
              String.format("Failed to create temporary stage for array binds. %s", ex.getMessage()), BindException.Type.UPLOAD);
        }
      }
    }
  }
32880
protected function doExecutePlugins(&$plugins, $stage)
    {
        $success = true;

        foreach ($plugins as $plugin => $options) {
            $this->logger->log(Lang::get('running_plugin', $plugin));

            $this->setPluginStatus($stage, $plugin, Build::STATUS_RUNNING);

            // Try and execute it
            if ($this->executePlugin($plugin, $options)) {
                // Execution was successful
                $this->logger->logSuccess(Lang::get('plugin_success'));
                $this->setPluginStatus($stage, $plugin, Build::STATUS_SUCCESS);
            } else {
                // Execution failed
                $this->logger->logFailure(Lang::get('plugin_failed'));
                $this->setPluginStatus($stage, $plugin, Build::STATUS_FAILED);

                if ($stage === 'setup') {
                    // If we're in the "setup" stage, execution should not continue after
                    // a plugin has failed:
                    throw new Exception('Plugin failed: ' . $plugin);
                } elseif ($stage === 'test') {
                    // If we're in the "test" stage and the plugin is not allowed to fail,
                    // then mark the build as failed:
                    if (empty($options['allow_failures'])) {
                        $success = false;
                    }
                }
            }
        }

        return $success;
    }
907781
public static function begin($firstStageForm) : StagedForm
    {
        $firstStage = self::parseStage($firstStageForm);

        if (!($firstStage instanceof IndependentFormStage)) {
            throw InvalidArgumentException::format(
                    'Invalid form stage argument: first stage must be independent, callable with required parameter given'
            );
        }

        return new self($firstStage);
    }
1276188
public void debug(UserFeedbackEvent.Stage stage, String message) {
    Log.debug(stage+": "+message);
    addEvent(new UserFeedbackEvent(autoML, UserFeedbackEvent.Level.Debug, stage, message));
  }
271273
@Override
    public void execute(@Nonnull final LifecycleStage lifecycleStage)
    {
        List<LifecycleListener> lifecycleListeners = listeners.get(lifecycleStage);
        if (lifecycleListeners == null) {
            throw illegalStage(lifecycleStage);
        }

        log("Stage '%s' starting...", lifecycleStage.getName());

        // Reverse the order for the STOP stage, so that dependencies are torn down in reverse order.
        if (lifecycleStage.equals(LifecycleStage.STOP_STAGE)) {
            lifecycleListeners = Lists.reverse(lifecycleListeners);
        }

        for (final LifecycleListener listener : lifecycleListeners) {
            listener.onStage(lifecycleStage);
        }

        log("Stage '%s' complete.", lifecycleStage.getName());
    }
748524
public function process($payload, callable $stage, callable $fallback = null)
    {
        try {
            return $stage($payload);
        }
        catch ( \Throwable $exception ) {
            if ( is_callable($fallback) ) {
                return $fallback($payload);
            }
            else {
                throw $exception;
            }
        }
    }
427842
public void showMenu (Stage stage, float x, float y) {
		setPosition(x, y - getHeight());
		if (stage.getHeight() - getY() > stage.getHeight()) setY(getY() + getHeight());
		ActorUtils.keepWithinStage(stage, this);
		stage.addActor(this);
	}
1247730
public void setStageKeys(java.util.Collection<StageKey> stageKeys) {
        if (stageKeys == null) {
            this.stageKeys = null;
            return;
        }

        this.stageKeys = new java.util.ArrayList<StageKey>(stageKeys);
    }
712221
public function getStageName($stage)
    {
        switch ($stage) {
            case Runtime::PRE_DEPLOY:
                return 'Pre Deploy';

            case Runtime::ON_DEPLOY:
                return 'On Deploy';

            case Runtime::POST_DEPLOY:
                return 'Post Deploy';

            case Runtime::ON_RELEASE:
                return 'On Release';

            case Runtime::POST_RELEASE:
                return 'Post Release';
        }

        return $stage;
    }
1290809
public function applyChange(
        MenuInterface $menu,
        $stage
    ) {
        $menuBuilders = $this->getElementsByMenuCodeAndStage(
            $menu->getCode(),
            $stage
        );

        /**
         * @var MenuBuilderInterface $menuBuilder
         */
        foreach ($menuBuilders as $menuBuilder) {
            $menuBuilder->build($menu);
        }

        return $this;
    }
73638
public void warn(UserFeedbackEvent.Stage stage, String message) {
    Log.warn(stage+": "+message);
    addEvent(new UserFeedbackEvent(autoML, UserFeedbackEvent.Level.Warn, stage, message));
  }
837792
protected void stageOutput(final String output) {
        boolean print = getPhaseConfiguration().isVerbose();
        if (print) {
            output(INDENT + INDENT + output);
        }
    }
149222
@Override
    public void addAction(final LifecycleStage stage, final LifecycleAction<T> action)
    {
        stageEvents.add(new StageEvent(stage, action));
    }
808375
protected function isLocalisedInStage($stage, $locale = null)
    {
        // Get locale
        if (!$locale) {
            $locale = FluentState::singleton()->getLocale();

            // Potentially no Locales have been created in the system yet.
            if (!$locale) {
                return false;
            }
        }

        // Get table
        $baseTable = $this->owner->baseTable();
        $table = $this->getLocalisedTable($baseTable);
        if ($stage === Versioned::LIVE) {
            $table .= self::SUFFIX_LIVE;
        }

        // Check for a cached item in the full list of all objects. These are populated optimistically.
        if (isset(static::$idsInLocaleCache[$locale][$table][$this->owner->ID])) {
            return (bool) static::$idsInLocaleCache[$locale][$table][$this->owner->ID];
        }

        if (!empty(static::$idsInLocaleCache[$locale][$table]['_complete'])) {
            return false;
        }

        // Set cache and return
        return static::$idsInLocaleCache[$locale][$table][$this->owner->ID]
            = $this->findRecordInLocale($locale, $table, $this->owner->ID);
    }
365767
protected function addStageToConfiguration(string $stageName, array $sections)
    {
        $stage = new Stage($stageName);

        foreach ($this->filterSections($sections) as $sectionName => $commands) {
            $stage->addSection($this->buildSection($sectionName, $commands));
        }

        $this->configuration->setStage($stage);
    }