Convert Figma logo to code with AI

stof logoStofDoctrineExtensionsBundle

Integration bundle for DoctrineExtensions by l3pp4rd in Symfony

1,886
380
1,886
52

Top Related Projects

Symfony Bundle for Doctrine ORM and DBAL

Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.

JWT authentication for your Symfony API

Quick Overview

StofDoctrineExtensionsBundle is a Symfony bundle that integrates Gedmo Doctrine extensions into Symfony applications. It provides easy configuration and integration of popular Doctrine extensions like Timestampable, Sluggable, and Tree, allowing developers to quickly add powerful functionality to their Doctrine entities.

Pros

  • Simplifies the integration of Gedmo Doctrine extensions in Symfony projects
  • Provides a consistent configuration interface for multiple extensions
  • Supports a wide range of useful Doctrine extensions out of the box
  • Regularly maintained and compatible with recent Symfony versions

Cons

  • Adds an additional layer of abstraction over Doctrine extensions
  • May introduce unnecessary complexity for projects that only need a few extensions
  • Requires understanding of both Symfony and Doctrine concepts
  • Some extensions may have performance implications if not used carefully

Code Examples

  1. Configuring Timestampable extension:
# config/packages/stof_doctrine_extensions.yaml
stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            timestampable: true
  1. Using Timestampable in an entity:
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Article
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private $id;

    #[Gedmo\Timestampable(on: 'create')]
    #[ORM\Column(type: 'datetime')]
    private $createdAt;

    #[Gedmo\Timestampable(on: 'update')]
    #[ORM\Column(type: 'datetime')]
    private $updatedAt;
}
  1. Configuring and using Sluggable:
# config/packages/stof_doctrine_extensions.yaml
stof_doctrine_extensions:
    orm:
        default:
            sluggable: true
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Article
{
    #[ORM\Column(length: 128)]
    private $title;

    #[Gedmo\Slug(fields: ['title'])]
    #[ORM\Column(length: 128, unique: true)]
    private $slug;
}

Getting Started

  1. Install the bundle:

    composer require stof/doctrine-extensions-bundle
    
  2. Enable the bundle in config/bundles.php:

    return [
        // ...
        Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
    ];
    
  3. Configure the extensions you want to use in config/packages/stof_doctrine_extensions.yaml:

    stof_doctrine_extensions:
        default_locale: en_US
        orm:
            default:
                timestampable: true
                sluggable: true
    
  4. Use the Gedmo annotations in your entities as shown in the code examples above.

Competitor Comparisons

Symfony Bundle for Doctrine ORM and DBAL

Pros of DoctrineBundle

  • Core Symfony integration for Doctrine ORM
  • Provides essential configuration and services for database interaction
  • Regularly updated and maintained by the Doctrine team

Cons of DoctrineBundle

  • Limited to basic Doctrine functionality
  • Lacks advanced features like behaviors and extensions
  • Requires additional bundles for extended capabilities

Code Comparison

StofDoctrineExtensionsBundle:

stof_doctrine_extensions:
    orm:
        default:
            timestampable: true
            sluggable: true

DoctrineBundle:

doctrine:
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

Summary

DoctrineBundle is the official Symfony integration for Doctrine ORM, providing essential database functionality. It's well-maintained and regularly updated. However, it lacks advanced features like behaviors and extensions.

StofDoctrineExtensionsBundle, on the other hand, extends DoctrineBundle's capabilities by integrating Doctrine Extensions. It offers additional features like Timestampable, Sluggable, and other behavioral extensions, making it more suitable for projects requiring these advanced functionalities.

While DoctrineBundle is sufficient for basic database operations, projects needing extended behaviors may benefit from using StofDoctrineExtensionsBundle alongside DoctrineBundle.

Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable

Pros of DoctrineExtensions

  • Standalone library, usable in any PHP project without Symfony dependency
  • More frequent updates and active development
  • Wider community support and contributions

Cons of DoctrineExtensions

  • Requires manual configuration in Symfony projects
  • Less integrated with Symfony's dependency injection system
  • May require additional setup for certain features in Symfony environment

Code Comparison

StofDoctrineExtensionsBundle (in Symfony):

# config/packages/stof_doctrine_extensions.yaml
stof_doctrine_extensions:
    orm:
        default:
            timestampable: true
            sluggable: true

DoctrineExtensions (manual setup in Symfony):

// src/Kernel.php
use Gedmo\Timestampable\TimestampableListener;
use Gedmo\Sluggable\SluggableListener;

public function bootKernel()
{
    $em = $this->getContainer()->get('doctrine.orm.entity_manager');
    $em->getEventManager()->addEventSubscriber(new TimestampableListener());
    $em->getEventManager()->addEventSubscriber(new SluggableListener());
}

Both libraries provide similar functionality, but StofDoctrineExtensionsBundle offers easier integration with Symfony projects, while DoctrineExtensions provides more flexibility for use in various PHP environments.

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.

Pros of FOSUserBundle

  • Provides a complete user management system out-of-the-box
  • Offers extensive customization options for user entities and forms
  • Includes built-in support for registration, password reset, and email confirmation

Cons of FOSUserBundle

  • Can be overkill for simple projects that don't require extensive user management
  • Less flexible for projects with unique user entity requirements
  • Requires more configuration and setup compared to StofDoctrineExtensionsBundle

Code Comparison

FOSUserBundle (User entity example):

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    // ...
}

StofDoctrineExtensionsBundle (Timestampable trait example):

use Gedmo\Timestampable\Traits\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Article
{
    use TimestampableEntity;
    // ...
}

FOSUserBundle focuses on user management, while StofDoctrineExtensionsBundle provides various Doctrine extensions. The code examples show how FOSUserBundle extends a base User class, whereas StofDoctrineExtensionsBundle uses traits to add functionality to entities.

JWT authentication for your Symfony API

Pros of LexikJWTAuthenticationBundle

  • Specialized for JWT authentication, providing a robust and secure solution
  • Easy integration with Symfony's security system
  • Offers flexibility in token creation, validation, and management

Cons of LexikJWTAuthenticationBundle

  • Limited to JWT authentication, while StofDoctrineExtensionsBundle offers broader functionality
  • May require additional configuration for complex authentication scenarios
  • Less suitable for projects not using JWT as the primary authentication method

Code Comparison

LexikJWTAuthenticationBundle:

lexik_jwt_authentication:
    secret_key: '%env(resolve:JWT_SECRET_KEY)%'
    public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
    pass_phrase: '%env(JWT_PASSPHRASE)%'

StofDoctrineExtensionsBundle:

stof_doctrine_extensions:
    orm:
        default:
            timestampable: true
            sluggable: true
            tree: true

The code snippets demonstrate the configuration differences. LexikJWTAuthenticationBundle focuses on JWT-specific settings, while StofDoctrineExtensionsBundle configures various Doctrine extensions for ORM functionality.

LexikJWTAuthenticationBundle is ideal for projects requiring JWT authentication, offering specialized features and integration. StofDoctrineExtensionsBundle, on the other hand, provides a wider range of Doctrine extensions, making it more versatile for general ORM enhancements but less focused on authentication.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

StofDoctrineExtensionsBundle

This bundle provides integration for DoctrineExtensions in your Symfony Project.

Total Downloads Latest Stable Version

For documentation, see it online

License: MIT