positibe / 内容感知
PositibeLabs 项目的内容感知实体库
0.1.1.0
2017-04-05 19:51 UTC
This package is not auto-updated.
Last update: 2024-09-29 02:50:28 UTC
README
这个库为你提供了一些特性,可以在 doctrine 实体中使用,这些实体实现了一些具有内容的系统,但没有与它们相关联。还提供了一些接口,用于仓库以创建内容感知的通用管理。
ContentClassAwareTrait
[php]
namespace Positibe\Component\ContentAware\Entity;
trait ContentClassAwareTrait {
/**
* @var string
*
* @ORM\Column(name="content_class", type="string", length=128, nullable=TRUE)
*/
protected $contentClass;
public function setContentClassByContent($content)
{
$this->contentClass = get_class($content);
}
/**
* @return string
*/
public function getContentClass()
{
return $this->contentClass;
}
/**
* @param string $contentClass
*/
public function setContentClass($contentClass)
{
$this->contentClass = $contentClass;
}
}
ContentAwareTrait
[php]
namespace Positibe\Component\ContentAware\Entity;
trait ContentAwareTrait
{
protected $content;
use ContentClassAwareTrait;
public function setContent($content)
{
$this->content = $content;
$this->setContentClassByContent($content);
}
public function getContent()
{
return $this->content;
}
}
ContentAwareInterface
此接口仅用于知道仓库是否为 ContentAware 实体
[php]
namespace Positibe\Component\ContentAware\Model;
interface ContentAwareInterface
{
}
ContentAwareRepositoryInterface
[php]
namespace Positibe\Component\ContentAware\Model;
interface ContentAwareRepositoryInterface
{
public function findContent($object);
}
使用 PHP 特性
这些是简单的 PHP 特性,所以你可以这样使用。
[php]
namespace Blog\Entity;
use Doctrine\ORM\Mapping as ORM;
use Positibe\Component\ContentAware\Entity\ContentClassAwareTrait;
use Positibe\Component\ContentAware\Model\ContentAwareInterface;
/**
* @ORM\Table()
* @ORM\Entity
*/
class Tags implements ContentAwareInterface
{
use ContentClassAwareTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}