Git Product home page Git Product logo

Comments (6)

samdark avatar samdark commented on June 16, 2024 2

Sounds reasonable for 2.1 but I'd go a bit further by passing result through allowing to post-process it:

return $this->afterRun($result);

Can't be done in 2.0 because of method signature change.

from yii-core.

egml avatar egml commented on June 16, 2024 1

Sorry) I'm talking about this piece of code here https://github.com/yiisoft/yii2/blob/master/framework/base/Action.php#L94-L95

public function runWithParams($params)
{
	...
	if ($this->beforeRun()) {
		$result = call_user_func_array([$this, 'run'], $args);
		$this->afterRun();
		return $result;
	}
	...
}

Wouldn't it be right to pass $result to afterRun() before returning it? Like this:

	...
	if ($this->beforeRun()) {
		$result = call_user_func_array([$this, 'run'], $args);
		$this->afterRun($result);
		return $result;
	}
	...

To be able to analyze the result of the action in afterRun() and change afterRun()'s execution accordingly. Right now I came up with a solution where I pass stuff through action class parameters. But it just seems not right. Or maybe I'm wrong, that was the base question) Is it worth making a PR or even talking about?

An example: action class which sends some specific EventSource stuff to the browser before and after each action.

class Operation extends \yii\base\Action
{
	...
	protected function beforeRun()
	{
		\Yii::$app->getLog()->targets['operation']->rotateFiles();
		$this->log('Operation begin [' . date('Y-m-d H:i:s') . ']');
		EventSource::begin();
		return true;
	}

	protected function afterRun()
	{
		... this is where it would be nice to have action run result to change $data ...
		EventSource::end($data);
		$this->log('Operation end [' . date('Y-m-d H:i:s') . ']');
	}
	...
}

from yii-core.

cebe avatar cebe commented on June 16, 2024

Sorry I read your message three times but I do not get what you are asking :) Could you rephrase or explain in more detail please?

from yii-core.

yii-bot avatar yii-bot commented on June 16, 2024

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

from yii-core.

lubobill1990 avatar lubobill1990 commented on June 16, 2024

+1
I think it's reasonable to pass the result to afterRun

With out the result of run() to be passed to afterRun, afterRun can do very few things.

from yii-core.

samdark avatar samdark commented on June 16, 2024

The issue doesn't apply to new code anymore.

from yii-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.