PageRenderTime 76ms CodeModel.GetById 34ms app.highlight 2ms RepoModel.GetById 38ms app.codeStats 0ms

/lib/mock/LimeMockTemplate.php

http://github.com/bschussek/lime
PHP | 57 lines | 18 code | 6 blank | 33 comment | 0 complexity | 46cb96cd5fd1b331cb086b1500464827 MD5 | raw file
 1<?php
 2
 3/*
 4 * This file is part of the Lime test framework.
 5 *
 6 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
 7 * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
 8 *
 9 * This source file is subject to the MIT license that is bundled
10 * with this source code in the file LICENSE.
11 */
12
13/**
14 * Reads template files and parses them with a set of template variables.
15 *
16 * @package    Lime
17 * @author     Bernhard Schussek <bernhard.schussek@symfony-project.com>
18 * @version    SVN: $Id: LimeMockTemplate.php 23701 2009-11-08 21:23:40Z bschussek $
19 */
20class LimeMockTemplate
21{
22  private
23    $parameters   = array(),
24    $filename     = '';
25
26  /**
27   * Constructor.
28   *
29   * Configures this template to use the given file.
30   *
31   * @param string $filename
32   */
33  public function __construct($filename)
34  {
35    $this->filename = $filename;
36  }
37
38  /**
39   * Renders the file of this template with the given parameters.
40   *
41   * The parameters are made available in the template and can be accessed there
42   * as normal PHP variables. The template is parsed and the output of the
43   * template is returned.
44   *
45   * @param  array $parameters
46   * @return string
47   */
48  public function render(array $parameters)
49  {
50    ob_start();
51    extract($parameters);
52    include $this->filename;
53
54    return ob_get_clean();
55  }
56
57}