1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: */
7:
8: namespace Nette\Utils;
9:
10: use Nette;
11:
12:
13: /**
14: * Limited scope for PHP code evaluation and script including.
15: *
16: * @deprecated
17: */
18: class LimitedScope
19: {
20:
21: /**
22: * Static class - cannot be instantiated.
23: */
24: final public function __construct()
25: {
26: throw new Nette\StaticClassException;
27: }
28:
29:
30: /**
31: * Evaluates code in limited scope.
32: * @param string PHP code
33: * @param array local variables
34: * @return mixed the return value of the evaluated code
35: */
36: public static function evaluate(/*$code, array $vars = NULL*/)
37: {
38: trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
39: if (func_num_args() > 1) {
40: foreach (func_get_arg(1) as $__k => $__v) $$__k = $__v;
41: unset($__k, $__v);
42: }
43: $res = eval('?>' . func_get_arg(0));
44: if ($res === FALSE && ($error = error_get_last()) && $error['type'] === E_PARSE) {
45: throw new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
46: }
47: return $res;
48: }
49:
50:
51: /**
52: * Includes script in a limited scope.
53: * @param string file to include
54: * @param array local variables
55: * @return mixed the return value of the included file
56: */
57: public static function load(/*$file, array $vars = NULL*/)
58: {
59: trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
60: if (func_num_args() > 1 && is_array(func_get_arg(1))) {
61: foreach (func_get_arg(1) as $__k => $__v) $$__k = $__v;
62: unset($__k, $__v);
63: }
64: return include func_get_arg(0);
65: }
66:
67: }
68: