tourze/cms-bundle

CMS内容管理系统核心功能包

Installs: 78

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/cms-bundle

0.0.3 2025-06-14 05:54 UTC

This package is auto-updated.

Last update: 2025-10-31 19:53:24 UTC


README

English | 中文

PHP Version License Build Status Coverage

A comprehensive CMS (Content Management System) bundle for Symfony applications, providing content management, category organization, tagging, and statistics features.

Table of Contents

Features

  • Content Management: Entity-Attribute-Value (EAV) based content model
  • Category System: Hierarchical content categorization
  • Tag Management: Flexible tagging system with tag groups
  • Search & Statistics: Content search logs and visit statistics
  • Event System: Content collection, liking, and visit tracking
  • JSON-RPC API: RESTful API endpoints for content operations
  • Admin Interface: EasyAdmin integration for backend management
  • Twig Extensions: Template helpers for CMS functionality

Installation

composer require tourze/cms-bundle

Configuration

Add the bundle to your config/bundles.php:

return [
    // ...
    CmsBundle\CmsBundle::class => ['all' => true],
];

Usage

Basic Entity Structure

The bundle provides 6 core entities:

  • Category: Hierarchical content categorization with tree structure
  • SearchLog: Search history tracking and keyword analytics
  • Tag: Content tagging system with unique tag names
  • TagGroup: Organization and grouping of tags
  • Topic: Content topics/articles with recommendation support
  • VisitStat: Daily visit statistics tracking

Services

ContentService

Search content by keywords in EAV attributes:

use CmsBundle\Service\ContentService;

class YourController
{
    public function __construct(
        private ContentService $contentService
    ) {}
    
    public function searchContent(string $keyword): void
    {
        $queryBuilder = $this->entityManager->createQueryBuilder();
        $this->contentService->searchByKeyword($queryBuilder, $keyword);
    }
}

StatService

Update visit statistics asynchronously:

use CmsBundle\Service\StatService;

class YourController
{
    public function __construct(
        private StatService $statService
    ) {}
    
    public function updateStats(int $entityId): void
    {
        $this->statService->updateStat($entityId);
    }
}

JSON-RPC Procedures

The bundle provides JSON-RPC endpoints for:

Content Operations

  • GetCmsEntityList: Retrieve paginated content lists with category/model filtering
  • GetCmsEntityDetail: Get detailed content information with visit tracking

Category Management

  • GetCmsCategoryList: Fetch category listings by model
  • GetCmsCategoryDetail: Get category details
  • AdminCreateCmsCategory: Create new categories (admin)
  • AdminGetCmsCategoryList: Admin category management
  • AdminGetCmsCategoryTree: Hierarchical category tree structure

Events

The bundle dispatches events for content interactions:

  • CollectEntityEvent: When content is collected/bookmarked
  • LikeEntityEvent: When content is liked
  • VisitEntityEvent: When content is visited

Twig Extensions

Use CMS functionality in templates:

{# Get single entity detail #}
{% set entity = get_cms_entity_detail(123) %}
{{ entity.title }}

{# Get entity list by model #}
{% set entities = get_cms_entity_list('article', 10, 0) %}
{% for entity in entities %}
    <h2>{{ entity.title }}</h2>
{% endfor %}

Database Schema

The bundle creates the following tables:

  • cms_category: Hierarchical content categories with tree structure
  • ims_cms_search: Search history logs with keyword tracking
  • cms_tag: Content tags with unique names
  • cms_tag_group: Tag organization groups
  • cms_topic: Content topics with recommendation support
  • cms_visit_stat: Daily visit statistics

Advanced Usage

Custom Entity Models

Extend the EAV model system for custom content types:

use CmsBundle\Service\EntityService;use CmsBundle\Service\ModelService;

class CustomContentService
{
    public function __construct(
        private ModelService $modelService,
        private EntityService $entityService
    ) {}
    
    public function createCustomEntity(string $modelCode, array $data): Entity
    {
        $model = $this->modelService->findValidModelByCode($modelCode);
        // Create and populate entity...
    }
}

Advanced Search Integration

Implement complex search scenarios using ContentService:

use CmsBundle\Service\ContentService;

$qb = $entityRepository->createQueryBuilder('e');
$this->contentService->searchByKeyword($qb, 'search term', $model);
$results = $qb->getQuery()->getResult();

Cross-Module Integration

When integrating with other modules, always use Service layer instead of direct Repository access:

// ✅ Correct - Use Service layer
$entityService->findEntityBy(['id' => $id]);

// ❌ Wrong - Direct Repository access violates architecture
$entityRepository->findOneBy(['id' => $id]);

Testing

Run the test suite:

./vendor/bin/phpunit packages/cms-bundle/tests

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Doctrine ORM 3.0+

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests.

License

MIT License