daux.io/libs/Format/Base/ContentPage.php

86 lines
1.7 KiB
PHP
Raw Normal View History

<?php namespace Todaymade\Daux\Format\Base;
use Todaymade\Daux\Config;
2015-07-29 22:31:41 +02:00
use Todaymade\Daux\ContentTypes\ContentType;
use Todaymade\Daux\Tree\Content;
abstract class ContentPage extends SimplePage
{
/**
* @var Content
*/
protected $file;
/**
* @var Config
*/
protected $config;
/**
* @var ContentType
*/
protected $contentType;
protected $generatedContent;
public function __construct($title, $content)
{
$this->initializePage($title, $content);
}
public function setFile(Content $file)
{
$this->file = $file;
}
2015-06-29 16:16:39 +02:00
public function getFile()
{
return $this->file;
}
public function setConfig(Config $config)
{
$this->config = $config;
}
/**
* @deprecated use setConfig instead
*/
public function setParams(Config $config)
{
$this->setConfig($config);
}
/**
* @param ContentType $contentType
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
}
public function getPureContent()
{
if (!$this->generatedContent) {
$this->generatedContent = $this->contentType->convert($this->content, $this->getFile());
}
return $this->generatedContent;
}
protected function generatePage()
{
return $this->getPureContent();
}
public static function fromFile(Content $file, $config, ContentType $contentType)
{
2015-07-16 11:08:16 +02:00
$page = new static($file->getTitle(), $file->getContent());
$page->setFile($file);
$page->setConfig($config);
$page->setContentType($contentType);
return $page;
}
}