| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) or exit; |
| 3 |
|
| 4 |
class VwoTemplater { |
| 5 |
protected $dirs = []; |
| 6 |
|
| 7 |
public function __construct( array $dirs = [ '' ] ) { |
| 8 |
$this->dirs = $dirs; |
| 9 |
} |
| 10 |
|
| 11 |
protected function find( $file ) { |
| 12 |
foreach ( $this->dirs as $dir ) { |
| 13 |
if ( is_file( $path = ( $dir ? trailingslashit( $dir ) : '' ) . $file ) ) return $path; |
| 14 |
elseif ( is_file( $path .= '.php' ) ) return $path; |
| 15 |
} |
| 16 |
return false; |
| 17 |
} |
| 18 |
|
| 19 |
public function render( string $file, array $vars = [] ) { |
| 20 |
if ( ! $file = $this->find( $file ) ) { |
| 21 |
return false; |
| 22 |
} |
| 23 |
if ( $vars ) extract( $vars, EXTR_SKIP ); |
| 24 |
|
| 25 |
ob_start(); |
| 26 |
include $file; |
| 27 |
|
| 28 |
return ob_get_clean(); |
| 29 |
} |
| 30 |
} |
| 31 |
|