Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed non-default call of $app-get() in favor of using $app->has() #14185

Merged
merged 2 commits into from
Jul 4, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Removed non-default call of $app-get() in favor of using $app->has()
  • Loading branch information
SamMousa committed May 22, 2017
commit 3a0916ae7b4da6337b11e6ac7f488b99b0eb79d3
6 changes: 3 additions & 3 deletions framework/behaviors/BlameableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public function init()
*/
protected function getValue($event)
{
if ($this->value === null) {
$user = Yii::$app->get('user', false);
return $user && !$user->isGuest ? $user->id : null;
if ($this->value === null && Yii::$app->has('user')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!$user->isGuest check is missing. Because of that behavior is not the same as it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is already part of the getter:

    public function getId()
    {
        $identity = $this->getIdentity();

        return $identity !== null ? $identity->getId() : null;
    }

    public function getIsGuest()
    {
        return $this->getIdentity() === null;
    }

$user = Yii::$app->get('user');
return !$user->isGuest ? $user->id : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, even better :)

}

return parent::getValue($event);
Expand Down