Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 399
Zeile 13... Zeile 13...
13
use Nette\MemberAccessException;
13
use Nette\MemberAccessException;
Zeile 14... Zeile 14...
14
 
14
 
15
 
15
 
-
 
16
/**
16
/**
17
 * Nette\SmartObject helpers.
17
 * Nette\SmartObject helpers.
18
 * @internal
18
 */
19
 */
19
final class ObjectHelpers
20
final class ObjectHelpers
Zeile 26... Zeile 27...
26
	 */
27
	 */
27
	public static function strictGet(string $class, string $name): void
28
	public static function strictGet(string $class, string $name): void
28
	{
29
	{
29
		$rc = new \ReflectionClass($class);
30
		$rc = new \ReflectionClass($class);
30
		$hint = self::getSuggestion(array_merge(
31
		$hint = self::getSuggestion(array_merge(
31
			array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
32
			array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
32
			self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
33
			self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
33
		), $name);
34
		), $name);
34
		throw new MemberAccessException("Cannot read an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
35
		throw new MemberAccessException("Cannot read an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
35
	}
36
	}
Zeile 41... Zeile 42...
41
	 */
42
	 */
42
	public static function strictSet(string $class, string $name): void
43
	public static function strictSet(string $class, string $name): void
43
	{
44
	{
44
		$rc = new \ReflectionClass($class);
45
		$rc = new \ReflectionClass($class);
45
		$hint = self::getSuggestion(array_merge(
46
		$hint = self::getSuggestion(array_merge(
46
			array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
47
			array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
47
			self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
48
			self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
48
		), $name);
49
		), $name);
49
		throw new MemberAccessException("Cannot write to an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
50
		throw new MemberAccessException("Cannot write to an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
50
	}
51
	}
Zeile 74... Zeile 75...
74
 
75
 
75
		} else {
76
		} else {
76
			$hint = self::getSuggestion(array_merge(
77
			$hint = self::getSuggestion(array_merge(
77
				get_class_methods($class),
78
				get_class_methods($class),
78
				self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:static[ \t]+)?(?:\S+[ \t]+)??(\w+)\(~m'),
79
				self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:static[ \t]+)?(?:\S+[ \t]+)??(\w+)\(~m'),
79
				$additionalMethods
80
				$additionalMethods,
80
			), $method);
81
			), $method);
81
			throw new MemberAccessException("Call to undefined method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
82
			throw new MemberAccessException("Call to undefined method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
82
		}
83
		}
Zeile 105... Zeile 106...
105
				: ($rm->isProtected() ? 'protected ' : '');
106
				: ($rm->isProtected() ? 'protected ' : '');
106
			throw new MemberAccessException("Call to {$visibility}method $class::$method() from " . ($context ? "scope $context." : 'global scope.'));
107
			throw new MemberAccessException("Call to {$visibility}method $class::$method() from " . ($context ? "scope $context." : 'global scope.'));
Zeile 107... Zeile 108...
107
 
108
 
108
		} else {
109
		} else {
109
			$hint = self::getSuggestion(
110
			$hint = self::getSuggestion(
110
				array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), function ($m) { return $m->isStatic(); }),
111
				array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), fn($m) => $m->isStatic()),
111
				$method
112
				$method,
112
			);
113
			);
113
			throw new MemberAccessException("Call to undefined static method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
114
			throw new MemberAccessException("Call to undefined static method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
114
		}
115
		}
Zeile 131... Zeile 132...
131
		$rc = new \ReflectionClass($class);
132
		$rc = new \ReflectionClass($class);
132
		preg_match_all(
133
		preg_match_all(
133
			'~^  [ \t*]*  @property(|-read|-write|-deprecated)  [ \t]+  [^\s$]+  [ \t]+  \$  (\w+)  ()~mx',
134
			'~^  [ \t*]*  @property(|-read|-write|-deprecated)  [ \t]+  [^\s$]+  [ \t]+  \$  (\w+)  ()~mx',
134
			(string) $rc->getDocComment(),
135
			(string) $rc->getDocComment(),
135
			$matches,
136
			$matches,
136
			PREG_SET_ORDER
137
			PREG_SET_ORDER,
137
		);
138
		);
Zeile 138... Zeile 139...
138
 
139
 
139
		$props = [];
140
		$props = [];
140
		foreach ($matches as [, $type, $name]) {
141
		foreach ($matches as [, $type, $name]) {
Zeile 197... Zeile 198...
197
				$doc[] = $trait->getDocComment();
198
				$doc[] = $trait->getDocComment();
198
				$traits += $trait->getTraits();
199
				$traits += $trait->getTraits();
199
			}
200
			}
200
		} while ($rc = $rc->getParentClass());
201
		} while ($rc = $rc->getParentClass());
Zeile 201... Zeile 202...
201
 
202
 
202
		return preg_match_all($pattern, implode($doc), $m) ? $m[1] : [];
203
		return preg_match_all($pattern, implode('', $doc), $m) ? $m[1] : [];
Zeile 203... Zeile 204...
203
	}
204
	}
204
 
205
 
205
 
206
 
206
	/**
207
	/**
207
	 * Checks if the public non-static property exists.
208
	 * Checks if the public non-static property exists.
208
	 * @return bool|string returns 'event' if the property exists and has event like name
209
	 * Returns 'event' if the property exists and has event like name
209
	 * @internal
210
	 * @internal
210
	 */
211
	 */
211
	public static function hasProperty(string $class, string $name)
212
	public static function hasProperty(string $class, string $name): bool|string
212
	{
213
	{
213
		static $cache;
214
		static $cache;