Tool for laying out displays on Linux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

119 lines
2.1 KiB

<?php
declare(strict_types=1);
namespace App;
use Symfony\Component\Yaml\Yaml;
/**
* Represent the configuration containing screens and layouts
*
* @author Adam Pippin <hello@adampippin.ca>
*/
class Configuration
{
/**
* Represents the available screens and their configuration
* @var array<string, Screen>
*/
protected $_screens;
/**
* Represents the available layouts
* @var array<string, Layout>
*/
protected $_layouts;
/**
* Initialize an empty config
*/
public function __construct()
{
$this->_screens = [];
$this->_layouts = [];
}
/**
* Load a configuration from a YAML file
*
* @param string $file
* @return void
*/
public function load(string $file): void
{
$config = Yaml::parseFile($file);
foreach ($config['screens'] as $screen_name => $screen)
{
$this->_screens[$screen_name] = app()->make(\App\Screen::class, [
'outputs' => is_array($screen['output']) ? $screen['output'] : [$screen['output']]
]);
}
foreach ($config['layouts'] as $layout => $data)
{
$this->_layouts[$layout] = app()->make(\App\Layout::class, ['screens' => $data['screens'], 'links' => $data['links']]);
}
}
/**
* Fetch a specific screen
*
* @param string $screen_name
* @return Screen
*/
public function getScreen(string $screen_name): Screen
{
return $this->_screens[$screen_name];
}
/**
* Fetch the primary screen
*
* @return Screen
*/
public function getPrimaryScreen(): Screen
{
return $this->getScreen($this->getPrimaryScreenName());
}
/**
* Fetch the name of the primary screen
*
* @return string
*/
public function getPrimaryScreenName(): string
{
foreach ($this->_screens as $name => $screen)
{
if ($screen->isPrimary())
{
return $name;
}
}
throw new \Exception("No primary screen found");
}
/**
* Fetch a specific layout
*
* @param string $layout
* @return Layout
*/
public function getLayout(string $layout): Layout
{
return $this->_layouts[$layout];
}
/**
* Fetch all the layouts
*
* @return array<string, Layout>
*/
public function getLayouts(): array
{
return $this->_layouts;
}
}