Class Kitab\Compiler\Compiler

class Compiler
{
    public function __construct();
    public function compile(Kitab\Finder $finder, Kitab\Compiler\Target\Target $target);
    public function getParser(): Kitab\Compiler\Parser;
    protected function link(Kitab\Compiler\IntermediateRepresentation\File $file, array &$symbols);
}

A compiler that orchestrates the whole compilation process.

This compiler, as explained previously, is a stream compiler. It receives a finder that is an iterator where each item is a PHP file to analyse. Each file is parsed by the parser, transformed into a Intermediate Representation, that is compiled by the target into partial objects. The target ends the whole process by assembling all the objects.

Attributes

protected static $_parser = null;

The parsed used to parse PHP files.

The parser is allocated once, hence the static declaration.

Methods

public function __construct()

When constructing the compiler, a new instance of the Kitab\Compiler\Parser parser is created and stored statically.

public function compile(Kitab\Finder $finder, Kitab\Compiler\Target\Target $target)

Compile all files provided by the finder into the specified target. See the workflow description for more details.

Examples

$finder = new Kitab\Finder();
$finder->in($path);

$target = new Kitab\Compiler\Target\Html\Html();

$compiler = new Kitab\Compiler\Compiler();
$compiler->compile($finder, $target);
public function getParser(): Kitab\Compiler\Parser

Return the parser stored in the cache.

Examples

$compiler = new Kitab\Compiler\Compiler();

assert($compiler->getParser() instanceof Kitab\Compiler\Parser);
protected function link(Kitab\Compiler\IntermediateRepresentation\File $file, array &$symbols)

Extract new symbols from an intermediate representation and update the linker.

The linker is a tree structure.

Exceptions

If the link handles an intermediate representation that is unexpected, a Kitab\Exception\LinkerUnknownIntermediateRepresentation exception will be thrown. This is not likely to happen, except during a development phase.