60844

Using JMSSerialize to serialize Doctrine2 Entities that follow SimplifiedYamlDriver convention

Question:

The symfony sponsored project \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver is really useful in my project to keep Entity file names clean and simple. However, JMSSerialize assumes that the naming convention for each Entity is the fully qualified namespace. This is not true when using \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver in your Doctrine2 Configuration.

(<a href="http://docs.doctrine-project.org/en/latest/reference/yaml-mapping.html" rel="nofollow">http://docs.doctrine-project.org/en/latest/reference/yaml-mapping.html</a>)

<?php $namespaces = array( '/path/to/files1' => 'MyProject\Entities', '/path/to/files2' => 'OtherProject\Entities' ); $driver = new \Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver($namespaces);

According to the docs: <strong>Filenames are shortened, “MyProject\Entities\User” will become User.orm.yml</strong>

But JMSSerialzer is looking for the YAML files at $myDir . '/MyProject.Entities.User.yml'

(see: <a href="http://jmsyst.com/libs/serializer/master/configuration#configuring-metadata-locations" rel="nofollow">http://jmsyst.com/libs/serializer/master/configuration#configuring-metadata-locations</a>)

<strong>Question: Is there a way to override the metadata filename JMSSerialize looks for? I'm already using addMetadataDir() to specify its location</strong>

<em>Note: this is not a Symfony2 project</em>

Answer1:

Are you using the second parameter of addMetadataDir?

From JMS\Serializer\SerializerBuilder.php:

/** * Adds a directory where the serializer will look for class metadata. * * The namespace prefix will make the names of the actual metadata files a bit shorter. For example, let's assume * that you have a directory where you only store metadata files for the ``MyApplication\Entity`` namespace. * * If you use an empty prefix, your metadata files would need to look like: * * ``my-dir/MyApplication.Entity.SomeObject.yml`` * ``my-dir/MyApplication.Entity.OtherObject.xml`` * * If you use ``MyApplication\Entity`` as prefix, your metadata files would need to look like: * * ``my-dir/SomeObject.yml`` * ``my-dir/OtherObject.yml`` * * Please keep in mind that you currently may only have one directory per namespace prefix. * * @param string $dir The directory where metadata files are located. * @param string $namespacePrefix An optional prefix if you only store metadata for specific namespaces in this directory. * * @return SerializerBuilder * * @throws InvalidArgumentException When a directory does not exist * @throws InvalidArgumentException When a directory has already been registered */ public function addMetadataDir($dir, $namespacePrefix = '') { // ... }

It appears that if you specify the second parameter, you can achieve what you're looking for.

Recommend

  • how to list images on sd card sorted according to time
  • How to compare two directories and their files in perl
  • PHP upload/read files on separate drive
  • Alert email not working correctly
  • Google Analytics v4 in Android: Could not find class 'com.google.android.gms.analytics.Tracker&
  • How many wiki instances to install?
  • Describe the .NET assembly circular dependency problem in layman's terms
  • Deployments not visible in Kubernetes Dashboard
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • How can I include If-None-Match header in HttpRequestMessage
  • How to get links to open in the native browser in iOS Meteor apps?
  • gspread or such: help me get cell coordinates (not value)
  • Parse a date string in a specific locale (not timezone!)
  • ImageMagick, replace semi-transparent white with opaque white
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • Cannot connect to cassandra from Spark
  • Display issues when we change from one jquery mobile page to another in firefox
  • Cross-Platform Protobuf Serialization
  • script to move all files from one location to another location
  • ILMerge & Keep Assembly Name
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Symfony2: How to get request parameter
  • Upload files with Ajax and Jquery
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Do I've to free mysql result after storing it?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • How to get icons for entities from eclipse?
  • A cron job substitute?
  • json Serialization in asp
  • Proper way to use connect-multiparty with express.js?
  • Benchmarking RAM performance - UWP and C#
  • Load html files in TinyMce
  • Angular 2 constructor injection vs direct access
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • JaxB to read class hierarchy
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal