PHP annotations : Addendum or Doctrine Annotation? - php

Addendum
Doctrine 2 Annotations
Can you give me any reason one is better than the other ?
Here my list for now :
Addendum is a project dedicated for that
Addendum seems to have more functionnalities
Addendum API seems easier to use
Doctrine has more support and more people involved
Doctrine seems to be a project more alive
Doctrine is fully compatible PHP 5.3, whereas Addendum seems to be trying to become compatible (see home page)
Doctrine Annotations can be cached easily
The decision is not easy...

I suppose I'd rather use the Doctrine's component :
I've never heard of Addendum -- while I've heard a lot about Doctrine (and have used it several times)
Which means more community and support for Doctrine
Doctrine is used by some big Frameworks (symfony ; and can easily be integrated with Zend Framework)
Which means chances are higher that you'll already use Doctrine ; and find developers who are familiar with its syntax
Maybe less important for you, But some guy from Doctrine's team has done some work on getting Annotations integrated into PHP
There is a RFC : Request for Comments: Class Metadata
For now, it doesn't seem this is going to be integrated into PHP, but it means there is works done by the Doctrine's team, that shows their solution has some thinking

For what it's worth...
I've been using Addendum for a year now, and I've found it ridiculously easy to use. Its extension to the PHP Reflection API is seamless, and it supports far more use cases than Doctrine Annotations component.
It lacks namespaces support, but I could patch AnnotationMatcher class so it accepted namespaced classes (without getting false matches from docblock tags) and it has worked like a charm.
Doctrine's annotations takes into account PHP 5.3 use statements. That's the only thing that Addendum does not do and IMO it wouldn't be so trivial to implement.

Related

The mechanism of annotations in Symfony - how does it all work?

I have started to learn Symfony (4.1) and I have a question about annotations.
As far as I know, annotation are just comments in terms of php and they are not a part of the language itself. However they are rather powerful thing in Symfony.
I want to know, how it all works.
Is there a code preprocessor which parses the source files dynamically and creates new php entities?
But if it's so, how does it affect the performance of an application?
Why should I use special namespaces for certain annotations?
Put simply, I would like to know how do annotations in Symfony work, the mechanism of this feature.
Yes, indeed, annotations are not part of the language itself. But they're also not the part of Symfony framework.
Annotations are usually handled by doctrine/annotations package (most common). It utilizes reflection to read and parse these comments and transform them into annotation objects (every annotation has an annotation class which it represents).
Then, its up to the library to make use of generated objects representing these annotations.
So to answer first question - yes, there is a preprocessor. But it doesn't "create new php entities", because its the job for the library that uses those annotations (e.g. Symfony framework or Doctrine ORM).
How it affects the performance, depends on the library that uses them. If they would be parsed on every request, that would indeed affect performance. So e.g. Symfony and Doctrine ORM cache this data or create proxy classes etc.
So the answer to second question is - it might if used incorrectly, but it usually is not (in production environment) as they are simply not parsed every time.
The last question doesn't really relates to annotations. Since annotations are really classes, the reason for namespacing them is also the same. To avoid conflicts between libraries and for sake of readability.

How to upgrade symfony from 1.4 to 2.1? [duplicate]

I've got a huge site that has been written (in a very bad way) in symfony 1.4
now, I've been asked to make some substantial changes to the navigation flow, add some features and so on..
considering the effort, I was wondering if it would be better to take the radical decision to port the entire website to symfony 2.0, but I'm not sure how hard that it could be.
Has anybody ever done this before?
Do you have any suggestion to make for patterns to follow, or tutorials or doc or whatever?
You may wrap your legacy project in a brand new sf2 project, by using this bundle. This way, you'll be able to migrate your project one piece at a time, and new functionalities may be developed with sf2 as soon as you get the wrapper to work.
You may be interested by this post about migrating
Here's how I would go about it:
You need to learn and study some things first:
HTTP fundamentals
PHP namespaces, which are heavily used
Symfony2 documentation
Symfony2 documentation
Symfony2 documentation
PHPUnit documentation
Then when you get the hang of Symfony2, you need to find out what to reuse from your old project:
Models, business logic?
Did you use Doctrine in symfony? If yes, look at how to port your entities to Doctrine2, and learn about the differences. If you used Propel, I would look at switching to Doctrine2 and not use the PropelBundle, atleast until you get used to Symfony2. You can find better documentation and sample code out there for Doctrine2.
You also need to convert your old helpers classes to Symfony2 services.
Views?
Symfony2 uses Twig as templating engine, but you could go with pure PHP.
Controllers?
This should feel somewhat similar to symfony. The flow of Symfony2 matches the HTTP flow, meaning you get a Request object and must reurn a Response object.
It really depends on how well structured our old project is. Symfony2 is an entirely different beast than 1.0-1.4. I would probably not call it a port, but a rewrite - however, if your old project is well structured you could probably reuse quite a bit.
Without actually seeing your code, it's impossible to give a good answer on how hard it would be. It's very much doable, but there is no easy route. Symfony2 is, IMHO, the way of the future for PHP projects and in the end you will get a project that is much easier to maintain and support.

