Why we are using Jms Serializer in Symfony - symfony

I have Used FosRestBundle in my project.In the Documentation they used the JmsSerializer.I want know how it could be used.

Check out the JMS Serializer documentation at http://jmsyst.com/libs/serializer
From the introduction:
This library allows you to (de-)serialize data of any complexity.
Currently, it supports XML, JSON, and YAML.
It also provides you with a rich tool-set to adapt the output to your
specific needs.
Built-in features include:
(De-)serialize data of any complexity; circular references are handled gracefully.
Supports many built-in PHP types (such as dates)
Integrates with Doctrine ORM, et. al.
Supports versioning, e.g. for APIs
Configurable via PHP, XML, YAML, or Doctrine Annotations

Related

Why TypeBuilderInterface is deprecated since api platform 3.1?

I rely heavily on TypeBuilderInterface because I build my own types for GraphQL. Not just for enums. So how should I define my own types? Since api platform version 3.1, this interface is deprecated by TypeBuilderEnumInterface that has been added in that PR https://github.com/api-platform/core/pull/5199
I can't just treat my custom types like entities, because entities are handled differently by the api platform than regular GraphQL types, so this deprecation will break like many of my implementations.
I expect TypeBuilderEnumInterface to live alongside TypeBuilderInterface, not instead of it.

Convertin JsonSchema to Doctrine Enties (or Swagger, JSON)

