Controller run

@return Data
@throws ComponentException
@throws ControllerException
@throws \ReflectionException
771084
protected function process(): Data
    {
        // initial variables for use inside controller
        $module = $this->module;
        $controller = $this->controller;
        $params = $this->params;

        /**
         * @var \closure $controllerClosure
         */
        $controllerClosure = include $this->getFile();

        if (!\is_callable($controllerClosure)) {
            throw new ControllerException("Controller is not callable '{$module}/{$controller}'");
        }

        // process params
        $params = $this->getMeta()->params($params);

        // call Closure or Controller
        $result = $controllerClosure(...$params);

        // switch statement for result of Closure run
        switch (true) {
            case ($result === false):
                // return "false" is equal to disable view and layout
                $this->disableLayout();
                $this->disableView();
                break;
            case \is_string($result):
                // return string variable is equal to change view template
                $this->setTemplate($result);
                break;
            case \is_array($result):
                // return associative array is equal to setup view data
                $this->getData()->setFromArray($result);
                break;
            case ($result instanceof self):
                // return Controller - just extract data from it
                $this->getData()->setFromArray($result->getData()->toArray());
                break;
        }

        return $this->getData();
    }
427305
public function run()
    {
        // Load routing user config file
        $this->routes();
        // Launch routage
        Router::resolve();
        // Load databases user config file
        $this->databases();
        // Load Bootstrap
        $this->bootstrap();
        // Launch Controller defined by routage
        $bodyContent = $this->controller();
        // Show body content return by Controller
        echo $bodyContent;
    }
1042389
public function run()
    {
        $this->container = $this->container ?: new Container;

        try {
            if ($this->isControllerAction()) {
                return $this->runController();
            }

            return $this->runCallable();
        } catch (HttpResponseException $e) {
            return $e->getResponse();
        }
    }
648028
public function run()
    {
        if (Yii::$app->getRequest()->getIsAjax()) {
            return $this->renderAjaxResponse();
        }
        $this->chooseView();
        return $this->renderHtmlResponse();
    }
449487
public function run()
	{
		$context = $this->_getContext();

		$jobManager = MAdmin_Job_Manager_Factory::createManager( $context );
		$criteria = $jobManager->createSearch( true );

		$start = 0;

		do
		{
			$items = $jobManager->searchItems( $criteria );

			foreach( $items as $item )
			{
				try
				{
					$job = $item->getMethod();

					if( preg_match( '/^[a-zA-Z0-9\_]+\.[a-zA-Z0-9\_]+$/', $job ) !== 1 ) {
						throw new Controller_Jobs_Exception( sprintf( 'Invalid characters in job name "%1$s"', $job ) );
					}

					$parts = explode( '.', $job );

					if( count( $parts ) !== 2 ) {
						throw new Controller_Jobs_Exception( sprintf( 'Invalid job method "%1$s"', $job ) );
					}

					$name = "Controller_ExtJS_{$parts[0]}_Factory";
					$method = $parts[1];

					if( class_exists( $name ) === false ) {
						throw new Controller_Jobs_Exception( sprintf( 'Class "%1$s" not available', $name ) );
					}

					$name .= '::createController';

					if( ( $controller = call_user_func_array( $name, array( $context ) ) ) === false ) {
						throw new Controller_Jobs_Exception( sprintf( 'Unable to call factory method "%1$s"', $name ) );
					}

					if( method_exists( $controller, $method ) === false ) {
						throw new Controller_Jobs_Exception( sprintf( 'Method "%1$s" not available', $method ) );
					}

					$result = $controller->$method( (object) $item->getParameter() );

					$item->setResult( $result );
					$item->setStatus( -1 );
				}
				catch( Exception $e )
				{
					$str = 'Error while processing job "%1$s": %2$s';
					$context->getLogger()->log( sprintf( $str, $item->getMethod(), $e->getMessage() ) );
					$item->setStatus( 0 );
				}

				$jobManager->saveItem( $item );
			}

			$count = count( $items );
			$start += $count;
			$criteria->setSlice( $start );
		}
		while( $count > 0 );
	}
286859
public function run()
    {
        Url::remember();
        $dataProvider = $this->searchModel->singleSearch(Yii::$app->request->queryParams, $this->query);

        return $this->controller->render($this->view, array_merge([
            'searchModel' => $this->searchModel,
            'dataProvider' => $dataProvider,
        ], $this->params));
    }
