Flow\Loader::autoload PHP Méthode

autoload() public static méthode

public static autoload ( )
    public static function autoload()
    {
        static $autoload = false;
        if ($autoload) {
            return;
        }
        ini_set('unserialize_callback_func', 'spl_autoload_call');
        spl_autoload_register(function ($class) {
            $class = explode('\\', $class);
            array_shift($class);
            $path = __DIR__ . '/' . implode('/', $class) . '.php';
            if (is_readable($path)) {
                include $path;
            }
        });
        $autoload = true;
    }

Usage Example

Exemple #1
0
<?php

require __DIR__ . '/../src/Flow/Loader.php';
use Flow\Loader;
use Flow\Helper;
Loader::autoload();
class OutputTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        parent::setUp();
        $this->flow = new Loader(['source' => __DIR__ . '/actual', 'target' => __DIR__ . '/cache']);
    }
    public function outputProvider()
    {
        $tests = ['and', 'add', 'array', 'block', 'comparison', 'concat', 'conditional', 'div', 'for', 'for_else', 'if', 'if_else', 'if_inline', 'in', 'include', 'join', 'logical', 'macro', 'mul', 'or', 'output', 'set', 'sub', 'unless', 'xor'];
        return array_map(function ($item) {
            return [$item];
        }, $tests);
    }
    /**
     * @dataProvider outputProvider
     */
    public function testOutput($data)
    {
        $expected = __DIR__ . "/expected/{$data}.html";
        $this->assertTrue($this->flow->isValid("{$data}.html"));
        $template = $this->flow->load("{$data}.html");
        $this->assertEquals(file_get_contents($expected), $template->render());
    }
}