定制 tourze/user-follow-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/user-follow-bundle

最新稳定版本:0.0.1

Composer 安装命令:

composer require tourze/user-follow-bundle

包简介

Symfony bundle for user follow/follower relationship management with event handling and EasyAdmin integration

README 文档

README

English | 中文

A Symfony bundle that provides user follow/follower relationship management functionality with comprehensive event handling and EasyAdmin integration.

Features

  • User Follow System: Follow/unfollow users with status management
  • Follow Statistics: Get followers count and following count
  • Event System: Dispatch events when users follow/unfollow others
  • EasyAdmin Integration: Built-in admin interface for managing follow relationships
  • Doctrine Integration: Full database persistence with indexing
  • Blameable & Timestampable: Track who created the relationship and when

Installation

composer require tourze/user-follow-bundle

Configuration

Add the bundle to your bundles.php:

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

Basic Usage

Using the Follow Service

<?php

use Tourze\UserFollowBundle\Service\FollowService;
use Symfony\Component\Security\Core\User\UserInterface;

class UserService
{
    public function __construct(
        private FollowService $followService,
    ) {}

    public function checkFollowStatus(UserInterface $currentUser, UserInterface $targetUser): bool
    {
        return $this->followService->isFollowing($currentUser, $targetUser);
    }

    public function getUserStats(UserInterface $user): array
    {
        return [
            'followers' => $this->followService->getFansCount($user),
            'following' => $this->followService->getFollowCount($user),
        ];
    }
}

Creating Follow Relations

<?php

use Tourze\UserFollowBundle\Entity\FollowRelation;
use Doctrine\ORM\EntityManagerInterface;

class FollowManager
{
    public function __construct(
        private EntityManagerInterface $em,
    ) {}

    public function followUser(UserInterface $follower, UserInterface $followed): void
    {
        $relation = new FollowRelation();
        $relation->setUser($follower);
        $relation->setFollowUser($followed);
        $relation->setStatus(true);

        $this->em->persist($relation);
        $this->em->flush();
    }

    public function unfollowUser(UserInterface $follower, UserInterface $followed): void
    {
        $relation = $this->em->getRepository(FollowRelation::class)
            ->findOneBy([
                'user' => $follower,
                'followUser' => $followed,
                'status' => true,
            ]);

        if ($relation) {
            $relation->setStatus(false);
            $this->em->flush();
        }
    }
}

Event Handling

Listen to follow events:

<?php

use Tourze\UserFollowBundle\Event\AfterFollowUser;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

class FollowNotificationListener
{
    #[AsEventListener(event: AfterFollowUser::class)]
    public function onAfterFollowUser(AfterFollowUser $event): void
    {
        $follower = $event->getFollower();
        $followedUser = $event->getFollowedUser();

        // Send notification, update statistics, etc.
        // ...
    }
}

Database Schema

The bundle creates a forum_follow_relation table with the following structure:

  • id: Snowflake ID (primary key)
  • user_id: ID of the follower (foreign key)
  • follow_user_id: ID of the followed user (foreign key)
  • status: Boolean status (true = following, false = unfollowed)
  • created_at: Timestamp when relation was created
  • updated_at: Timestamp when relation was last updated
  • created_by: User who created the relation

EasyAdmin Integration

The bundle automatically registers admin controllers for managing follow relationships in the EasyAdmin backend.

API Reference

FollowService

  • isFollowing(UserInterface $follower, UserInterface $followedUser): bool

    • Check if a user is following another user
  • getFansCount(UserInterface $user): int

    • Get the number of followers for a user
  • getFollowCount(UserInterface $user): int

    • Get the number of users that a user is following

FollowRelation Entity

  • getUser(): ?UserInterface

    • Get the follower
  • setUser(?UserInterface $user): void

    • Set the follower
  • getFollowUser(): ?UserInterface

    • Get the followed user
  • setFollowUser(?UserInterface $followUser): void

    • Set the followed user
  • getStatus(): ?bool

    • Get the follow status
  • setStatus(?bool $status): void

    • Set the follow status

Events

  • AfterFollowUser: Dispatched after a user follows another user
    • getFollower(): Returns the user who initiated the follow
    • getFollowedUser(): Returns the user who was followed

Dependencies

  • Symfony 7.3+
  • Doctrine ORM 3.0+
  • EasyAdmin Bundle 4.0+
  • Tourze Doctrine User Bundle
  • Tourze Doctrine Snowflake Bundle
  • Tourze Doctrine Timestamp Bundle

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

tourze/user-follow-bundle 适用场景与选型建议

tourze/user-follow-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/user-follow-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/user-follow-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/user-follow-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-14