443287
public function execute()
	{
		// Incoming task
		$this->_task = strtolower(\Request::getCmd('task', \Request::getWord('layout', '')));

		// Check if the task is in the taskMap
		if (isset($this->_taskMap[$this->_task]))
		{
			$doTask = $this->_taskMap[$this->_task];
		}
		// Check if the default task is set
		elseif (isset($this->_taskMap['__default']))
		{
			$doTask = $this->_taskMap['__default'];
		}
		// Raise an error (hopefully, this shouldn't happen)
		else
		{
			throw new InvalidTaskException(Lang::txt('The requested task "%s" was not found.', $this->_task), 404);
		}

		$name = $this->_controller;
		$layout = preg_replace('/[^A-Z0-9_]/i', '', $doTask);
		if (!$this->_controller)
		{
			$cls = get_class($this);
			// Attempt to parse the controller name from the class name
			if ((ucfirst($this->_name) . 'Controller') != $cls
			 && preg_match('/(\w)Controller(.*)/i', $cls, $r))
			{
				$this->_controller = strtolower($r[2]);
				$name   = $this->_controller;
				$layout = preg_replace('/[^A-Z0-9_]/i', '', $doTask);
			}
			// Namepsaced component
			else if (preg_match('/(.?)Controllers\\\(.*)/i', $cls, $r))
			{
				$this->_controller = strtolower($r[2]);
				$name   = $this->_controller;
				$layout = preg_replace('/[^A-Z0-9_]/i', '', $doTask);
			}
			// No controller name found - single controller component
			else
			{
				$name = $doTask;
			}
		}

		// Instantiate a view with layout the same name as the task
		$this->view = new View(array(
			'base_path' => $this->_basePath,
			'name'      => $name,
			'layout'    => $layout
		));

		// Set some commonly used vars
		$this->view->set('option', $this->_option)
					->set('task', $doTask)
					->set('controller', $this->_controller);

		// Record the actual task being fired
		$doTask .= 'Task';

		// On before do task hook
		$this->_onBeforeDoTask();

		// Call the task
		$this->$doTask();
	}
131089
private function generateBasicController()
    {
        $controllerClass = $this->applicationDir.DS.'Controllers'.DS.$this->controller.'Controller'.EXT;

        if (file_exists($controllerClass)) {
            throw new \Exception("$controllerClass already exists!!");
        }

        /*write operation ->*/
        $filePointer = fopen($controllerClass, 'w') or die('Unable to generate controller');

        $controllerContent = $this->getControllerTemplate();
        $content = $this->getIndexStub();
        $content = $this->replaceTemplate('{%methods%}', $content, $controllerContent);

        return $this->writeContentToClass($filePointer, $content);
    }
896706
public function run() {

		$modelClass		= $this->modelService->getModelClass();
		$model			= new $modelClass;

		if( $model->load( Yii::$app->request->post(), $model->getClassName() ) && $model->validate() ) {

			$this->controller->model = $this->modelService->create( $model );

			// Trigger Ajax Success
			return AjaxUtil::generateSuccess( Yii::$app->coreMessage->getMessage( CoreGlobal::MESSAGE_REQUEST ), $model );
		}

		// Generate Errors
		$errors = AjaxUtil::generateErrorMessage( $model );

		// Trigger Ajax Failure
		return AjaxUtil::generateFailure( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_REQUEST ), $errors );
	}
790825
public function run()
	{
		//check if flushing required
		$flushValue = Yii::$app->request->post('flush-cache');
		if ($flushValue !== null) {
			$this->flushCache($flushValue);
			return Yii::$app->controller->refresh();
		}

		//sections
		$i = 0;
		ob_start();
		foreach ($this->sections as $key=>$value) {
			//render section
			if (is_string($value)) {
				$camelized = Inflector::camelize($value);
				$methodName = 'section' . $camelized;
				if (method_exists($this, $methodName)) {
					$this->renderSection($key, $this->{$methodName}());
				} else {
					$msg = Yii::t('app', 'There is no method `section{section}` defined', ['section'=>$camelized]);
					throw new InvalidConfigException($msg);
				}
			} else if ($value instanceof \Closure) {
				$this->renderSection($key, call_user_func($value));
			} else if (is_array($value)) {
				$this->renderSection($key, $value);
			} else {
				$msg = Yii::t('app', 'Invalid format of section definition {section}', ['section'=>$key]);
				throw new InvalidConfigException($msg);
			}
			$i++;

			//separator
			if (!empty($this->sectionSeparator) && $i < count($this->sections)) {
				echo $this->sectionSeparator;
			}
		}

		return $this->render(ob_get_clean());
	}
