Skip to content

Commit

Permalink
Maybe a performance thing
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Jun 8, 2018
1 parent bf51bc4 commit f9012d9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/HasParentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public function getClassNameForRelationships()

protected function getParentClass()
{
return (new ReflectionClass($this))->getParentClass()->getName();
static $parentClassName;

return $parentClassName ?: $parentClassName = (new ReflectionClass($this))->getParentClass()->getName();
}
}

2 comments on commit f9012d9

@chadhutchins
Copy link

Choose a reason for hiding this comment

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

@calebporzio If I wanted to manually set the $parentClassName, where would I do that?

I have a scenario where my Parent is not the specific Parent class of my Children.

Ex. C extends B, and B extends A. I have the HasChildren trait on Class A. I have the HasParent trait on Class C. But since class C extends B, the getParentClass() method will return B instead of A.

Thanks!

@chadhutchins
Copy link

Choose a reason for hiding this comment

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

@calebporzio This PR will solve this: #104

Though I am still curious if there is a way to set the $parentClassName or what the intent is for this?

Please sign in to comment.