2015-05-18 14:26:29 +02:00
|
|
|
<?php namespace Todaymade\Daux\Format\Base;
|
|
|
|
|
2015-06-29 16:11:01 +02:00
|
|
|
use Todaymade\Daux\Config;
|
2015-07-29 22:31:41 +02:00
|
|
|
use Todaymade\Daux\ContentTypes\ContentType;
|
2015-05-18 14:26:29 +02:00
|
|
|
use Todaymade\Daux\Tree\Content;
|
|
|
|
|
2015-07-28 17:25:03 +02:00
|
|
|
abstract class ContentPage extends SimplePage
|
2015-05-18 14:26:29 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Content
|
|
|
|
*/
|
|
|
|
protected $file;
|
|
|
|
|
|
|
|
/**
|
2015-06-29 16:11:01 +02:00
|
|
|
* @var Config
|
2015-05-18 14:26:29 +02:00
|
|
|
*/
|
|
|
|
protected $params;
|
|
|
|
|
2015-07-19 01:05:43 +02:00
|
|
|
/**
|
2015-07-28 17:25:03 +02:00
|
|
|
* @var ContentType
|
2015-07-19 01:05:43 +02:00
|
|
|
*/
|
2015-07-28 17:25:03 +02:00
|
|
|
protected $contentType;
|
2015-07-19 01:05:43 +02:00
|
|
|
|
2016-03-13 21:51:15 +01:00
|
|
|
protected $generatedContent;
|
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-06-29 16:11:01 +02:00
|
|
|
public function setParams(Config $params)
|
2015-05-18 14:26:29 +02:00
|
|
|
{
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2015-07-28 17:25:03 +02:00
|
|
|
/**
|
|
|
|
* @param ContentType $contentType
|
|
|
|
*/
|
|
|
|
public function setContentType($contentType)
|
2015-05-22 14:48:09 +02:00
|
|
|
{
|
2015-07-28 17:25:03 +02:00
|
|
|
$this->contentType = $contentType;
|
2015-05-22 14:48:09 +02:00
|
|
|
}
|
|
|
|
|
2016-03-13 21:51:15 +01:00
|
|
|
public function getPureContent()
|
2015-05-22 14:48:09 +02:00
|
|
|
{
|
2016-03-13 21:51:15 +01:00
|
|
|
if (!$this->generatedContent) {
|
|
|
|
$this->generatedContent = $this->contentType->convert($this->content, $this->getFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->generatedContent;
|
2015-05-22 14:48:09 +02:00
|
|
|
}
|
|
|
|
|
2015-05-18 14:26:29 +02:00
|
|
|
protected function generatePage()
|
|
|
|
{
|
2016-03-13 21:51:15 +01:00
|
|
|
return $this->getPureContent();
|
2015-05-18 14:26:29 +02:00
|
|
|
}
|
|
|
|
|
2015-07-28 17:25:03 +02:00
|
|
|
public static function fromFile(Content $file, $params, ContentType $contentType)
|
2015-05-18 14:26:29 +02:00
|
|
|
{
|
2015-07-16 11:08:16 +02:00
|
|
|
$page = new static($file->getTitle(), $file->getContent());
|
2015-05-18 14:26:29 +02:00
|
|
|
$page->setFile($file);
|
|
|
|
$page->setParams($params);
|
2015-07-28 17:25:03 +02:00
|
|
|
$page->setContentType($contentType);
|
2015-05-18 14:26:29 +02:00
|
|
|
|
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
}
|