public function register(callable $factory, $priority = 0): self
    {
        array_unshift($this->engines, [$factory, $priority]);
        $this->cache = null;

        $sorted = false;
        while (!$sorted) {
            $sorted = true;
            for ($i = 0, $l = count($this->engines) - 1; $i < $l; $i++) {
                if ($this->engines[$i][1] < $this->engines[$i + 1][1]) {
                    $tmp = $this->engines[$i];
                    $this->engines[$i] = $this->engines[$i + 1];
                    $this->engines[$i + 1] = $tmp;
                    $sorted = false;
                }
            }
        }

        return $this;
    }