Index

tWithMakefiles

MMO\core\classes · 1 symbol · generated 30 Sep 2026

trait

tWithMakefiles

tWithMakefiles.php:19

Trait giving a class a named collection of iMakefile builders (e.g. one per asset type: 'scss', 'js', ...), each tied to an output filename, with a uniform way to (re)build one/some/all of them.

trait MMO\core\classes\tWithMakefiles
Namespace
MMO\core\classes
NOTE: [`removeMakefile`](https://mmoframework.fr/documentation/mmo.core/php/classes/tWithMakefiles.md#twithmakefiles-removemakefile) logs a warning through `$this->warning()` on an unknown $type, so a class using this trait is expected to also use [`tLogEmitter`](https://mmoframework.fr/documentation/mmo.core/php/classes/tLogEmitter.md#tlogemitter) (or otherwise implement iLogEmitter).
class Builder {use tWithMakefiles, tLogEmitter;} $b = new Builder(); $b->setMakefile('scss', 'build/style.css', new ScssMakefile()); $b->make('scss'); // rebuilds build/style.css if its scss sources changed $b->make(); // rebuilds every registered makefile

Index

makefiles
getMakefile($type)
getMakefiles()
hasMakefile($type)
make($types, $opts)Automake the makefiles
moveMakeFile($type, $filename)Change a registered makefile's output filename (moving/renaming its build target).
removeMakefile($type, $removeLink)Unregister a makefile.
setMakefile($type, $filename, $makefile)Register a makefile under $type, and point it at $filename.

Properties1

makefiles

protected $makefiles = []

Methods7

getMakefile($type)

tWithMakefiles.php:38
function getMakefile(string $type): MMO\core\interfaces\iMakefile
$typestring
returnsiMakefile
throwsif no makefile was registered under $type
$b->getMakefile('scss')->getFilename(); // 'build/style.css'

getMakefiles()

tWithMakefiles.php:28
function getMakefiles()
returnsevery registered makefile, keyed by its $type
$b->getMakefiles(); // ['scss' => $scssMakefile]

hasMakefile($type)

tWithMakefiles.php:89
function hasMakefile($type): bool
$type
returnsbooltrue if a makefile is registered under $type

make($types, $opts)

tWithMakefiles.php:104

Automake the makefiles

function make(array|string|null $types = null, array $opts = [])
$types = nullarray | string | nullthe type(s) to build (a single type, a list of types, or null for every registered makefile)
$opts = []arrayoptions forwarded to each makefile's autoMake()
returns
throwsif any of $types is not registered
$b->make('scss'); // rebuild just the 'scss' makefile$b->make(['scss', 'js']); // rebuild both$b->make(); // rebuild every registered makefile

moveMakeFile($type, $filename)

tWithMakefiles.php:81

Change a registered makefile's output filename (moving/renaming its build target).

function moveMakeFile(string $type, string $filename)
$typestring
$filenamestringthe new output filename
returns
throwsif $type is not registered
$b->moveMakeFile('scss', 'build/style2.css');

removeMakefile($type, $removeLink)

tWithMakefiles.php:65

Unregister a makefile. Logs a warning (does not throw) if $type is not registered.

function removeMakefile(string $type, bool $removeLink = true)
$typestring
$removeLink = trueboolif true (the default), also clear the makefile's own filename (setFilename(null)) before dropping it
returns
$b->removeMakefile('scss'); $b->hasMakefile('scss'); // false

setMakefile($type, $filename, $makefile)

tWithMakefiles.php:51

Register a makefile under $type, and point it at $filename.

function setMakefile(string $type, string $filename, MMO\core\interfaces\iMakefile $makefile): MMO\core\interfaces\iMakefile
$typestringan arbitrary identifier for this makefile (e.g. 'scss', 'js')
$filenamestringthe output file this makefile builds
$makefileiMakefile
returnsiMakefile$makefile, for chaining
$b->setMakefile('scss', 'build/style.css', new ScssMakefile());