X
X
XEHKOK2018-12-13 21:47:35
Twig
XEHKOK, 2018-12-13 21:47:35

How to install Twig 2.x without Composer?

Hello. The question is, is it possible to install Twig 2.x without Composer, via spl_autoload?
I can't figure out how to autoload Twig 2.x without Composer. I have an approximate ready-made code with GIT:
Twig 2.0 without Composer

<?php
spl_autoload_register(function ($class) {

    // project-specific namespace prefix
    $prefix = 'Twig';

    // base directory for the namespace prefix
    $base_dir = __DIR__ . '/Twig/lib/Twig/';

    // does the class use the namespace prefix?
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        // no, move to the next registered autoloader
        return;
    }

    // get the relative class name
    $relative_class = substr($class, $len);

    // replace the namespace prefix with the base directory, replace namespace
    // separators with directory separators in the relative class name, append
    // with .php
    $file = $base_dir . str_replace('_', '/', $relative_class) . '.php';

    // if the file exists, require it
    if (file_exists($file)) {
        require $file;
    }
});
?>

Can't figure out how to tie this code into Twig 2.x
My download excerpt from Twig 1.x:
$tpl_path = ROOT_DIR . '/templates/' . $config['cp_tpl'];

require_once ENGINE_DIR . '/lib/Twig/Autoloader.php';
Twig_Autoloader::register();

$loader = new Twig_Loader_Filesystem($tpl_path);
$twig = new Twig_Environment($loader, array(
    'cache'       => ENGINE_DIR . '/cache/twig',
    'auto_reload' => true
));

Help me!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question