woohoolabs / yang

The efficient and elegant, PSR-7 compliant JSON:API 1.1 client library for PHP
MIT License
168 stars 13 forks source link

Allow access to ResourceObject.id #15

Closed holtkamp closed 5 years ago

holtkamp commented 5 years ago

Currently the ResourceObject.id property is private and can therefore not be accessed once the object is instantiated. Is this on purpose?

Rationale I would like to be to access it, so the id can be used to (dynamically) generate a DELETE request like:

https://domain.ext/api/v1/resourceName/id/$id

Something like:

//application.php
$articleResource = ArticleResource::getInstance(123);
if( $apiClient->delete($articleResource)){
    echo 'deleted Article!';
}
//apiClient.php
public function delete(Resource $resource) : bool{
    $request = $this->someRequestBuilder->getDeleteRequest($articleResource)
    $response = $this->sendRequest($request);
    return $this->analyzeRespons($response);
}

Maybe the ResourceObject.id should not be accessed, that is possible, but in that case I would like to know "why" 😄

kocsismate commented 5 years ago

Hi @holtkamp,

The only purpose of the id field being private without any getter/setter is that I didn't have any meaningful use-case in mind for accessing it.

Would it be OK for you if I added the id(), type(), attributes() and relationships() accessors as well as the setId() and setType() mutators?

kocsismate commented 5 years ago

Done in https://github.com/woohoolabs/yang/commit/fb539603f759a0fb410c66e65b0e186ee9eec75b :)