Starting with Doctrine. Which version is good to?

I'm using Zend Framework and I feel that I need a good ORM to work with. I don't know much of Zend Framework, I just know how to do the basics. I expect to work together with both Doctrine and Zend Framework
But to sget started, I'm going to try a simple Doctrine project (no ZF) to get used to the application. Then I'll try to integrate it in ZF
Which version of Doctrine do I start learning? Does Doctrine have a good integration with ZF?
Besides,
Is there any recent site for Doctrine learning? I just can't find the sandbox version to follow the Doctrine documentation. If anyone knows of any tutorial on how to get started with doctrine only first, please let me know
I've done projects with zend framework and doctrine. They play pretty nice together.
I followed this tutorial and it worked well.
But honestly I don't use doctrine on anything but the largest sites. I've switched over to RedBean. Zero configuration autodiscovery, and the ability to freeze data models when you are done for maximum performance.
You should really try it out, it is so simple its stupid. It is really one of the best ORM's ive ever used. EVER. Try it.
I am personally using Doctrine 1.2
and i followed the Zendcasts.com "more than 5 casts about doctrine" & same Byron's tuts
both of them is good
Update :
1- http://www.zendcasts.com/deep-integration-between-zend-and-doctrine-1-2/2010/01/ has the sample code
2- http://www.doctrine-project.org/projects/orm/1.2/download/1.2.3 has the doctrine framework if you need to download it alone
I've found Doctrine2 reasonable stable, although it's still in beta. It seems most of the other PHP 'ORM' libraries (Doctrine 1.2 included) are Active Record, while Doctrine2 is a Data Mapper. In my opinion, you can put together a relatively simple Active Record using Zend's native Db_Table, so that makes Doctrine 1.2 less appealing (at least to me).
I've used this answer about integrating Doctrine2 and Zend Framework.
I agree with Byron, and have only used Doctrine2 on select projects.
[As an aside, I've noticed RedBean in the past, and have wanted to try it - from what I've seen it's certainly worth taking a look.]
Doctrine 2 is in beta and requires PHP5.3 as it fully utilizes Namespaces. If you cannot use PHP5.3 in your project, you cannot use Doctrine 2.
Apart from that, there has been a number of architectural changes in Doctrine 2 that make it much more attractive than Doctrine < 2, mainly
using DataMapper instead of ActiveRecord
promotes DI over static calls
faster and less memory-intensive
revolves around Entities and DDD
uses "Annotations"
See
http://architects.dzone.com/articles/doctrine-1-doctrine-2
http://www.slideshare.net/jwage/doctrine-2-not-the-same-old-php-orm

Doctrine 2.0 ready for use?

I'm working on a small project (some mark tracking software for a school subject department - PHP frontend with a sqlite DB) and have decided to use ORM.
I've taken a look at RedBeanPHP but it seemed a bit too limited for my liking. As such, I've decided to give Doctrine a go.
My only prior experience with ORM is LINQ to SQL in .NET. Anyway, I was wondering if I should get started with Doctrine 2.0 (which is in beta at the moment) or if I should take sometime to learn 1.2.
I'm looking for feedback from those who are comfortable with both, and more importantly, I'd like to know how complete the Doctrine 2.0 documentation is. Is there enough information on the website for somebody new to Doctrine (and quite new to ORM) to get up and running with 2.0 or is the documentation for the new version still quite lacking?
Doctrine 2 is a DataMapper ORM whereas 1.2 is Active Record. I would go with 2.0; the documentation is great
The Doctrine2 documentation is quite good already. I'd start with the reference.
I've been developing with Doctrine2 for a few months now, and have had no issues. I'll be going into production with it soon, and am pretty confident.
2.0's DataMapper pattern is really superior to the 1.2/ActiveRecord model. Very flexible, and possible more performant. If you're starting development today, I think it's very likely the best way to go.

PHP: Is ReflectionClass future-compatible?

I have been using the cool reflection class in my framework. I wonder whether or not ReflectionClass is future-compatible? For example, in PHP5.3 or PHP6.
Classes that are bundled with PHP don't tend to just "disappear" ; especially classes that have been added only "lately" -- the Reflection API has only been added in PHP 5.
For PHP 5.3, it is still here (classes like that don't go away in a minor version) ; and, in fact, it is being improved with PHP 5.3.2 -- there is a new method, from what I've heard.
For PHP 6... Well, always in motion the futur is, as one would say... But I'd bet the reflection API will stay : it is really useful, is a great addition to the language, and is used by several modern tools.
Yes, go4it!
Reflection is quite new and used in many big frameworks like Zend Framework or Doctrine ORM.

Categories