thefootballsocialclub / fschateoasbundle Goto Github PK
View Code? Open in Web Editor NEWPlease use https://github.com/willdurand/hateoas and https://github.com/willdurand/BazingaHateoasBundle instead.
Please use https://github.com/willdurand/hateoas and https://github.com/willdurand/BazingaHateoasBundle instead.
At the moment, the links in json look like:
{
"links": {
"self": {
"rel": "self",
"href": "xxx"
}
}
}
but it should look like this (to reduce size, and simplify usage)
{
"links": {
"self": "xxx"
}
}
I did not understand the code.
you can do:
$visitor->setDefaultRootName('collection');
$visitor->document = $visitor->createDocument();
Obviously, you want to call the root name collection
And, If you really want to check, could you open a PR on the serializer. reflection is so slow ... :(
The serializer beginning with 0.12 supports a metadata stack. We can use this to delay creating links, and embedding objects, since we can only do that once.
A (failing) testcase is the following controller test:
public function testListPostsJson()
{
$client = $this->createClient();
$client->request('GET', '/api/posts?_format=json');
$response = $client->getResponse(); /** @var $response Response */
$this->assertEquals(200, $response->getStatusCode());
}
Running this results in
JMS\Serializer\Exception\InvalidArgumentException: There is already data for "links".
This is only a problem for JSON, not XML, but will ultimately allow us to inline the HalPagerfanta inside another model that can contain additional properties, links, and embedded resources.
I have the following schema:
Path\To\My\Foo
relations:
- rel: self
href:
route: get_foo
parameters:
id: .id
- rel: bar
href:
route: get_bar
parameters:
id: .bar.id
Basically, bar is not required and may be null, therefore generating the route would throw an exception.
Is there a way to only generate the bar
link if the foo
has resource bar
only? And ignore if it it does not?
Hey,
I see that many people are interested in non required relation.
An example would be a User that could have a manager, but not always.
The current PR try catch the parameters creation or the url generation. I dot not like this as this could hide an error (configuration, runtime, whatever).
What I propose:
@Relation("manager", @Route("user_get", parameters = {"id" = "manager.id"}), required_parameters = {"manager"})
Without the new required_parameters
option, the behavior would stay the same.
required_parameters
would accept an array of propertyPaths. If one of the propertyPath is null or false, then the relation link would not be created.
WDYT ?
We should be able to generate links off of collections, so you would specify a parameter to create a link for each element in that array.
For example, you have an array of authors, and you want to generate a link for each author
/**
* @Rest\Relation("self",
* href = @Rest\Route("author", collection_parameters = { "id" = ".author[].id" }))
*/
Many people will wonder why the example uses annotations for the serializer
metadata, and yaml for the hateoas
metadata.
In addition to this, annotations will let people define serializer
and hateoas
metadata in the same file.
Right now its only possible to define the url by hardcoding it in the annotation. However in some cases the URL needs to be fetched dynamically from the model.
/**
* @Rest\Relation("foo", href = ".someUrl")
*/
JMSSerializerBundle has a DoctrineProxySubscriber which loads Doctrine Proxies before serializing them.
When I serialize a Pagerfanta object with, for example, 2 users. One user is a Proxy and 1 user is loaded completely. I've set @XmlRoot("user")
. When I serialize the Pagerfanta object to XML one user has a <entry>
root and one has a <user>
root.
How can this be fixed? Should the PagerfantaHandler trigger some kind of event?
XmlFormViewSerializer
Do not serialize value with CDATA section. Which can create some issues is the value contains some xml tag.
What I did:
/*
<textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
*/
protected function serializeTextareaWidget(\DOMElement $parentElement, FormView $view, $variables)
{
$textareaElement = $parentElement->ownerDocument->createElement('textarea');
$textareaElement->appendChild($parentElement->ownerDocument->createCDATASection($variables['value']));
$parentElement->appendChild($textareaElement);
$this->addWidgetAttributes($textareaElement, $view, $variables);
}
Do you want a PR ? Should i CDATAize all the field ?
Thank you for your bundle! Would it be possible to tag and release a version?
This will make using the library via composer easier.
To fix this the following would need to be done:
Thank you in advance!
As discussed by email:
@Hateoas/Routeparameters(parameters = { "_format" = "Request.requestFormat" } )
I would like to know if there is any special reason why this bundle is bound to Pagerfanta? As far as I saw from a quick look into the RelationsManager, only the current and max page are needed from the paginator and it shouldnt be that hard to get broader support into the bundle. The only catch would be the existing type-hinting and BC if I'm not overseeing something.
I'm interested in getting support for, at least, KnpPaginator into the bundle because I'm using it all over the place and love the sorting- and filtering-capabilities.
Another candidate for implementation would be the new Doctrine Paginator.
I'm getting this error when running composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for fsc/hateoas-bundle 0.4.x-dev -> satisfiable by fsc/hateoas-bundle 0.4.x
- Conclusion: remove jms/metadata dev-master
- fsc/hateoas-bundle 0.4.x-dev requires jms/metadata >=1.1.0,<1.3-dev -> satisfiable by jms/metada
data 1.2.0-RC.
- Can only install one of: jms/metadata dev-master, jms/metadata 1.1.1.
- Can only install one of: jms/metadata dev-master, jms/metadata 1.2.0-RC.
- Installation request for jms/metadata == 9999999-dev -> satisfiable by jms/metadata dev-master.
i have some examples where I also support setting the _format
via the URL, so to generate the correct URLs I would need to also have the _format
request attributed passed to the generateUrl()
call.
then again do we really want to cover this use case? we can just assume that people are using proper accept header to request the format they want.
furthermore fixing this will require the link classes to gain access to the request instance, which is a bit iffy in general.
Hi @adrienbrault,
First, thanks for your work on this helpful bundle, Is it possible to use jms/serializer 1.13.* instead of 1.12.*.
Thanks
The configuration would look like this:
fsc_hateoas:
json:
index_relations_by_rel: true
index_links_by_rel: true
Hey,
The JMS serializer is now a library, and can be used without symfony2. The relevant part of the hateoas bundle should be extracted into a php library, that could be used with the serializer.
We realized we are having performance issues because of this bundle. If we remove the @Rest\Relation
annotations from our entities (about 4-6 per entity) we can cut our reponse times in half! (From 0.6s to 0.3s)
This does not work at all ;)
We should be able to specify a different URL generator service for a route. This would allow using a RFC6570 compliant router generator to be used instead (for templated links).
I'm using ODM, and it's automatically adding links to all my embedded documents... Is there a way to only show HATEOAS stuff when configured to do so instead on all serialized stuff?
This bundle currently does not work if you try to upgrade to Symfony 2.3, which has now been released.
I am trying to get the bundle working, but the relations are not working. I tried it both with master, as well as with thdev-formview-serialization branch. Here is the interesting part of my code: https://gist.github.com/3961294.
Basically, The links just don't show up. I have traced it to https://github.com/TheFootballSocialClub/FSCHateoasBundle/blob/master/Factory/LinkFactory.php#L34 where the class metadata is empty. This is where I am stuck.
Help, please. Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.