Skip to content

Instantly share code, notes, and snippets.

@adrienbrault
Last active December 18, 2015 18:30
Show Gist options
  • Save adrienbrault/5826375 to your computer and use it in GitHub Desktop.
Save adrienbrault/5826375 to your computer and use it in GitHub Desktop.
Hateoas php library features ideas/wishlist

I'm about to start writing a new php library for hateoas stuff. Here are my thoughts about what features it should have. If you have comments/suggestions/ideas/requests/whatever, please comment the gist.

  • php 5.3 library
  • hooking into the jms serializer
  • support multiple hateoas "formats/standards" (hal, etc)
  • configuration layer
    • static configuration: php, yaml, annotations, extension api for other libraries (being cached)
    • dynamic configuration, attach configuration to an object

In yaml/annotations, when configuring links, href/rel/content/parameters value can be a string, number etc ... But if it starts with a @, the content is replaced by a handler.

@{handler_id}.{rest}, handler_id is the handler id, and rest will be passed to the handler.

In the example, @this is a handler, which will use PropertyAccess and {rest} to get the value on the object

Namespace\User:
relations:
-
rel: self
href:
route: user_get
parameters:
id: @this.id
_format: @request.attributes._format # "request" is a handler allowing to access symfony's request attributes/properties/parameters
somethingElse: staticString
attributes: # extra attributes added to the serialized link
type: foo/bar
-
rel: @this.dynamicRelGetter
href: @this.dynamicHrefGetter
-
rel: country
href:
route: country_get
parameters: {id: @this.country.id}
content: @this.country
-
rel: manager
href:
route: user_get
parameters: {id: @this.manager.id}
content:
value: @this.manager
if: @this.manager
-
rel: edit
href:
route: user_edit
parameters: {id: @this.id}
content: @serviceFactory.symfony_service_id@method # there'd be some handler to call sf2 services methods
preLinksCallback: onPreLinksSomething
<?php
class User
{
// ... properties, methods
public function onPreLinksSomething($links)
{
// Add fancy links with the php api
foreach ($this->getAuthors() as $author) {
$links->...
}
}
}
@adrienbrault
Copy link
Author

@j Embedded resources are configured with the content property, maybe I should rename that to "embed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment