1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://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) {
41: $$__k = $__v;
42: }
43: unset($__k, $__v);
44: }
45: $res = eval('?>' . func_get_arg(0));
46: if ($res === FALSE && ($error = error_get_last()) && $error['type'] === E_PARSE) {
47: throw new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
48: }
49: return $res;
50: }
51:
52:
53: /**
54: * Includes script in a limited scope.
55: * @param string file to include
56: * @param array local variables
57: * @return mixed the return value of the included file
58: */
59: public static function load(/*$file, array $vars = NULL*/)
60: {
61: trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
62: if (func_num_args() > 1 && is_array(func_get_arg(1))) {
63: foreach (func_get_arg(1) as $__k => $__v) {
64: $$__k = $__v;
65: }
66: unset($__k, $__v);
67: }
68: return include func_get_arg(0);
69: }
70:
71: }
72: