tourze / product-comment-bundle
Symfony 商品评论系统,支持评论、回复、点赞功能
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/product-comment-bundle
Requires
- doctrine/collections: ^2.3
- doctrine/data-fixtures: ^2.0
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/doctrine-fixtures-bundle: ^4.0
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- knplabs/knp-paginator-bundle: ^6.5
- psr/log: ^3|^2|^1
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/form: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/routing: ^7.3
- symfony/security-bundle: ^7.3
- symfony/security-core: ^7.3
- symfony/security-http: ^7.3
- symfony/serializer: ^7.3
- symfony/validator: ^7.3
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-ip-bundle: 1.1.*
- tourze/doctrine-resolve-target-entity-bundle: 1.*
- tourze/doctrine-snowflake-bundle: 1.1.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/enum-extra: 1.0.*
- tourze/json-rpc-core: 1.0.*
- tourze/json-rpc-lock-bundle: 1.0.*
- tourze/json-rpc-log-bundle: 1.0.*
- tourze/json-rpc-paginator-bundle: 1.0.*
- tourze/json-rpc-security-bundle: 1.0.*
- tourze/order-core-bundle: 1.0.*
- tourze/product-core-bundle: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
- tourze/tag-manage-bundle: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2025-11-14 07:47:02 UTC
README
A Symfony bundle for managing product comments, including hierarchical comments, ratings, likes, and administrative controls.
Table of Contents
- Quick Start
- Features
- Installation
- Dependencies
- API Endpoints
- Entity Structure
- Advanced Usage
- Security
- Contributing
- License
Quick Start
Register the Bundle
Add the bundle to your config/bundles.php:
<?php return [ // ... ProductCommentBundle\ProductCommentBundle::class => ['all' => true], ];
Configure Database
Run the database migrations to create the necessary tables:
php bin/console doctrine:migrations:migrate
Basic Usage
Submit a Product Comment
<?php use ProductCommentBundle\Procedure\SubmitProductComment; // Through JSON-RPC API $procedure = new SubmitProductComment($orderProductRepository, $productCommentRepository, $requestStack, $security, $entityManager); $procedure->orderProductId = 'order-product-123'; $procedure->content = 'Great product! Highly recommended.'; $procedure->images = ['image1.jpg', 'image2.jpg']; $result = $procedure->execute();
Get Product Comments
<?php use ProductCommentBundle\Procedure\GetProductCommentList; $procedure = new GetProductCommentList($security, $productCommentRepository, $spuService); $procedure->productId = 'product-123'; $procedure->skuId = 'sku-456'; // optional $procedure->rootParentId = '0'; // optional, defaults to '0' for top-level comments $comments = $procedure->execute();
Like a Comment
<?php use ProductCommentBundle\Procedure\LikeProductComment; $procedure = new LikeProductComment($productCommentRepository, $entityManager, $security); $procedure->contentId = 'comment-123'; $result = $procedure->execute();
Configuration
The bundle uses the following configuration structure:
# config/packages/product_comment.yaml product_comment: # Configuration will be added here as needed
Features
- 🔗 Hierarchical comment system with parent-child relationships
- ⭐ Product rating system with numeric scores
- 👍 Like/dislike functionality with tracking
- 🖼️ Support for image and video attachments
- 🔐 User authentication and authorization
- 📱 IP tracking and client identification
- 👨💼 Administrative review and management
- 🎯 JSON-RPC API endpoints for frontend integration
- 🔧 EasyAdmin integration for backend management
Installation
composer require tourze/product-comment-bundle
Dependencies
Required Dependencies
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- EasyAdmin Bundle 4.0 or higher
Internal Dependencies
tourze/bundle-dependency- Bundle dependency managementtourze/doctrine-indexed-bundle- Doctrine indexing utilitiestourze/doctrine-snowflake-bundle- Snowflake ID generationtourze/json-rpc-core- JSON-RPC core functionalitytourze/json-rpc-paginator-bundle- Pagination support
API Endpoints
The bundle provides the following JSON-RPC procedures:
SubmitProductComment- Submit a new product commentGetProductCommentList- Retrieve paginated comment listsLikeProductComment- Like or unlike a comment (requirescontentIdparameter)ReplyProductComment- Reply to an existing comment (requirescontentIdandcontentparameters)
Entity Structure
ProductComment
- Hierarchical structure with parent/child relationships
- Support for ratings, likes, and multimedia content
- User authentication and IP tracking
- Administrative controls and state management
ProductCommentLike
- Tracks user likes/dislikes on comments
- Prevents duplicate likes from same user
CommentLikeLog
- Audit trail for like/unlike actions
- Tracks user actions and timestamps
Advanced Usage
Custom Comment Validation
You can extend the comment validation by implementing custom validators:
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; class CustomCommentValidator { public function validate($value, ExecutionContextInterface $context) { // Your custom validation logic here if (strlen($value) < 10) { $context->buildViolation('Comment must be at least 10 characters long') ->addViolation(); } } }
Event Subscribers
The bundle dispatches events that you can listen to:
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use ProductCommentBundle\Event\CommentCreatedEvent; class CommentSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ CommentCreatedEvent::class => 'onCommentCreated', ]; } public function onCommentCreated(CommentCreatedEvent $event) { // Handle comment creation } }
Custom Admin Controllers
Extend the provided admin controllers for custom functionality:
use ProductCommentBundle\Controller\Admin\ProductCommentCrudController; class CustomProductCommentCrudController extends ProductCommentCrudController { public function configureActions(Actions $actions): Actions { // Your custom actions return parent::configureActions($actions); } }
Security
Authentication
The bundle requires authenticated users for comment operations. Ensure your application has proper authentication configured:
# config/packages/security.yaml security: access_control: - { path: ^/admin/product-comment, roles: ROLE_ADMIN } - { path: ^/api/product-comment, roles: ROLE_USER }
Authorization
User permissions are checked at the procedure level using #[IsGranted] attributes:
- Comment submission requires
IS_AUTHENTICATED_FULLY - Admin operations require
ROLE_ADMIN - Like operations require
IS_AUTHENTICATED_FULLY
Data Validation
All input data is validated using Symfony's validation component:
- Content length validation
- Image format validation
- User ownership verification
- Rate limiting protection
IP Tracking
The bundle tracks IP addresses for security and auditing purposes. This data is used for:
- Preventing abuse
- Audit trails
- Geographic analytics
Contributing
Please see CONTRIBUTING.md for details on how to contribute to this project.
License
The MIT License (MIT). Please see License File for more information.