Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Core Bundle Laravel Package

baconmanager/core-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require bacon/core-bundle
    

    Add to AppKernel.php:

    new Bacon\Bundle\CoreBundle\BaconCoreBundle(),
    new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
    
  2. Configure Doctrine: In app/config/config.yml:

    doctrine:
        orm:
            filters:
                softdeleteable:
                    class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                    enabled: true
    
  3. Register Doctrine Listeners (app/config/services.yml):

    services:
        gedmo.listener.softdeleteable:
            class: Gedmo\SoftDeleteable\SoftDeleteableListener
            tags:
                - { name: doctrine.event_subscriber, connection: default }
            calls:
                - [ setAnnotationReader, [ "@annotation_reader" ] ]
    
        gedmo.listener.timestampable:
            class: Gedmo\Timestampable\TimestampableListener
            tags:
                - { name: doctrine.event_subscriber, connection: default }
            calls:
                - [ setAnnotationReader, [ "@annotation_reader" ] ]
    
  4. First Use Case: Extend Bacon\Bundle\CoreBundle\Entity\BaseEntity for your entities:

    use Bacon\Bundle\CoreBundle\Entity\BaseEntity;
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity
     */
    class User extends BaseEntity
    {
        // Custom fields
    }
    

    The bundle automatically adds createdAt, updatedAt, and soft-delete functionality.


Implementation Patterns

Base Entity Usage

  • Automatic Fields: Extend BaseEntity to get createdAt, updatedAt, and deletedAt fields out-of-the-box.
  • Soft Deletes: Use isDeleted() and delete() methods for soft-deletion logic:
    $user = $entityManager->find(User::class, 1);
    $user->delete(); // Soft-deletes the record
    

Form Handling

  • FormHandler: Use Bacon\Bundle\CoreBundle\Form\FormHandler to simplify CRUD operations:
    use Bacon\Bundle\CoreBundle\Form\FormHandler;
    
    $formHandler = new FormHandler($form, $entityManager);
    if ($formHandler->save()) {
        // Success
    }
    

Pagination

  • KnpPaginatorBundle: Leverage the included KnpPaginatorBundle for pagination:
    use Knp\Component\Pager\PaginatorInterface;
    
    $paginator = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
        $entityManager->getRepository(User::class)->findAll(),
        $request->query->getInt('page', 1),
        10
    );
    

Twig Extensions

  • Custom Twig Filters: Use provided Twig extensions (e.g., for formatting dates or soft-deleted checks):
    {{ entity.createdAt|date('Y-m-d') }}
    {% if entity.isDeleted() %}Deleted{% endif %}
    

Gotchas and Tips

Pitfalls

  1. Soft-Delete Filter:

    • Ensure softdeleteable filter is enabled in config.yml; otherwise, soft-deleted records may still appear in queries.
    • Debug missing soft-delete behavior by checking Doctrine event subscribers.
  2. FormHandler Quirks:

    • FormHandler assumes the form is bound to an entity. Unbound forms may throw errors.
    • Validate entity state (e.g., isDeleted()) before saving to avoid conflicts.
  3. Entity Inheritance:

    • Override BaseEntity methods (e.g., prePersist()) carefully to avoid breaking automatic timestamp updates.

Debugging Tips

  • Doctrine Events: Use stderr logging to debug Doctrine listeners:
    # config.yml
    doctrine:
        dbal:
            logging: true
    
  • Soft-Delete Queries: Add AND u.deletedAt IS NULL manually to queries if soft-delete filter isn’t working.

Extension Points

  1. Custom Behaviors: Add new behaviors by extending BaseEntity and overriding methods:

    class AuditEntity extends BaseEntity
    {
        public function prePersist()
        {
            $this->setCreatedBy($this->getUser());
            parent::prePersist();
        }
    }
    
  2. Twig Extensions: Extend existing Twig filters in Resources/twig/ or override the bundle’s extensions.

  3. FormHandler: Subclass FormHandler to add custom validation or pre-save logic:

    class CustomFormHandler extends FormHandler
    {
        public function save()
        {
            if (!$this->validateCustomRules()) {
                return false;
            }
            return parent::save();
        }
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware