zend-blog-3-backend
163 строки · 3.0 Кб
1<?php
2
3namespace App\Entity;
4
5use App\Entity\Traits\ModifyEntityTrait;
6use Doctrine\ORM\Mapping as ORM;
7
8/**
9* @ORM\Table()
10* @ORM\Entity(repositoryClass="App\Repository\PygmentsCodeRepository")
11* @ORM\HasLifecycleCallbacks()
12*/
13class PygmentsCode
14{
15use ModifyEntityTrait;
16
17/**
18* @var int
19*
20* @ORM\Id
21* @ORM\Column(type="integer")
22* @ORM\GeneratedValue(strategy="AUTO")
23*/
24private $id;
25
26/**
27* @var PygmentsLanguage
28*
29* @ORM\ManyToOne(targetEntity="PygmentsLanguage")
30* @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
31*/
32private $language;
33
34/**
35* @var string
36*
37* @ORM\Column(type="text", length=65535)
38*/
39private $sourceCode = '';
40
41/**
42* @var string|null
43*
44* @ORM\Column(type="text", length=65535, nullable=true)
45*/
46private $sourceHtml;
47
48/**
49* @var string|null
50*
51* @ORM\Column(type="text", length=65535, nullable=true)
52*/
53private $sourceHtmlPreview;
54
55/**
56* @return int
57*/
58public function getId()
59{
60return $this->id;
61}
62
63/**
64* @return string
65*/
66public function getLexer(): string
67{
68$result = 'text';
69if ($this->language) {
70$result = $this->language->getLexer();
71}
72
73return $result;
74}
75
76/**
77* @return string
78*/
79public function getContentHash(): string
80{
81return sha1($this->getSourceCode() . ':' . $this->getLexer());
82}
83
84/**
85* @return PygmentsLanguage|null
86*/
87public function getLanguage(): ?PygmentsLanguage
88{
89return $this->language;
90}
91
92/**
93* @param PygmentsLanguage|null $language
94*
95* @return PygmentsCode
96*/
97public function setLanguage(PygmentsLanguage $language = null): self
98{
99$this->language = $language;
100
101return $this;
102}
103
104/**
105* @return string|null
106*/
107public function getSourceCode(): ?string
108{
109return $this->sourceCode;
110}
111
112/**
113* @param mixed $sourceCode
114*
115* @return PygmentsCode
116*/
117public function setSourceCode($sourceCode): self
118{
119$this->sourceCode = $sourceCode;
120
121return $this;
122}
123
124/**
125* @return string|null
126*/
127public function getSourceHtml(): ?string
128{
129return $this->sourceHtml;
130}
131
132/**
133* @param string $sourceHtml
134*
135* @return PygmentsCode
136*/
137public function setSourceHtml(string $sourceHtml): self
138{
139$this->sourceHtml = $sourceHtml;
140
141return $this;
142}
143
144/**
145* @return string|null
146*/
147public function getSourceHtmlPreview(): ?string
148{
149return $this->sourceHtmlPreview;
150}
151
152/**
153* @param string|null $sourceHtmlPreview
154*
155* @return PygmentsCode
156*/
157public function setSourceHtmlPreview(string $sourceHtmlPreview = null): PygmentsCode
158{
159$this->sourceHtmlPreview = $sourceHtmlPreview;
160
161return $this;
162}
163}
164