public function ensureScopeRule($stackLevel = 2)
{
$property = $this->reflectionProperty;
if ($property->isProtected()) {
$backTrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $stackLevel + 1);
$accessor = isset($backTrace[$stackLevel]) ? $backTrace[$stackLevel] : [];
$propertyClass = $property->class;
if (isset($accessor['class'])) {
if ($accessor['class'] === $propertyClass || is_subclass_of($accessor['class'], $propertyClass)) {
return true;
}
}
throw new AspectException("Cannot access protected property {$propertyClass}::{$property->name}");
}
return true;
}