tommcdo / kohana-twig Goto Github PK
View Code? Open in Web Editor NEWA Twig module for Kohana
A Twig module for Kohana
Sometimes kohana-twig couldn`t find {% extends "name.twig" %}
, because it is located in subfolder.
Solution is to extend Twig_Loader_CFS in application folder:
<?php defined('SYSPATH') or die('No direct script access.');
class Twig_Loader_CFS implements Twig_LoaderInterface
{
protected $_config;
protected $history;
private function rememberPath($path)
{
$path = realpath($path);
$path = is_file($path) ? dirname($path) : $path;
$this->history[] = $path;
return $this->history;
}
public function __construct($config)
{
$this->_config = $config;
$this->rememberPath($this->_config['path']);
}
public function find_template($name)
{
$path = Kohana::find_file($this->_config['path'], $name, $this->_config['extension']);
if ($path == false) {
$breadcrumbs = array_reverse($this->history);
$finded = false;
foreach ($breadcrumbs as $dir) {
$path = $dir . DS . $name;
if (is_file($path)) {
$finded = true;
$this->rememberPath($path);
return $path;
}
}
if (!$finded) {
throw new Kohana_Exception(
'The requested twig :name could not be found',
[
':name' => $name
]
);
}
} else {
$this->rememberPath($path);
}
return $path;
}
public function getSource($name)
{
return file_get_contents($this->find_template($name));
}
public function getCacheKey($name)
{
return $name;
}
public function isFresh($name, $time)
{
return filemtime($this->find_template($name)) <= $time;
}
}
The environment method used for overriding the Twig
class is called protected static function twig()
. This is fine when it's defined in the class Kohana_Twig
(which Twig
extends), but not when writing an override, as PHP believes twig()
to be the constructor, which is not allowed to be static.
My present workaround without modifying the module:
class Oops_Twig extends Kohana_Twig {
protected static function twig()
{
// overrides...
}
}
class Twig extends Oops_Twig {}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.