edumedia/tag-bundle

安装数: 4,270

依赖项: 0

建议者: 0

安全: 0

星标: 3

关注者: 2

分支: 1

公开问题: 0

类型:symfony-bundle

0.1.19 2024-09-24 08:44 UTC

This package is auto-updated.

Last update: 2024-09-24 08:46:19 UTC


README

理由

为 Symfony 6+ 和 PHP 8+ 复兴 https://github.com/FabienPennequin/FPNTagBundle

注意:fpn/tag-bundle 的主要区别在于,可标记的实体不保留它们的标签,它们仅通过 TagService 可用。

如何使用

安装包

composer require edumedia/tag-bundle

创建标签类

<?php
// src/Entity/Tag.php

namespace App\Entity;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use eduMedia\TagBundle\Entity\TagInterface;
use eduMedia\TagBundle\Entity\TagTrait;

#[ORM\Entity]
#[ORM\Table(name: 'tag')]
class Tag implements TagInterface
{

    use TagTrait;

    #[ORM\OneToMany(mappedBy: 'tag', targetEntity: 'App\Entity\Tagging', fetch: 'EAGER')]
    protected ?Collection $tagging = null;

}

创建标签化类

<?php
// src/Entity/Tagging.php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use eduMedia\TagBundle\Entity\TaggingInterface;
use eduMedia\TagBundle\Entity\TaggingTrait;
use eduMedia\TagBundle\Entity\TagInterface;

#[ORM\Entity]
#[ORM\Table(name: 'tagging')]
class Tagging implements TaggingInterface
{

    use TaggingTrait;

    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: 'App\Entity\Tag', inversedBy: 'tagging')]
    protected TagInterface $tag;

}

使实体可标记

以下是一个用户示例

<?php
// src/Entity/User

namespace App\Entity;

use eduMedia\TagBundle\Entity\TaggableInterface;
use eduMedia\TagBundle\Entity\TaggableTrait;

class User implements /* (...) */ TaggableInterface
{

    use TaggableTrait;
    
    // (...)
}

定义服务参数

# config/services.yaml
services:
  # (...)
  eduMedia\TagBundle\Service\TagService:
    arguments:
      - 'App\Entity\Tag'
      - 'App\Entity\Tagging'

迁移,以创建表

bin/console make:migration
bin/console doctrine:migrations:migrate

安装资产

bin/console assets:install

功能

  • 大多数功能都打包在 eduMedia\TagBundle\Service\TagService 中(尚未文档化,但应具有自解释性)
  • 如果已安装 symfony/console,则可用 edumedia:tag:create 命令
  • 如果已安装 symfony/twig-bundle,则 tag_service 在全局范围内可用
  • 如果已安装 symfony/form,则可用 eduMedia\TagBundle\Form\Type\TagType
  • 如果使用 easycorp/easyadmin-bundle,则可用 eduMedia\TagBundle\Admin\Field\TagField

待办事项

  • 自动测试(需要帮助)