Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
change readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xleliu committed Jul 6, 2017
1 parent 3d78f60 commit 4c466e3
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,39 @@ and then `require` them in your code.

```php
<?php

require '../src/Autoloader.php';

Xiaoler\Blade\Autoloader::register();

use Xiaoler\Blade\FileViewFinder;
use Xiaoler\Blade\Factory;
use Xiaoler\Blade\Compilers\BladeCompiler;
use Xiaoler\Blade\Engines\CompilerEngine;
use Xiaoler\Blade\Filesystem;
use Xiaoler\Blade\Engines\EngineResolver;

$path = ['/view_path']; // your view file path, it's an array
$cachePath = '/cache_path'; // compiled file path

$compiler = new \Xiaoler\Blade\Compilers\BladeCompiler($cachePath);
$file = new Filesystem;
$compiler = new BladeCompiler($file, $cachePath);

// you can add a custom directive if you want
$compiler->directive('datetime', function($timestamp) {
return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
});

$engine = new \Xiaoler\Blade\Engines\CompilerEngine($compiler);
$finder = new \Xiaoler\Blade\FileViewFinder($path);

// if your view file extension is not php or blade.php, use this to add it
$finder->addExtension('tpl');
$resolver = new EngineResolver;
$resolver->register('blade', function () use ($file, $cachePath) {
return new CompilerEngine(new BladeCompiler($file, $cachePath));
});

// get an instance of factory
$factory = new \Xiaoler\Blade\Factory($engine, $finder);
$factory = new Factory($resolver, new FileViewFinder($file, $path));

// if your view file extension is not php or blade.php, use this to add it
$factory->addExtension('tpl', 'blade');

// render the template file and echo it
echo $factory->make('hello', ['a' => 1, 'b' => 2])->render();
Expand Down

0 comments on commit 4c466e3

Please sign in to comment.