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

Common Bundle Laravel Package

belsym/common-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package to composer.json:

    {
        "require": {
            "belsym/common-bundle": "*"
        }
    }
    

    Run composer update.

  2. Register the Bundle Add new Belsym\CommonBundle\BelsymCommonBundle() to app/Kernel.php under registerBundles().

  3. First Use Case: BaseEntity Extend BaseEntity in your entity:

    use Belsym\CommonBundle\Entity\BaseEntity;
    
    class User extends BaseEntity
    {
        // Your custom fields/methods
    }
    

    Run php bin/console doctrine:schema:update --force to apply timestamps (createdAt, updatedAt).


Implementation Patterns

Entity Inheritance

  • BaseEntity: Use for all Doctrine entities needing auto-timestamps.
    class Post extends BaseEntity
    {
        // Automatically gets `id`, `createdAt`, `updatedAt`
    }
    
  • BaseUser: Extend for user-related entities (e.g., Customer, Admin).
    class Customer extends BaseUser
    {
        // Inherits `firstName`, `lastName`, `dateOfBirth`
    }
    
  • BaseLookup: Replace enums with related entities (e.g., Status table).
    class Status extends BaseLookup
    {
        // Uses a lookup table instead of SQLite enum
    }
    

DBAL Integration

  • EnumType: Replace native enums with database-backed lookups.
    use Belsym\CommonBundle\DBAL\Types\EnumType;
    
    $platform->registerDoctrineTypeMapping('enum', EnumType::class);
    

Testing

  • BaseDatabaseTestCase: Extend for database-heavy tests.
    use Belsym\CommonBundle\Tests\BaseDatabaseTestCase;
    
    class UserTest extends BaseDatabaseTestCase
    {
        public function testUserCreation()
        {
            $user = new User();
            $this->assertInstanceOf(BaseEntity::class, $user);
        }
    }
    
  • BaseFixtureLoadingTestCase: Load fixtures before tests.
    use Belsym\CommonBundle\Tests\BaseFixtureLoadingTestCase;
    
    class FixtureTest extends BaseFixtureLoadingTestCase
    {
        protected function getFixturesDir()
        {
            return __DIR__ . '/../fixtures';
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Broken State: The package is experimental—validate behavior before production use.
  2. SQLite Enums: BaseLookup is a workaround; test thoroughly in SQLite.
  3. Missing Docs: TODO sections imply incomplete functionality (e.g., BaseUser usage).

Debugging

  • Timestamp Issues: Ensure createdAt/updatedAt are not overridden in child entities.
  • Fixture Loading: Verify getFixturesDir() returns a valid path in test cases.

Extension Points

  1. Custom Fields: Override BaseEntity methods to add default values:
    public function __construct()
    {
        $this->setStatus('draft'); // Default status
    }
    
  2. EnumType: Extend for custom validation:
    class CustomEnumType extends EnumType
    {
        public function convertToDatabaseValue($value, AbstractPlatform $platform)
        {
            // Custom logic
        }
    }
    
  3. Test Isolation: Use setUp() in BaseDatabaseTestCase to reset state:
    public function setUp(): void
    {
        $this->getEntityManager()->getConnection()->beginTransaction();
        parent::setUp();
    }
    
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