Skip to content

Instantly share code, notes, and snippets.

@eimihar
Last active April 14, 2016 08:56
Show Gist options
  • Save eimihar/12e2bb8826769676258837a1d5b7322f to your computer and use it in GitHub Desktop.
Save eimihar/12e2bb8826769676258837a1d5b7322f to your computer and use it in GitHub Desktop.
method invocation on property accessed through getter
// case on accessing the data by given fields
GET /api/person/10?fields=name,address,phone,delete
// api function
$person = Entity\Person::find($id);
if(!isset($_GET['fields']))
return $person->toArray();
$fields = explode(',', $_GET['fields']);
$data = array();
// delete method gets invoked.
foreach($fields as $field)
$data->$field = $person;
return $data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment