mirror of
https://github.com/flarum/core.git
synced 2025-07-23 01:31:40 +02:00
This PR introduces the ability to just override a LESS file's contents through an extender.
This is mainly useful for theme development, as there are times in extensively customized themes where overriding the actual file makes a huge difference vs overriding CSS styles which can turn into a maintenance hell real fast.
Overriding styles is more tedious than overriding files. When you're designing an element, you would normally rather start from a blank canvas, than a styled element. With an already styled element you have to first override and undo the styles you do not wish to have, only then can you start shaping it, but even then you'd always end up constantly undoing default styles. This mostly applies for more advanced themes. (example: 851c55516d/less/forum/DiscussionList.less
)
76 lines
1.3 KiB
PHP
76 lines
1.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Flarum.
|
|
*
|
|
* For detailed copyright and license information, please view the
|
|
* LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Flarum\Frontend\Compiler\Source;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
class FileSource implements SourceInterface
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $path;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $extensionId;
|
|
|
|
/**
|
|
* @param string $path
|
|
*/
|
|
public function __construct(string $path, ?string $extensionId = null)
|
|
{
|
|
if (! file_exists($path)) {
|
|
throw new InvalidArgumentException("File not found at path: $path");
|
|
}
|
|
|
|
$this->path = $path;
|
|
$this->extensionId = $extensionId;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getContent(): string
|
|
{
|
|
return file_get_contents($this->path);
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function getCacheDifferentiator()
|
|
{
|
|
return [$this->path, filemtime($this->path)];
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPath(): string
|
|
{
|
|
return $this->path;
|
|
}
|
|
|
|
public function setPath(string $path): void
|
|
{
|
|
$this->path = $path;
|
|
}
|
|
|
|
public function getExtensionId(): ?string
|
|
{
|
|
return $this->extensionId;
|
|
}
|
|
}
|