I've been provided with a large set of JSONSchema (draft 7) describing a model of incoming messages for a SOAP API.
Based on that i have to create/generate PHP/Doctrine entities to save incoming json messages.
Because that is a large set of files, manual work is not an option. I have to build a generator.
I did some research and there are some php libraries that transform JSONSchema to a PHP model, but not to Doctrine entities.
I know there is an ApiPlatrform project - based on Symfony (i use Symfony as well) that has a schema generator tool to generate entities.
API Platform embraces open web standards (Swagger, JSON-LD, GraphQL, Hydra, HAL, JWT, OAuth, HTTP.) but unfortunately it doesn`t support jsonSchema.
Using this generator would be the perfect solution for me because I could go directly from JSONSchema to Doctrine+Symfony entities.
So now I'm looking for the way to transform JSONSchema to , i think it would be best for my project, to Swagger 3 (i could use Swagger later on for my API).
I didn't find any libraries or documentation that will do that.
There are some libraries that can create PHP classes (so far swaggest is best one i think), but none to create entities.
So now i have to options:
1.JSONSchema to e.g Swagger and use ApiPlatform schema generator to create entities
2.I use Swaggest to create PHP model classes and then somehow i convert it to entities
As a third solution i was thinking that maybe there is a way to transfor JSONSchema to mysql database and then create entities from it (there is a symfony/doctrine generator) for that (here im bit afraid of loosing some relations between tables)
Both solutions are good for me , but I think 1 is best.
So my question is , do you guys know any libraries or can you direct me to how to transform JSONSchema to Swagger ?
My goal is to have a generator that creates a nice and clean PHP Doctrine Entities with all relations and preferrably validation without any additional code (some libraries creates a lot of code on top of PHP classes)
Thanks in advance for any help and suggestions

How to structure models and use Doctrine in Symfony2

I am switching over to Symfony for a project that I am working on but I need a little advice on how to structure the files when it comes to models and using doctrine.
I have a custom framework that I use, which in turns uses the MVC model. Pretty much all of my MYSQL database queries are stored in the models and I access them through the controller.
Now after looking at Symfony2, my interpretation is that "model" files in Symfony are called Servies. Is this correct?
I have also generated a number of Entities that correspond to my MYSQL database. My question here is do I place my custom Doctrine queries inside the Service files or do I create them inside the Entity files?
I'm a little unsure how to structure this.
Thanks
Pretty much all of my MYSQL database queries are stored in the models
That's bad, but I'll mention about it later.
Now after looking at Symfony2, my interpretation is that "model" files in Symfony are called Servies. Is this correct?
Queries should be done in either repositories or in some cases in services.
If your query returns entities, then it should be repository for sure.
My question here is do I place my custom Doctrine queries inside the Service files or do I create them inside the Entity files?
Entities should be plain PHP objects. They shouldn't depend on anything than other entities. Entities actually doesn't even know anything about database. It's pure object oriented business logic.
Again, all DB queries should be in repositories or services.
I would suggest to go through Symfony Book in first place, to get idea of how "the Symfony way" works.
Symfony is not MVC framework:
Symfony2 is really about providing the tools for the Controller part, the View part, but not the Model part [...] Symfony2 is an HTTP framework; it is a Request/Response framework.
And it is great. Symfony allows to make your model as you wish without any restrictions. The Doctrine (ORM and/or DBAL) is a separate set of libraries. You can use any other library, or build your own persistence layer abstraction, or work with native SQL through PDO/MySQLi/etc.
Service is just an object that registered in the container and have some dependencies. Services can doing anything. They can represent your model, but it is not a requirement.
Organizing Your Business Logic (The Symfony Best Practices)
Doctrine ORM Best Practices

Does Apache Thrift provide reflection API?

Does thrift provide a way to inspect struct fields at runtime?
My use case is with C# but the question is regarding the standard Thrift API.
There is no standard thrift API across languages so what you can do beyond serialization is highly language dependent. If you can't accomplish what you want using just reflection, examine the code that is generated by the thrift compiler for the thrift object you are interested in. I've not seen C# thrift generated code but it may contain additional data that could be useful to you.
I am very familiar with the Java implementation and I can tell you that using thrift with Java there is no need to use reflection at all. Every thrift generated class contains information that allows the deserializer to reconstruct the class from field id numbers. The java thrift compiler creates static members and methods which contain pretty much everything you would ever want. For Java it is actually better than reflection because it contains the element types for lists/maps/sets.
Now there is no guarantee that the formats of this data won't change in future versions of thrift but given that all of the various protocols depend on them the 'hidden' API should be fairly stable.
If you have access to the IDL at runtime you could use a parser for the IDL and infer the generated fields that way.
I'm not an expert in C# but you could maybe link to the native libparse library used in the Thrift executable (I'm not sure if the parse library is generic enough to use like that, I'm just assuming).
Alternatively you could use the parser from Facebook's Swift (https://github.com/facebook/swift/tree/master/swift-idl-parser, or download the JAR from http://central.maven.org/maven2/com/facebook/swift/swift-idl-parser/0.13.2/swift-idl-parser-0.13.2.jar). This is probably easier or better for your case IMO, even though it is a Java library I think it should convert just fine to CLR using IKVM.net.
A third stupidly simple and hackish way to do this would be to use the Thrift HTML generator to generate HTML documentation and parse that using regex or run it through HTML Tidy and parse it as XML

Real-World examples of Reflection

What are your best examples of using Reflection in production code?
ASP.NET MVC inferring the action and controller to invoke from URL. Routing in general.
Most recently, I had to use reflection to load an assembly (in order to investigate its public types) from just the path of the assembly.
Before Linq To Sql came out...I had to write my own ORM in .NET 2.0.
I used reflection heavily to reflect back on:
Classes to their CRUD stored procedures
Properties to their column names
Which operations were valid for the class
I also used reflection to handle all variable assignment after the results were retreived (all classes inherited an ActiveRecord class that handled the calls into the DAL).
Rough stuff...but after some performance tuning it wasn't half bad.
Pulling data out of an SQL table where you had an ID, a type, and other data
Then you could load "Chevrolet" and work with all of it's methods
I did have occasion to write a Python O/R mapper on one at one point, but it was a proof of concept and never went into production.
I do quite a lot of work that makes extensive use of the system data dictionary on a DBMS (for example a generic slowly-changing dimension loader). It might be argued that this is not dissimilar to reflective programming in principle.
Finally, Python in all its forms is very easy to do reflection with. In fact, it's so good at this that I've used it to poke about with underlying API's in other languages - and use the reflective capabilities to query the underlying interfaces. I have done this with pretty much every reflective mechanism that exists in the Python world: CPython on Python API's and COM API's using makepy, Jython for java API's and IronPython for .Net API's.
In one of my recent apps, an add-in for Kofax Express, I have an option to OCR a file and output a PDF. Since the OCR tool I'm using has a runtime fee, I made the OCR part a seperate assembly. If the file exists, I show the OCR options and late bind the assembly and invoke the required methods and attach to the events with reflection. A simple plug in architecture without interfaces, and saves customers from having to pay royalty fees if they don't need to OCR; we just don't give them the OCR dll.
WPF Databinding:
1) Binding path "(TextBox.Text)" vs "Text"?
If you bind to a path called Text, WPF uses reflection to resolve the name. If you use the class-qualified name, binding avoids the reflection performance hit. Class-qualified names also allows binding to attached properties!
(via http://dotnet.org.za/rudi/archive/2008/03/25/10-things-i-didn-t-know-about-wpf-data-binding.aspx)
NUnit Unit Testing Framework - Not very typical though
CSLA uses reflection a lot
Pretty much any Windows Forms app that supports plugins
My DAL is all reflection based. It reflects on the POCO properties to build SQL.
Within a factory, we use reflection to either pass back a "Dummy" implementation of an interface or a real (hooked to the DB) implementation of an interface, based on the class specified in a properties file (in Java).

Resources