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

Symfony Blog Admin Bundle Mynosql Based Laravel Package

dovstone/symfony-blog-admin-bundle-mynosql-based

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your Symfony project via Composer:

    composer require dovstone/symfony-blog-admin-bundle-mynosql-based
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        Dovstone\BlogAdminBundle\DovstoneBlogAdminBundle::class => ['all' => true],
    ];
    
  2. Database Configuration Configure MyNoSQL in .env (adjust per your NoSQL provider, e.g., MongoDB, CouchDB):

    MYNOSQL_DSN=mongodb://localhost:27017
    MYNOSQL_DATABASE=blog_db
    
  3. First Use Case: Create a Post Use the provided CLI command to scaffold a blog post:

    php bin/console dovstone:blog:post:create --title="First Post" --content="Hello World!"
    

    Verify the post in your NoSQL database (e.g., via MongoDB Compass or php bin/console dovstone:blog:post:list).


Where to Look First

  • Bundle Docs: Check src/Resources/doc/index.md for high-level usage.
  • Commands: Run php bin/console list dovstone to explore available CLI tools.
  • Controllers: Inspect src/Controller/ for RESTful endpoints (e.g., PostController).
  • Entities: Review src/Entity/ for NoSQL document structures (e.g., Post.php).

Implementation Patterns

Workflows

  1. CRUD Operations via CLI

    • Create: dovstone:blog:post:create
    • Read: dovstone:blog:post:list or dovstone:blog:post:show <id>
    • Update: dovstone:blog:post:edit <id> --title="New Title"
    • Delete: dovstone:blog:post:delete <id> Tip: Use --force for destructive actions (e.g., delete).
  2. RESTful API Integration The bundle exposes endpoints under /api/blog:

    • GET /api/blog/posts → List posts (paginated).
    • POST /api/blog/posts → Create a post (JSON payload).
    • GET /api/blog/posts/{id} → Show a post. Example Payload:
      {
          "title": "API Post",
          "content": "Created via API",
          "tags": ["api", "symfony"]
      }
      
  3. Event-Driven Extensions Listen to bundle events (e.g., PostCreatedEvent) in your EventSubscriber:

    use Dovstone\BlogAdminBundle\Event\PostCreatedEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class MySubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                PostCreatedEvent::class => 'onPostCreated',
            ];
        }
    
        public function onPostCreated(PostCreatedEvent $event)
        {
            // Send notification, log analytics, etc.
        }
    }
    
  4. Twig Integration Embed posts in templates using the blog_post Twig function:

    {% for post in blog_post.list() %}
        <h2>{{ post.title }}</h2>
        <p>{{ post.content|truncate(100) }}</p>
    {% endfor %}
    

Integration Tips

  • Custom Fields: Extend the Post entity by overriding src/Entity/Post.php and updating the NoSQL schema.
  • Authentication: Secure API endpoints with Symfony’s security component:
    # config/packages/security.yaml
    access_control:
        - { path: ^/api/blog, roles: ROLE_USER }
    
  • Testing: Use the Test\BlogAdminBundleTest class as a base for functional tests:
    use Dovstone\BlogAdminBundle\Test\BlogAdminBundleTest;
    
    class MyBlogTest extends BlogAdminBundleTest
    {
        public function testPostCreation()
        {
            $this->createPost(['title' => 'Test']);
            $this->assertDatabaseHas('posts', ['title' => 'Test']);
        }
    }
    

Gotchas and Tips

Pitfalls

  1. NoSQL Schema Mismatches

    • Issue: Custom fields in Post entity may not map to the NoSQL schema.
    • Fix: Ensure your entity uses #[MyNoSQL\Annotation\Document] and #[MyNoSQL\Annotation\Field] annotations. Example:
      #[MyNoSQL\Annotation\Document(collection: "posts")]
      class Post
      {
          #[MyNoSQL\Annotation\Field(type: "string")]
          private string $title;
      }
      
  2. CLI Command Conflicts

    • Issue: Namespace collisions with other bundles’ commands.
    • Fix: Prefix commands or override them in config/packages/dovstone_blog_admin.yaml:
      dovstone_blog_admin:
          commands:
              create_post: 'app:blog:post:create' # Custom namespace
      
  3. Pagination Limits

    • Issue: Default pagination (e.g., 10 items/page) may be too restrictive.
    • Fix: Override the PostRepository to adjust limits:
      class CustomPostRepository extends PostRepository
      {
          public function findAllWithPagination(int $page = 1, int $limit = 50)
          {
              return $this->createQueryBuilder()
                  ->skip(($page - 1) * $limit)
                  ->limit($limit)
                  ->getQuery()
                  ->execute();
          }
      }
      
  4. Event Dispatching

    • Issue: Events may not trigger if the bundle isn’t properly registered.
    • Fix: Verify the EventDispatcher is autowired in your subscriber and the event class is fully qualified:
      use Dovstone\BlogAdminBundle\Event\PostCreatedEvent; // Correct namespace
      

Debugging Tips

  1. Enable Debug Mode Set APP_DEBUG=1 in .env to see detailed errors and SQL/NoSQL queries.

  2. Log NoSQL Queries Configure Monolog to log MyNoSQL queries:

    # config/packages/monolog.yaml
    handlers:
        mynosql:
            type: stream
            path: "%kernel.logs_dir%/mynosql.log"
            level: debug
            channels: ["mynosql"]
    
  3. Validate Entities Use Symfony’s validator to catch entity issues early:

    php bin/console debug:validator Dovstone\BlogAdminBundle\Entity\Post
    

Extension Points

  1. Custom Actions Add new CLI commands by extending the Command base class:

    namespace App\Command;
    
    use Dovstone\BlogAdminBundle\Command\AbstractBlogCommand;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class ExportPostsCommand extends AbstractBlogCommand
    {
        protected function configure()
        {
            $this->setName('app:blog:export');
        }
    
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            // Custom logic (e.g., export to CSV)
        }
    }
    
  2. Override Templates Customize Twig templates by copying files from vendor/dovstone/symfony-blog-admin-bundle-mynosql-based/templates/ to templates/bundles/dovstoneblogadmin/.

  3. Add Middleware Inject middleware for API requests (e.g., rate limiting):

    # config/packages/api_platform.yaml
    api_platform:
        formats:
            jsonld:
                mime_types: ['application/ld+json']
        patch_formats:
            json: ['application/merge-patch+json']
        swagger:
            versions: [3]
    
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.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php