JMS serializer yml datetime format - symfony

I have an Rest API built on Symfony 2.7 Framework with FOSRestBundle and JMSSerializerBundle. I have a look to yml reference and annotations.
I have choosen to define how each entity of my model is serialized with yml.
I have seen that we can serialize Datetime object on a specific format :
#JMS\Type("DateTime<'d-m-Y'>")
But I don't know the correct syntax used with yml definition, I have tried :
my_field:
expose: true
type: datetime
format: 'd-m-Y'
And
my_field:
expose: true
type: datetime<'d-m-Y'>
I don't want to use Annotations because I have a lot of yaml files.
But the field is not serialized...
Anyone can help me ?

I put it as an answer in case it helps more people:
my_field:
expose: true
type: DateTime<'d-m-Y'>

Related

symfony 4 - default normalization to snake_case

trying to get the sf4 serializer component to use snake_case as the default:
Symfony\Component\Serializer\Normalizer\ObjectNormalizer:
public: true
arguments: ['#serializer.mapping.class_metadata_factory', '#serializer.name_converter.camel_case_to_snake_case']
tags: [serializer.normalizer]
works.
but now DateTime is being normalized to empty arrays.
I don't get why, without the config changes, its normalized to a date string, as you would expect.
What am i doing wrong here?
turns out, you simply need to enable a name_converter the proper way like this instead:
# config/packages/framework.yaml
framework:
# ...
serializer:
name_converter: 'serializer.name_converter.camel_case_to_snake_case'
see
https://symfony.com/doc/current/serializer.html#enabling-a-name-converter
https://github.com/symfony/symfony/issues/40818

Symfony2 : Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given

I'm trying to implement OAuth2 in my actual symfony2 project using the FOSOAuthServerBundle.
I've been following this Article to implement it.
Since i don't use FOS User bundle i had to create a UserProvider.
I'm also using A User Repository as he did in his Article.
I've been stuck with this error :
ContextErrorException: Catchable Fatal Error: Argument 2 passed to Doctrine\ORM\EntityRepository::__construct() must be an instance of Doctrine\ORM\Mapping\ClassMetadata, none given, called in /app/cache/dev/appDevDebugProjectContainer.php on line 3527 and defined in /app/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php line 67
I've followed the given code for services.yml:
And converted it to Yaml, here my file (services.yml) :
imports:
- { resource: parameters.yml }
parameters:
# wca_transition.example.class: WCA\TransitionBundle\Example
collection.import.from_email: "%import_from_email%"
collection.import.to_email: "%import_to_email%"
platform.entity.user.class: WCA\ServerBundle\Entity\Profile
platform.user.provider.class: WCA\ServerBundle\Provider\ProfileProvider
services:
# wca_betosee_transition.example:
# class: %wca_transition.example.class%
# arguments: [#service_id, "plain_value", %parameter%]
collectionImportCommand:
class: WCA\ServerBundle\Command\CollectionImporterCommand
calls:
- [setContainer, ["#service_container"] ]
platform.user.manager:
class: Doctrine\ORM\EntityManager
factory-service: doctrine
factory-method: getManagerForClass
arguments: ["%platform.entity.user.class%"]
platform.user.repository:
class: WCA\ServerBundle\Model\ProfileRepository
factory-service: platform.user.manager
factory-method: getRepository
arguments: ["%platform.entity.user.class%"]
platform.user.provider:
class: "%platform.user.provider.class%"
# arguments: ["#platform.user.repository"]
platform.grant_type.api_key:
class: WCA\ServerBundle\OAuth\ApiKeyGrantExtension
arguments: ["#platform.user.repository"]
tags:
- { name: fos_oauth_server.grant_extension, uri: http://mywebsite.local/grants/api_key }
I suppose the given error is coming from my configuration but i don't see what could be wrong since i followed what was given. Either the services created don't get the given arguments ("none given") or i don't pass the correct ones.
Any ideas or hints?
PS : If you need any other files, don't hesitate to ask, i'll update the post.
I doubt if it will help but try changing factory-service,factory-method to factory_service and factory_method to match the Symfony documentation.
Sounds like it is the only article that describes very well how to implement FOS OAuth2 bundle, even better than their own documentation.
But for some reason, services are defined in xml which I find very weird and ugly.
Anyway, as #Cerad mentioned, if you translate the xml service to the yaml format, then you'll have to replace the - by _ and it will work fine.

Cannot import resource error, FosRestBundle Throws InvalidArgumentException

Hello i have a strange problem, while using FostRestBundle.
First error is :
InvalidArgumentException: Every parent controller must have get{SINGULAR}Action($id) method
where {SINGULAR} is a singular form of associated object
And the second one :
Cannot import resource "/home/a15net/public_html/game/src/ATL/ContentBundle/Resources/config/api_routing.yml" from "/home/a15net/public_html/game/app/config/routing.yml".
I'v checked my all "YAML" files but there was no indent problems.
Tried to update composer twice nothing helped.
Edit : Config.yml > http://goo.gl/dqCAu
You have to remove the 'type' from this import statement fro your routing.yml
atl_content_api:
resource: "#ATLContentBundle/Resources/config/api_routing.yml"
Inside the api_routing.yml you can specify the rest type for each controller like,
acme_user_rest:
resource: Acme\UserBundle\Controller\UserRestController
prefix: /api
type: rest
this blog will help you to implement the sme
--- NOT --- SOLUTION :
If a route has a parent route, you must not put "type:rest" to it. You have to use "type:rest" only in parent routes.
Sample :
catalogs:
type: rest
prefix: api
resource: ATL\CatalogBundle\Controller\API\CatalogsController
options:
expose: true
taxonomy:
parent: catalogs
resource: ATL\CatalogBundle\Controller\API\TaxonomyController
options:
expose: true
I will not choose this as correct answer until more comments and other solution suggestions writed.
Edit
When you remove type:rest from children route, it is not a rest route anymore.

Set the default propel connection for entire php process

Propel 1.6 and Symfony 1.4
I'm looking for a way to programmatically set the default propel connection for the length of an entire php process. The issue is that I'm using an alternative db for testing purposes and I have a good deal of code that doesn't pass the PropelPDO object currently.
Can this be done? Any tips? Thanks.
Why not use environments in your databases.yml?
dev:
propel:
class: sfPropelDatabase
param:
classname: DebugPDO
etc, etc
stage:
propel:
class: sfPropelDatabase
param:
classname: PropelPDO
etc, etc
prod:
propel:
class: sfPropelDatabase
param:
classname: PropelPDO
etc, etc
So, the solution to this was to use the following, pretty clean and sweet:
//override the "default" "propel" dsn and set it to our testing db!
\Propel::setConnection(
"propel",
Propel::getConnection(SqliteSetup::$databaseName)
);

Class Gedmo\Translatable\Entity\Translation is not a valid entity or mapped super class

When i am trying to persist content through my entity i get the following error:
Class Gedmo\Translatable\Entity\Translation is not a valid entity or mapped super class.
I have done some research, but can't find anything that solves this problem.
The error disappears when I change:
orm:
default: translatable: true
To:
orm: default: ~
in config.yml.
But the content is not saved as translation, but overwrites the existing content in the "new" language.
I have the following relevant lines in my deps file:
[symfony]
git=http://github.com/symfony/symfony.git
version=origin/2.0
[gedmo-doctrine-extensions]
git=http://github.com/l3pp4rd/DoctrineExtensions.git
version=v2.3.0
[Stof-DoctrineExtensionsBundle]
git=https://github.com/stof/StofDoctrineExtensionsBundle.git
target=/bundles/Stof/DoctrineExtensionsBundle
I think that the problem is that you are requesting version 2.3.0 of the extensions but your symfony version is 2.0.x which does not include the latest Doctrine version. You should change this to:
[gedmo-doctrine-extensions]
git=http://github.com/l3pp4rd/DoctrineExtensions.git
version=v2.1.0
[DoctrineExtensionsBundle]
git=http://github.com/stof/StofDoctrineExtensionsBundle.git
target=/bundles/Stof/DoctrineExtensionsBundle
version=1.0.0

Resources