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

PropertyStorage fix #474

Merged
merged 4 commits into from
Jun 26, 2014
Merged

PropertyStorage fix #474

merged 4 commits into from
Jun 26, 2014

Conversation

DominikTo
Copy link
Member

Methods and properties are in a different namespace, so currently $this->pathFilter() is an undefined method which causes:

Call to undefined method Sabre\DAV\PropertyStorage\Plugin::pathFilter() in /opt/foo/bar/vendor/sabre/dav/lib/DAV/PropertyStorage/Plugin.php on line 68

public function __call($method, $args)
{
if (is_callable([$this, $method])) {
return call_user_func_array($this->$method, $args);
Copy link
Member

Choose a reason for hiding this comment

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

$this->pathFilter is a public property, so there is no method?

this implementation feels misleading...

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 am not sure either if this is a good solution. $pathFilter is supposed to be a callable (see the section about restricting paths here: http://sabre.io/dav/property-storage/), but currently the $this->pathFilter($path) calls in this class will fail with Call to undefined method Sabre\DAV\PropertyStorage\Plugin::pathFilter() as calling $this->pathFilter() in an object context will try to call a method called pathFilter() which does not exist.

Another option would be to actually add a method pathFilter() and return the property $pathFilter - if it's a callable.
This PR is mostly a bug report, because right now the following calls to $this->pathFilter() in the Property Storage Plugin will all fail:

/cc @evert

Copy link
Member

Choose a reason for hiding this comment

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

I think we should change the callsites so PHP don't need to guess if we like to call a property or a method.
just introduce a local var and you are good to go.

Instead of

if ($this->pathFilter && !$this->pathFilter($path)) return;

just do

$pathFilter = $this->pathFilter;
if ($pathFilter && !$pathFilter($path)) return;

This would make it obvious I think. this could of course be done in a private method, so this "hack" won't be distributed across the whole class..

private function pathFilter($path) {
  // make sure we are calling the callable of our public property and not the equal named method
  $pathFilter = $this->pathFilter;
  return ($pathFilter && !$pathFilter($path));
}

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

That indeed seems to be a better solution. Also added a test now.
Let's see what @evert thinks. :)

Copy link
Member

Choose a reason for hiding this comment

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

Great to have a test for this. Looks good to me, thanks.

@evert
Copy link
Member

evert commented Jun 26, 2014

Looks great. __call is definitely something that's good to avoid :)

evert added a commit that referenced this pull request Jun 26, 2014
@evert evert merged commit 457c1f0 into sabre-io:master Jun 26, 2014
@evert
Copy link
Member

evert commented Jun 26, 2014

Weird that there were no travis builds ?

@DominikTo
Copy link
Member Author

Thanks for merging! Travis builds are showing up for me? :)

@DominikTo DominikTo deleted the property-storage-fix branch June 26, 2014 15:38
DominikTo added a commit that referenced this pull request Jun 26, 2014
DominikTo added a commit that referenced this pull request Jun 26, 2014
Conflicts:
	ChangeLog.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants