All Projects → mtarld → symbok-bundle

mtarld / symbok-bundle

Licence: MIT license
Symfony annotations bundle

Programming Languages

PHP
23972 projects - #3 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to symbok-bundle

Sonatadoctrineormadminbundle
Integrate Doctrine ORM into the SonataAdminBundle
Stars: ✭ 400 (+700%)
Mutual labels:  symfony-bundle, doctrine
Doctrinetraitbundle
Generate the entities stub methods in a trait
Stars: ✭ 6 (-88%)
Mutual labels:  symfony-bundle, doctrine
Doctrinebundle
Symfony Bundle for Doctrine ORM and DBAL
Stars: ✭ 4,225 (+8350%)
Mutual labels:  symfony-bundle, doctrine
Doctrinecachebundle
Symfony2 Bundle for Doctrine Cache
Stars: ✭ 2,813 (+5526%)
Mutual labels:  symfony-bundle, doctrine
Stofdoctrineextensionsbundle
Integration bundle for DoctrineExtensions by l3pp4rd in Symfony
Stars: ✭ 1,713 (+3326%)
Mutual labels:  symfony-bundle, doctrine
Translationformbundle
Ease translations with some dedicated Symfony form types
Stars: ✭ 289 (+478%)
Mutual labels:  symfony-bundle, doctrine
Doctrine Json Odm
An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
Stars: ✭ 420 (+740%)
Mutual labels:  symfony-bundle, doctrine
Kotlin Builder Annotation
A minimal viable replacement for the Lombok @Builder plugin for Kotlin code
Stars: ✭ 67 (+34%)
Mutual labels:  lombok, annotations
Doctrinephpcrbundle
This bundle integrates Doctrine PHPCR ODM and PHPCR backends into Symfony
Stars: ✭ 131 (+162%)
Mutual labels:  symfony-bundle, doctrine
User Bundle
A new Symfony user bundle
Stars: ✭ 116 (+132%)
Mutual labels:  symfony-bundle, doctrine
doctrine-json-odm
JSON Object-Document Mapping bundle for Symfony and Doctrine
Stars: ✭ 15 (-70%)
Mutual labels:  symfony-bundle, doctrine
Msgphp
Reusable domain layers. Shipped with industry standard infrastructure.
Stars: ✭ 182 (+264%)
Mutual labels:  symfony-bundle, doctrine
eav-bundle
A Symfony bundle for basic EAV management
Stars: ✭ 19 (-62%)
Mutual labels:  symfony-bundle, doctrine
Doctrinemigrationsbundle
Symfony integration for the doctrine/migrations library
Stars: ✭ 3,782 (+7464%)
Mutual labels:  symfony-bundle, doctrine
annotation-cache-bundle
Annotation based caching for services inside a symfony container
Stars: ✭ 16 (-68%)
Mutual labels:  symfony-bundle, annotations
Doctrineenumbundle
📦 Provides support of ENUM type for Doctrine in Symfony applications.
Stars: ✭ 410 (+720%)
Mutual labels:  symfony-bundle, doctrine
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (-18%)
Mutual labels:  annotations, annotation-processing
Placeholderview
This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS -->
Stars: ✭ 2,104 (+4108%)
Mutual labels:  annotations, annotation-processing
Oneupaclbundle
The missing link between Symfonys Acl implementation and your application.
Stars: ✭ 48 (-4%)
Mutual labels:  symfony-bundle, doctrine
Doctrinefixturesbundle
Symfony integration for the doctrine/data-fixtures library
Stars: ✭ 2,174 (+4248%)
Mutual labels:  symfony-bundle, doctrine

⚠️ Status: Archived

With PHP 8.1 and the emergence of public readonly properties, this bundle repository has been archived and is no longer maintained.

If you really need to generate getters and setters generation, you can have a look at lombok-php.

Symbok Annotation Bundle

Packagist GitHub Actions Status

Runtime code generator bundle for Symfony.

  • Detects classes that are using Symbok annotations, generates related methods and loads generated class instead of the original one.
  • Stores generated classes in Symfony cache so that Symbok compiles them just once.
  • Reads basic Doctrine annotations to handle property's type, nullable status and entity relation.

Initially inspired by Plumbok.

Compatible with Symfony 4 and 5

Symbok ?

👋 Bye bye endless PHP classes !

Symbok provides annotations in order to generate on the fly predictable and repetitive methods.

Available annotations are:

  • AllArgsConstructor
  • Data
  • ToString
  • Getter
  • Setter
  • Nullable

Symbok also parses doctrine properties annotations such as Column, JoinColumn, OneToOne, OneToMany, ManyToOne, ManyToMany in order to automatically discover property type, nullable status and adapt generated methods.

You'll be able to find more precise information on Symbok Bundle in the documentation

Getting started

Installation

You can easily install Symbok by composer

$ composer require mtarld/symbok-bundle

Then, bundle should be registered. Just verify that config\bundles.php is containing :

Mtarld\SymbokBundle\SymbokBundle::class => ['all' => true]

Configuration

Once Symbok is installed, you should configure it to fit your needs.

To do so, edit config/packages/symbok.yaml

# config/packages/symbok.yaml

symbok:
    # Namespaces that you wanna be processed
    namespaces:
        - 'App\Entity'
        - 'App\Model'
        
    defaults:
        getter: ~
            # If getters are nullable by default (default true)
            nullable: ~

        setter: ~
            # If setters are fluent by default (default true)
            fluent: ~

            # If setters are nullable by default (default true)
            nullable: ~

            # If setters should update other side when relation is detected (default true)
            updateOtherSide: ~

        constructor:
            # If constructor uses nullable parameters (default true)
            nullable: ~

And you're ready to go ! 🚀

Basic example

Register your namespace in config file

# config/packages/symbok.yaml

symbok:
    namespaces:
      - 'App\Entity'

Then edit your class by adding annotations

<?php

// src/Entity/Product.php

namespace App\Entity;

use Mtarld\SymbokBundle\Annotation\Getter;

class Product
{
    /**
     * @Getter
     */
    private int $id;
}

Then, the class will be executed as the following:

<?php

namespace App\Entity;

use Mtarld\SymbokBundle\Annotation\Getter;

class Product
{
    /**
     * @Getter
     */
    private int $id;
    
    public function getId(): ?int
    {
        return $this->id;
    }
}

Provided commands

Updating original files with symbok:update:classes

$ php bin/console symbok:update:classes

When running this command, original classes' docblock will be updated with good @method tags so that IDEs will be able to know that new methods exist.

For instance, the class:

<?php

// src/Entity/Product.php

namespace App\Entity;

use Mtarld\SymbokBundle\Annotation\Getter;

class Product
{
    /**
     * @var int
     * @Getter
     */
    private $id;
}

Will be rewritten as:

<?php

// src/Entity/Product.php

namespace App\Entity;

use Mtarld\SymbokBundle\Annotation\Getter;

/**
 * @method int getId()
 */
class Product
{
    /**
     * @var int
     * @Getter
     */
    private $id;
}

Previewing results with symbok:preview

$ php bin/console symbok:preview [-s|--compilationStrategy COMPILATIONSTRATEGY] <class path>

By using that command, you will be able preview Symbok compilation results directly in your CLI.

Compilation strategy represents which compilation will be applied on target class. It could be either:

  • runtime to preview PHP code that will be executed at runtime
  • saved to preview PHP code that will be written when using symbok:update:classes command

Documentation

A detailed documentation is available here

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

After writing your fix/feature, you can run following commands to make sure that everyting is still ok.

# Install dev dependencies
$ composer install

# Running tests locally
$ make test

Authors

  • Mathias Arlaud - mtarld - <mathias(dot)arlaud@gmail(dot)com>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].