Search code examples
phpsymfonyannotations

PHP annotation bundle for creating setter and getter


At the moment I do not use any bundles / plugins for creating setter and getter for my project. I used Project Lombok for my JAVA projects. I was wondering if there were any solutions for PHP. I found two bundles which can be used in PHP, but these are not actively maintained anymore. The bundle names are:

  • Plumbok
  • Accessible

Are there any actively maintained bundles and easy to use inside any Symfony project in combination with PHPStorm.


Solution

  • I recently created a symfony bundle that does what you're searching for: Symbok. It's compatible with Symfony3 and 4.

    It uses an additional autoloader to detect classes that are using Symbok annotations. Then it generates related methods and load generated class instead of the original one. Generated class is stored in Symfony cache so that Symbok compiles it just once.

    The original class docblock is updated with @method tags to permit IDEs such as PHPStorm to know that getter method exists

    It also reads basic Doctrine annotations to handle property's type, nullable status and doctrine relations.

    Here is the repository link: https://github.com/mtarld/symbok-bundle