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

TASK: Defer initialisation of NodePriviliges #1883

Merged
merged 2 commits into from Apr 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,6 +54,20 @@ abstract class AbstractNodePrivilege extends AbstractPrivilege implements Method
*/
protected $initialized = false;

/**
* Constructor
*
* @param PrivilegeTarget $privilegeTarget
* @param string $matcher
* @param string $permission
* @param $parameters
*/
public function __construct(PrivilegeTarget $privilegeTarget, string $matcher, string $permission, $parameters)
{
parent::__construct($privilegeTarget, $matcher, $permission, $parameters);
$this->cacheEntryIdentifier = null;
}

/**
* @return void
*/
Expand All @@ -68,15 +82,26 @@ public function initialize()
$this->initializeMethodPrivilege();
}

/**
* @return void
*/
protected function buildCacheEntryIdentifier()
{
$this->cacheEntryIdentifier = md5($this->privilegeTarget->getIdentifier() . '__methodPrivilege' . '|' . $this->buildMethodPrivilegeMatcher());
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to use the existing getPrivilegeTargetIdentifier instead of $this->privilegeTarget->getIdentifier() method here?

Copy link
Member

Choose a reason for hiding this comment

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

@kitsunet Can you clarify this? Is that needed due to lazy initialisation or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

by testing look like calling getPrivilegeTargetIdentifier doesn't make any difference.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think there were edge cases in which using getPrivilegeTargetIdentifier triggered additional initialisations that were not really needed.

}

/**
* Unique identifier of this privilege
*
* @return string
*/
public function getCacheEntryIdentifier()
{
$this->initializeMethodPrivilege();
return $this->methodPrivilege->getCacheEntryIdentifier();
if ($this->cacheEntryIdentifier === null) {
$this->buildCacheEntryIdentifier();
}

return $this->cacheEntryIdentifier;
}

/**
Expand Down