+4 votes

Hi all,

We have some really exciting news for you. Today is a big day for us as we’re releasing first public beta of ORM Designer 2. This version comes with a whole new code leaving almost nothing but the product name unchanged.

One of the new key features is native support of Linux, OS X and Windows systems. But these are old news to the ones following us on twitter or blog. Now we are adding another great feature that many of you were asking for. As of now ORM Designer fully supports Doctrine 2 annotations. It was a big challenge for us, we accepted it and now we can say we accomplished it ;-).

As with any beta and especially with the first beta version please bear in mind that you might experience bugs or unexpected results. Please let us know about these issues and we’ll make sure it’s fixed in a future revision.

You can download new version of ORM Designer 2 here. But before you do, please read more about how annotations support works:

How annotations import/export works?

When we began implementing annotations support we had to figure out how to update your code without changing or removing anything but the Doctrine mapping. We defined explicit rules for add, update and remove actions:

ADD - Add anything generated by ORM Designer if there’s no collision with your code:

  • Namespace definitions
  • Default namespace definitions
  • Entity class (if generating new code)
  • Variable declaration
  • Variable annotations declaration
  • todo: getters, setters, collections adders and getters(see the next section)

UPDATE - ORM Designer updates only Doctrine2 annotations within namespace "Doctrine\ORM\Mapping".

DELETE - This is the most important. ORM Designer NEVER removes anything from your code with the only exception of Doctrine2 annotations from namespace "Doctrine\ORM\Mapping".

  • If you add field to your Entity by using ORM Designer, new variable with annotations is added.
  • If you remove this field from your ORM Designer model, only annotations of this variable is removed!
  • Variable itself is left in code and you remove it manually if you want to.
  • The same is true for associations’ variables
  • And the same applies for the class itself. If you remove your class from diagram, the file is kept untouched. You shall remove the class if you want to manually.

Annotations:

  • ORM Designer evaluates complete namespaces when parsing your source code.
  • The tricky part is @Entity definition without namespaces. For such cases ORM Designer has a list of Doctrine2 annotations to recognize it also without namespace qualification.
  • Default namespace used with ORM Designer is a recommended Doctrine2 format "@ORM\Entity".

REFORMAT

Because ORM Designer sometimes adds code snippets to your code, it's necessary to add this code as smoothly as possible. For that ORM Designer follows these rules:

  • Code snippet is always inserted to the best position, not only to the end of file.
  • When adding new variable, search for a similar variable in the code.
  • When adding namespace definition, add it as last item of your namespace definitions list
  • When modifying annotations, keep ORM annotations together and keep other annotations without modifications.
  • When inserting anything new, scan for file indention and use the same (If you're using two spaces for indention, ORM Designer indent new code with two spaces, if you're using tabs, ORM Designer uses tabs.)
  • ORM Designer recognizes some annotation types and might sometime unify these annotations (Doctrine 2 only). For example array(1,2,3) is exported as one-line, but if you have array of complex structures, each element is exported on separate line with adequate indention!

Definition files scanner
Another part of annotations support is new project scanner. Because entities defined by annotations can be located anywhere in the project in several files, we implemented also fast annotations scanner which helps you to find all your definition files.

Usage is to YML or XML definitions import. Simply choose your project's root directory and let ORM Designer do his job. Depending on project size scanning and importing can take some time, because ORM Designer needs to scan ALL your PHP files. We already test it on large projects (~4500 files and ~200 entities) and scanner takes about 5-10seconds, import less than a minute.

What can be done next

  • Currently ORM Designer imports/exports only annotations and variables. In the future it will be also possible to perform one-time export of getters and setters functions. But before that, we need to know what format / content of these functions is preferred most.
  • Now our importers/exports support only core Doctrine2 annotations. But in the future will be also possible to import other annotations based on or even vaguely related Doctrine2. Right now we know about:

Samples

For those of you interested in how ORM Designer exports PHP files, here are some examples:
- http://pastebin.com/DaXHRi7z
- http://pastebin.com/N7YRZDP7
- http://pastebin.com/q4UpMSUK

Summary

Although we spent a lot of time on annotations support and just annotation parser itself is covered by more than 200 unit tests, there will be probably some bugs. Please be patient and report us all bugs you might experience so we can bring you better ORM Designer 2 in near future.

Thank you all and thanks for helping us making a better tool for ORM developers!

Ludek

in Information by Skipper developer (141k points)
edited by

3 Answers

0 votes
Best answer

Thank you for adding this! A question about what comes next: will you add annotation support to "File > Import ORM Schema"? This would allow me to import the tables from Symfony2's FOSUserBundle for example, so I can set up relations between them.

by (780 points)
selected by

You should be able to import it right now. You need a latest version of ORMD2 (2.1.4.656) and follow these steps:

After that your model will contain new module with imported entities.

http://screencast.com/t/Z2QMNgDLmknr

0 votes

Namespace definitions
Default namespace definitions

How i can define custom namespace? I create some tables with relationships, export by Doctrine2php and i has only

use Doctrine\ORM\Mapping AS ORM;

without any namespaces.

by (270 points)

You should be able to define namespace for whole module by editing ORM Property "namespace" defined for each module.

enter image description here

0 votes

my Request:

Doctrine Annotations Support:
@Gedmo extensions github url
A system to include custom annotations:
if you need more info a custom annotations have 2 type: entity annotation and field annotation.
in doctrine2 xml export schema i suggest a area to define:

  • namespace name es: Doctrine\ORM\Mapping
  • shortcut namespace es: ORM
  • list of custom annotations with custom field for any annotation
by (450 points)

Hi, thanks for suggestions. But could you be more clear what exactly would you like to see in next ORM Designer versions?

ad @Gedbo. We know about it and we have plans to support it, not sure when exactly.

ad custom annotations: Could you post sample of PHP file how would you like to see the result?

ad last part: Don't understand what you mean by this. ORM Designer already defines ORM shortcut for Doctrine\ORM\Mapping. Maybe some example would help.

Custom Annotation

In my project i create some custom annotation that hook a doctrine2 postload event

es.:

use Manticora\RestODM\Mapping as REST
class Project {

   @REST\Resource(server="api.rest.com", resource="user")
   @ORM\Column(type="string")
   protected $user_id;
}

after postload this api retrieve a user from api.rest.com/user/$user_id

in doctrine schema i want define:

  • annotation namespace: in my example is Manticora\RestODM\Mapping
  • a shortcut: in this example is Rest
  • a set of annotations if existis in namespace with attributes and define if annotation is a classannotation or a fieldannotation or both. in my example Rest\Resource is a field_annotation

with a custom annotations option orm designer can work a littile with Doctrine-mongoDb and other doctrine ODM

And Now i have few some other ideas (sry!!):

  • PHP 5.4 support traits feature: can you create an entity type traits
  • Doctrine 2.3 support a relations with abstract class and interface relation with interface

you can create export for these functionalities with define 3 new types of entities (traits, abstract class and interface)

thx for your answer and sorry for my bad english

Thanks for detailed answer.

Regarding to custom annotations, I think it should be possible to implement it. But I can't promise when. It will need more analyses of whole problem and implement it more universally to offer necessary customizability.

All of this will need some new ways how to predefine namespaces, shortcuts, ability to define several new annotations to entities/fields etc. But I think all of this would be possible by our new ORM property system.

Regarding to your other two ideas. I'm not PHP programmer so I'm not familiar with traits, but I will consult it with my colleagues. But as same as the second idea, I can't promise you any ETA for this. Now we have a lot of another short-term todo-s we want to implement, so your ideas could be implemented soon thereafter.

I would like to let you know that support for MongoDB is ready. More information about MongoDB ODM support is available here.