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