Is there any way to bind a class property to a method parameter inside that class so that there is a two way link when you click Ctrl + Click?
class Attachments extends Repository
{
public Documents $documents;
public function fromDocuments(callable $scope)
{
$this->scopeOnRepoProperty($scope, 'documents');
}
}
I mean, that in that case second parameter documents
in scopeOnRepoProperty()
method should refer to property $documents
.
The broader context:
The problem for me is that a large part of the code was very analogous, namely, most of the method scopeXXX
/fromXXX
does something like that, executes the method and sends the property repository to it as a parameter. i.e. in the example above, $scope($this->documents)
is executed;
and additionally, if $this->documents
is not initialized, a new instance is created.
So it's looks:
public function fromDocuments(callable $scope)
{
if (!isset($this->documents)) {
$this->documents = new Documents();
}
$scope($this->documents);
}
I wanted to save myself writing an if
every time, creating a new object and calling a method, and I came up with the idea that I can do it with one method that will take a callable and the name of this property and from type reflection class name.
The code works fine, unfortunately I lost the bindings to these properties because of this. In the previous version it was $this->documents
, so the link was there, but as it is now it is not.
I am wondering if there is any way I can achieve this. Any ideas?