780395
public function runComponents()
    {
        foreach ($this->components as $component) {
            if ($event = $component->fireEvent('component.beforeRun', [], true)) {
                return $event;
            }

            if ($result = $component->onRun()) {
                return $result;
            }

            if ($event = $component->fireEvent('component.run', [], true)) {
                return $event;
            }
        }
    }
870665
public function run()
    {
        $optimizer = new Optimizer();
        $optimizer->run();

        $removedLanguageElements = $optimizer->getRemovedLanguageElements();

        return $this->controller->render('optimizer', [
            'newDataProvider' => $this->controller->createLanguageSourceDataProvider($removedLanguageElements),
        ]);
    }
450255
public function run()
    {
        if ($this->route === null && Cii::$app->controller !== null) {
            $this->route = Cii::$app->controller->getRoute();
        }
        if ($this->params === null) {
            $this->params = Cii::$app->request->getQueryParams();
        }
        $posDefaultAction = strpos($this->route, Cii::$app->controller->defaultAction);
        if ($posDefaultAction) {
            $this->noDefaultAction = rtrim(substr($this->route, 0, $posDefaultAction), '/');
        } else {
            $this->noDefaultAction = false;
        }
        $posDefaultRoute = strpos($this->route, Cii::$app->controller->module->defaultRoute);
        if ($posDefaultRoute) {
            $this->noDefaultRoute = rtrim(substr($this->route, 0, $posDefaultRoute), '/');
        } else {
            $this->noDefaultRoute = false;
        }
        $items = $this->normalizeItems($this->items, $hasActiveChild);
        if (!empty($items)) {
            $options = $this->options;
            $tag = ArrayHelper::remove($options, 'tag', 'ul');
            echo Html::tag($tag, $this->renderItems($items), $options);
        }
    }
718292
public function run()
    {
        if ($this->route === null && Yii::$app->controller !== null) {
            $this->route = Yii::$app->controller->getRoute();
        }
        if ($this->params === null) {
            $this->params = Yii::$app->request->getQueryParams();
        }
        $items = $this->normalizeItems($this->items, $hasActiveChild);
        if (!empty($items)) {
            $options = $this->options;
            $tag = ArrayHelper::remove($options, 'tag', 'ul');

            if ($tag !== false) {
                echo Html::tag($tag, $this->renderItems($items), $options);
            } else {
                echo $this->renderItems($items);
            }
        }
    }
588586
public function run()
    {
        /* @var $model yii\db\ActiveRecord */
        $model = new $this->modelClass;
        $model->setScenario( $this->scenario );
        if (yii::$app->getRequest()->getIsPost()) {
            if ($model->load(yii::$app->getRequest()->post()) && $model->save()) {
                yii::$app->getSession()->setFlash('success', yii::t('cms', 'Success'));
                return $this->controller->redirect(['index']);
            } else {
                $errors = $model->getErrors();
                $err = '';
                foreach ($errors as $v) {
                    $err .= $v[0] . '<br>';
                }
                Yii::$app->getSession()->setFlash('error', $err);
            }
        }
        $model->loadDefaultValues();
        $data = array_merge(['model' => $model], $this->data);
        return $this->controller->render('create', $data);
    }
116307
public function run()
    {
        $searchModel = Yii::createObject($this->searchClass);
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->controller->render($this->view, [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
306360
public function run()
    {
        $this->controller->getSearchCriteria();
        $this->controller->dataProvider->pagination = false;
        $query = $this->controller->dataProvider->query;

        $config = new ExporterConfig();
        $exporter = new Exporter($config);
        $result = $query->asArray()->all();
        $fields = $this->fields;
        $values = array_map(function ($ar) use ($fields) {
        //$values = array_map(function () use ($fields) {
            $return = [];
            foreach($fields as $field) {
                $keyString = "['" . str_replace('.', "']['", $field) . "']"; 
                eval("\$return[] = \$ar".$keyString.";");
            }
            return $return;
        }, $result);
        if(isset($_GET['test'])) {
            return json_encode(array_merge([$this->fields], $values));
        } else {
            $this->setHttpHeaders('csv', $this->controller->getCompatibilityId(), 'text/plain');
            $exporter->export('php://output', array_merge([$this->fields], $values));
        }
    }