Builder implements LoggerAwareInterface
The main Cecil builder class. This class is responsible for building the website by processing various steps, managing configuration, and handling content, data, static files, pages, assets, menus, taxonomies, and rendering. It also provides methods for logging, debugging, and managing build metrics. $config = [
'title' => "My website",
'baseurl' => 'https://domain.tld/',
];
Builder::create($config)->build();
Table of Contents
Interfaces
- LoggerAwareInterface
Constants
- OPTIONS = ['drafts' => false, 'dry-run' => false, 'page' => '', 'render-subset' => '']
- Default options for the build process.
- STEPS = ['Cecil\Step\Pages\Load', 'Cecil\Step\Data\Load', 'Cecil\Step\StaticFiles\Load', 'Cecil\Step\Pages\Create', 'Cecil\Step\Pages\Convert', 'Cecil\Step\Taxonomies\Create', 'Cecil\Step\Pages\Generate', 'Cecil\Step\Menus\Create', 'Cecil\Step\StaticFiles\Copy', 'Cecil\Step\Pages\Render', 'Cecil\Step\Pages\Save', 'Cecil\Step\Assets\Save', 'Cecil\Step\Optimize\Html', 'Cecil\Step\Optimize\Css', 'Cecil\Step\Optimize\Js', 'Cecil\Step\Optimize\Images']
- Steps processed by build(), in order.
- VERBOSITY_DEBUG = 2
- VERBOSITY_NORMAL = 0
- VERBOSITY_QUIET = -1
- VERBOSITY_VERBOSE = 1
- VERSION = '8.x-dev'
- VERBOSITY_NORMAL = 0
Properties
- $assets : array<string|int, mixed>
- Assets path collection.
- $buildId : string
- Current build ID.
- $config : Config|array<string|int, mixed>|null
- Configuration object.
- $content : Finder
- Content files collection.
- $data : array<string|int, mixed>
- Data collection.
- $debug : bool
- Debug mode state.
- $generatorManager : GeneratorManager
- Generators manager.
- $logger : LoggerInterface
- Logger instance.
- $menus : array<string|int, mixed>
- Menus collection.
- $metrics : array<string|int, mixed>
- Build metrics.
- $options : array<string|int, mixed>
- Build options.
- $pages : Collection
- Pages collection.
- $renderer : RendererInterface
- Renderer.
- $static : array<string|int, mixed>
- Static files collection.
- $taxonomies : array<string|int, mixed>
- Taxonomies collection.
- $version : string
- Application version.
Methods
- __construct() : mixed
- addAsset() : void
- Add an asset path to assets list.
- build() : self
- Builds a new website.
- create() : self
- Creates a new Builder instance.
- getAssets() : array<string|int, mixed>
- Returns list of assets path.
- getBuildId() : string
- Returns current build ID.
- getBuildOptions() : array<string|int, mixed>
- Returns build options.
- getConfig() : Config
- Returns configuration.
- getData() : array<string|int, mixed>
- Returns data collection.
- getLogger() : LoggerInterface
- Returns the logger instance.
- getMenus() : Collection
- Returns all menus, for a language.
- getMetrics() : array<string|int, mixed>
- Returns metrics array.
- getPages() : Collection|null
- Returns pages collection.
- getPagesFiles() : Finder|null
- Returns pages files.
- getRenderer() : RendererInterface
- Returns Renderer object.
- getStatic() : array<string|int, mixed>
- Returns static files collection.
- getTaxonomies() : Collection|null
- Returns taxonomies collection, for a language.
- getVersion() : string
- Returns application version.
- importThemesConfig() : void
- Import themes configuration.
- isDebug() : bool
- Returns debug mode state.
- setAssets() : void
- Set assets path list.
- setConfig() : self
- Set configuration.
- setData() : void
- Set collected data.
- setDestinationDir() : self
- Config::setDestinationDir() alias.
- setLogger() : void
- {@inheritdoc}
- setMenus() : void
- Set menus collection.
- setPages() : void
- Set/update Pages collection.
- setPagesFiles() : void
- Set collected pages files.
- setRenderer() : void
- Set renderer object.
- setSourceDir() : self
- Config::setSourceDir() alias.
- setStatic() : void
- Set collected static files.
- setTaxonomies() : void
- Set taxonomies collection.
- checkErrors() : void
- Log soft errors.
Constants
OPTIONS
Default options for the build process.
public
array<string, bool|string>
OPTIONS
= ['drafts' => false, 'dry-run' => false, 'page' => '', 'render-subset' => '']
These options can be overridden when calling the build() method.
- 'drafts': if true, builds drafts too (default: false)
- 'dry-run': if true, generated files are not saved (default: false)
- 'page': if specified, only this page is processed (default: '')
- 'render-subset': limits the render step to a specific subset (default: '')
Tags
STEPS
Steps processed by build(), in order.
public
array<string|int, string>
STEPS
= ['Cecil\Step\Pages\Load', 'Cecil\Step\Data\Load', 'Cecil\Step\StaticFiles\Load', 'Cecil\Step\Pages\Create', 'Cecil\Step\Pages\Convert', 'Cecil\Step\Taxonomies\Create', 'Cecil\Step\Pages\Generate', 'Cecil\Step\Menus\Create', 'Cecil\Step\StaticFiles\Copy', 'Cecil\Step\Pages\Render', 'Cecil\Step\Pages\Save', 'Cecil\Step\Assets\Save', 'Cecil\Step\Optimize\Html', 'Cecil\Step\Optimize\Css', 'Cecil\Step\Optimize\Js', 'Cecil\Step\Optimize\Images']
These steps are executed sequentially to build the website. Each step is a class that implements the StepInterface.
Tags
VERBOSITY_DEBUG
public
mixed
VERBOSITY_DEBUG
= 2
VERBOSITY_NORMAL
public
mixed
VERBOSITY_NORMAL
= 0
VERBOSITY_QUIET
public
mixed
VERBOSITY_QUIET
= -1
VERBOSITY_VERBOSE
public
mixed
VERBOSITY_VERBOSE
= 1
VERSION
public
mixed
VERSION
= '8.x-dev'
Properties
$assets
Assets path collection.
protected
array<string|int, mixed>
$assets
= []
This is an array that holds paths to assets (like CSS, JS, images) that are used in the build process. It is used to keep track of assets that need to be processed or copied. It can be set to an array of paths or updated with new asset paths.
$buildId
Current build ID.
protected
string
$buildId
This is a unique identifier for the current build process. It is generated based on the current date and time when the build starts. It can be used to track builds, especially in environments where multiple builds may occur.
Tags
$config
Configuration object.
protected
Config|array<string|int, mixed>|null
$config
This object holds all the configuration settings for the build process. It can be set to an array or a Config instance.
Tags
$content
Content files collection.
protected
Finder
$content
This is a Finder instance that collects all the content files (pages, posts, etc.) from the source directory.
$data
Data collection.
protected
array<string|int, mixed>
$data
= []
This is an associative array that holds data loaded from YAML files in the data directory.
$debug
Debug mode state.
protected
bool
$debug
= false
If true, debug messages are logged.
$generatorManager
Generators manager.
protected
GeneratorManager
$generatorManager
This is an instance of GeneratorManager that manages all the generators used in the build process. Generators are used to create dynamic content or perform specific tasks during the build. It allows for the registration and execution of various generators that can extend the functionality of the build process.
$logger
Logger instance.
protected
LoggerInterface
$logger
This logger is used to log messages during the build process. It can be set to any PSR-3 compliant logger.
Tags
$menus
Menus collection.
protected
array<string|int, mixed>
$menus
This is an associative array that holds menus for different languages. Each key is a language code, and the value is a Collection\Menu\Collection instance that contains the menu items for that language. It is used to manage navigation menus across different languages in the website.
Tags
$metrics
Build metrics.
protected
array<string|int, mixed>
$metrics
= []
This array holds metrics about the build process, such as duration and memory usage for each step. It is used to track the performance of the build and can be useful for debugging and optimization.
$options
Build options.
protected
array<string|int, mixed>
$options
= []
These options can be passed to the build() method to customize the build process.
Tags
$pages
Pages collection.
protected
Collection
$pages
This is a collection of pages that have been processed and are ready for rendering. It is an instance of PagesCollection, which is a custom collection class for managing pages.
$renderer
Renderer.
protected
RendererInterface
$renderer
This is an instance of Renderer\RendererInterface that is responsible for rendering pages. It handles the rendering of templates and the application of data to those templates.
$static
Static files collection.
protected
array<string|int, mixed>
$static
= []
This is an associative array that holds static files (like images, CSS, JS) that are copied to the destination directory.
$taxonomies
Taxonomies collection.
protected
array<string|int, mixed>
$taxonomies
This is an associative array that holds taxonomies for different languages. Each key is a language code, and the value is a Collection\Taxonomy\Collection instance that contains the taxonomy terms for that language. It is used to manage taxonomies (like categories, tags) across different languages in the website.
Tags
$version
Application version.
protected
static string
$version
Methods
__construct()
public
__construct([Config|array<string|int, mixed>|null $config = null ][, LoggerInterface|null $logger = null ]) : mixed
Parameters
- $config : Config|array<string|int, mixed>|null = null
- $logger : LoggerInterface|null = null
addAsset()
Add an asset path to assets list.
public
addAsset(string $path) : void
Parameters
- $path : string
build()
Builds a new website.
public
build(array<string|int, self::OPTIONS> $options) : self
This method processes the build steps in order, collects content, data, static files, generates pages, renders them, and saves the output to the destination directory. It also collects metrics about the build process, such as duration and memory usage.
Parameters
- $options : array<string|int, self::OPTIONS>
Tags
Return values
selfcreate()
Creates a new Builder instance.
public
static create() : self
Return values
selfgetAssets()
Returns list of assets path.
public
getAssets() : array<string|int, mixed>
Return values
array<string|int, mixed>getBuildId()
Returns current build ID.
public
getBuildId() : string
Return values
stringgetBuildOptions()
Returns build options.
public
getBuildOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getConfig()
Returns configuration.
public
getConfig() : Config
Return values
ConfiggetData()
Returns data collection.
public
getData([string|null $language = null ]) : array<string|int, mixed>
Parameters
- $language : string|null = null
Return values
array<string|int, mixed>getLogger()
Returns the logger instance.
public
getLogger() : LoggerInterface
Return values
LoggerInterfacegetMenus()
Returns all menus, for a language.
public
getMenus(string $language) : Collection
Parameters
- $language : string
Return values
CollectiongetMetrics()
Returns metrics array.
public
getMetrics() : array<string|int, mixed>
Return values
array<string|int, mixed>getPages()
Returns pages collection.
public
getPages() : Collection|null
Return values
Collection|nullgetPagesFiles()
Returns pages files.
public
getPagesFiles() : Finder|null
Return values
Finder|nullgetRenderer()
Returns Renderer object.
public
getRenderer() : RendererInterface
Return values
RendererInterfacegetStatic()
Returns static files collection.
public
getStatic() : array<string|int, mixed>
Return values
array<string|int, mixed>getTaxonomies()
Returns taxonomies collection, for a language.
public
getTaxonomies(string $language) : Collection|null
Parameters
- $language : string
Return values
Collection|nullgetVersion()
Returns application version.
public
static getVersion() : string
Tags
Return values
stringimportThemesConfig()
Import themes configuration.
public
importThemesConfig() : void
isDebug()
Returns debug mode state.
public
isDebug() : bool
Return values
boolsetAssets()
Set assets path list.
public
setAssets(array<string|int, mixed> $assets) : void
Parameters
- $assets : array<string|int, mixed>
setConfig()
Set configuration.
public
setConfig(array<string|int, mixed>|Config $config) : self
Parameters
- $config : array<string|int, mixed>|Config
Return values
selfsetData()
Set collected data.
public
setData(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
setDestinationDir()
Config::setDestinationDir() alias.
public
setDestinationDir(string $destinationDir) : self
Parameters
- $destinationDir : string
Return values
selfsetLogger()
{@inheritdoc}
public
setLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
setMenus()
Set menus collection.
public
setMenus(array<string|int, mixed> $menus) : void
Parameters
- $menus : array<string|int, mixed>
setPages()
Set/update Pages collection.
public
setPages(Collection $pages) : void
Parameters
- $pages : Collection
setPagesFiles()
Set collected pages files.
public
setPagesFiles(Finder $content) : void
Parameters
- $content : Finder
setRenderer()
Set renderer object.
public
setRenderer(RendererInterface $renderer) : void
Parameters
- $renderer : RendererInterface
setSourceDir()
Config::setSourceDir() alias.
public
setSourceDir(string $sourceDir) : self
Parameters
- $sourceDir : string
Return values
selfsetStatic()
Set collected static files.
public
setStatic(array<string|int, mixed> $static) : void
Parameters
- $static : array<string|int, mixed>
setTaxonomies()
Set taxonomies collection.
public
setTaxonomies(array<string|int, mixed> $taxonomies) : void
Parameters
- $taxonomies : array<string|int, mixed>
checkErrors()
Log soft errors.
protected
checkErrors() : void