21 protected function push( array $scope ) {
22 $this->stack[] = array_merge( (array) $this->peek(), (array) $scope );
29 protected function peek() {
30 $length =
sizeof( $this->stack );
31 return $length ? $this->stack[ $length - 1 ] : array();
38 protected function pop() {
39 return array_pop( $this->stack );
47 'e' =>
'htmlspecialchars',
48 't' => [ $this,
'splat' ],
87 public function splat( $name, $scope = array() ) {
88 $this->push( $scope );
89 $scope = $this->peek();
90 foreach( $this->nameToPaths( $name ) as $file ) {
102 foreach( $paths as $name => $path ) {
103 $this->paths[$name][] = $path;
112 foreach( (array) $bases as $base ) {
113 $this->bases[] = $base;
127 @$onlyOne = array_merge( (array) $this->paths[$name], [
"$name.php", ]);
128 foreach( $onlyOne as $file ) {
129 foreach( $this->bases as $base ) {
130 $path = $base . DIRECTORY_SEPARATOR . $file;
131 if( is_readable( $path ) ) {
137 @$adds = array_merge( (array) $this->paths[$name.
'[]'], [
"$name-add.php", ]);
138 foreach( $adds as $file ) {
139 foreach( $this->bases as $base ) {
140 $path = $base . DIRECTORY_SEPARATOR . $file;
141 if( is_readable( $path ) ) {
166 $this->scope = $scope;
173 extract($this->scope);
push(array $scope)
push a scope onto the stack
addBases( $bases)
Add a base directory to resolve $relativePath to $absolutePath
splat()
extract the scope and include the file
pop()
pop a scope off the stack
__construct()
Setup default scopes and paths, but leave base dirs empty.
Helper class for Splat that runs the template PHP.
__construct( $file, array $scope)
Record the $file and $scope
nameToPaths($name)
Resolve a template $name to an array of absolute $paths.
addPaths(array $paths)
Add a resolution of $name to $relativePath
peek()
peek at current scope
splat( $name, $scope=array())
Main function: execute template $name with given $scope