eZ Community » Forums » eZ Publish 5 Platform » Best practices for API: how to...
expandshrink

Best practices for API: how to insantiate create/update structs?

Best practices for API: how to insantiate create/update structs?

Friday 17 April 2015 8:56:13 am - 3 replies

There are methods to create new create or update structs. 

E.g.: in LocationService

  • public function newLocationCreateStruct( $parentLocationId );
  • public function newLocationUpdateStruct();

But what if I want to use symfony Serializer component to create my structs from xml.

Is it a good practice to create a struct with a "new"? E.g:

$struct = new LocationUpdateStruct();

It would be great to know an opinion from the architect point of view.

Monday 20 April 2015 12:16:59 pm

Hello there.

Based on the current implementation, I don't see any reason why you couldn't create them manually. It is what the services do. I'm not sure why those methods were added in the first place. Maybe there are/were plans to make them a bit smarter, but I'm not aware of those.

Maybe André could give us a hint here, I'll ping him.

Monday 20 April 2015 12:53:13 pm

Quote from Bertrand Dunogier :

Based on the current implementation, I don't see any reason why you couldn't create them manually...

I agree completely that a better way is to create these structures using services. 

However, I'm working on a loading of eZ Publish entities (e.g. content types, roles etc) from xml files. Let's assume it is a kind of package loader of eZP4.

I use symfony Serializer component which allows me to easily deserialize structure objects from xml.

Internally it happens in the denormalize method which instantiates objects.

I can instantiate an object either using particular service (e.g. ContentTypeService->newContentTypeStruct) or using new(). Second option is a bit easier. The question is just how bad is it.

 

Modified on Monday 20 April 2015 12:54:34 pm by Andrey Astakhov

Monday 20 April 2015 1:28:48 pm

 

Quote from Andrey Astakhov :

I can instantiate an object either using particular service (e.g. ContentTypeService->newContentTypeStruct) or using new(). Second option is a bit easier. The question is just how bad is it.

"A tiny bit" bad then, but nothing serious happy.gif Emoticon

We might add some point add extra logic, like extra default value checks etc, but no in the immediate future, and it shouldn't break anything if we do.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from