I have the following scenario:
There is a base class called a Document and two subclasses called FileDocument and TextDocument.
FileDocument class has properties fileName, fileType and blob. TextDocument class has properties content and can have an object of FileDocument class.
The implementation will be as following:
class Document{
/**
* @ORMId
* @ORMGeneratedValue(strategy="NONE")
* @ORMColumn(name="id", type="guid")
*/
private string $id;
/**
* @ORMColumn(name="type", type="string", length=20)
*/
private string $type;
/**
* @ORMColumn(name="authorName", type="string", length=20)
*/
private string $authorName
getters and settere are here
-----
-----
-----
}
class FileDocument extends Document {
/**
* @ORMColumn(name="fileName", type="string", length=20)
*/
private string $fileName;
/**
* @ORMColumn(name="fileType", type="string", length=20)
*/
private string $fileType;
/**
* @ORMColumn(name="file", type="blob", length=20)
*/
private string $file;
public function getFileName(): string
{
return $this->fileName;
}
public function setFileName(string $fileName): void
{
$this->fileName = $fileName;
}
public function getContentType(): string
{
return $this->contentType;
}
public function setContentType(string $contentType): void
{
$this->contentType = $contentType;
}
-----
-----
-----
}
class TextDocument extends Document {
/**
* @ORMColumn(name="file", type="text", length=20)
*/
private string $content;
/**
* @ORMOneToOne(targetEntity=FileDocument::class)
*/
private FileDocument $file;
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content): void
{
$this->content = $content;
}
public function getFileDocmuent(): FileDocmuent
{
return $this->fileDocmuent;
}
public function setFileDocmuent(FileDocmuent $fileDocmuent): void
{
$this->fileDocmuent = $fileDocmuent;
}
-----
-----
-----
}
Would this be possible in PHP to use subclass FileDocument in another sub class TextDocument, for example?