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

72 lignes
1.4 KiB
PHP
Brut Vue normale Historique

<?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 $params;
/**
* @var ContentType
*/
protected $contentType;
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 setParams(Config $params)
{
$this->params = $params;
}
/**
* @param ContentType $contentType
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
}
protected function convertPage($content)
{
2015-07-31 12:53:22 +02:00
return $this->contentType->convert($content, $this->getFile());
}
protected function generatePage()
{
return $this->convertPage($this->content);
}
public static function fromFile(Content $file, $params, ContentType $contentType)
{
2015-07-16 11:08:16 +02:00
$page = new static($file->getTitle(), $file->getContent());
$page->setFile($file);
$page->setParams($params);
$page->setContentType($contentType);
return $page;
}
}