Any tutorial on annotation usage with doctrine

Hi,
Is there any tutorial anyone follows on the doctrine with annotation or is there any command-line tool available which can generate annotation form based on the provided entity? Thanks!

You can follow the description in the documentation and then use the builder in a factory, for example.

Based on the description for application integration this means:

namespace Album\Controller;

use Album\Form\AlbumForm;
use Laminas\Form\Annotation\AnnotationBuilder;
use Psr\Container\ContainerInterface;

class AlbumControllerFactory
{
    public function __invoke(ContainerInterface $container) : AlbumController
    {
        /** @var AnnotationBuilder $builder */
        $builder = $container->get(AnnotationBuilder::class);
        $form    = $builder->createForm(AlbumForm::class);

        return new AlbumController($form);
    }
}

So far there are no CLI commands, but the issue tracker is open for ideas. :smiley:

Thanks, @froschdesign. But I wanted a tutorial which helps integration of doctrine and it’s associations. The above-mentioned will is just setting up a factory. Which now I’m fairly aware of. Will Symfony form example will work in Laminas as is? Thanks!

I’m sorry, I do not understand what you want. In your first post you ask for form creation via annotations on entities. This can be done with the annotations of laminas-form like in the example in the documentation:

use Laminas\Form\Annotation;

/**
 * @Annotation\Name("user")
 * @Annotation\Hydrator("Laminas\Hydrator\ObjectProperty")
 */
class User
{
    /**
     * @Annotation\Exclude()
     */
    public $id;

    /**
     * @Annotation\Filter({"name":"StringTrim"})
     * @Annotation\Validator({"name":"StringLength", "options":{"min":1, "max":25}})
     * @Annotation\Validator({"name":"Regex",
"options":{"pattern":"/^[a-zA-Z][a-zA-Z0-9_-]{0,24}$/"}})
     * @Annotation\Attributes({"type":"text"})
     * @Annotation\Options({"label":"Username:"})
     */
    public $username;

    /**
     * @Annotation\Type("Laminas\Form\Element\Email")
     * @Annotation\Options({"label":"Your email address:"})
     */
    public $email;
}

Unfortunately, I don’t know what Symfony Forms is doing on this subject.

Maybe you can enlighten us a little. :wink:

Thanks, @froschdesign again. The example provided on the documentation is fairly simple and an advance version can be looked into with your help in laminas form. I thought maybe an example like collection integration with annotation would be there. But I’ll go through the code and see what I can find and share some examples here. Thanks again!

This information is missed in your original post. :wink:

Please check the annotation ComposedObject for that.