getClassAccessors example

return self::STATUS_INITIALIZED_FULL;
        }

        if (\is_array($this->initializer)) {
            $class = $instance::class;
            $propertyScope ??= $class;
            $propertyScopes = Hydrator::$propertyScopes[$class];
            $propertyScopes[$k = "\0$propertyScope\0$propertyName"] ?? $propertyScopes[$k = "\0*\0$propertyName"] ?? $k = $propertyName;

            if ($initializer = $this->initializer[$k] ?? null) {
                $value = $initializer(...[$instance$propertyName$propertyScope, LazyObjectRegistry::$defaultProperties[$class][$k] ?? null]);
                $accessor = LazyObjectRegistry::$classAccessors[$propertyScope] ??= LazyObjectRegistry::getClassAccessors($propertyScope);
                $accessor['set']($instance$propertyName$value);

                return $this->status = self::STATUS_INITIALIZED_PARTIAL;
            }

            $status = self::STATUS_UNINITIALIZED_PARTIAL;

            if ($initializer = $this->initializer["\0"] ?? null) {
                if (!\is_array($values = $initializer($instance, LazyObjectRegistry::$defaultProperties[$class]))) {
                    throw new \TypeError(sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $classget_debug_type($values)));
                }
                
get_in_scope:

        try {
            if (null === $scope) {
                if (null === $readonlyScope && 1 !== $parent) {
                    return $instance->$name;
                }
                $value = $instance->$name;

                return $value;
            }
            $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope);

            return $accessor['get']($instance$name, null !== $readonlyScope || 1 === $parent);
        } catch (\Error $e) {
            if (\Error::class !== $e::class || !str_starts_with($e->getMessage(), 'Cannot access uninitialized non-nullable property')) {
                throw $e;
            }

            try {
                if (null === $scope) {
                    $instance->$name = [];

                    
if (null === $values) {
                if (!\is_array($values = ($state->initializer["\0"])($this, Registry::$defaultProperties[$class]))) {
                    throw new \TypeError(sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $classget_debug_type($values)));
                }

                if (\array_key_exists($key$properties = (array) $this)) {
                    continue;
                }
            }

            if (\array_key_exists($key$values)) {
                $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope);
                $accessor['set']($this$name$properties[$key] = $values[$key]);
            } else {
                $state->initialize($this$name$scope);
                $properties = (array) $this;
            }
        }

        return $this;
    }

    /** * @return bool Returns false when the object cannot be reset, ie when it's not a lazy object */
get_in_scope:

        try {
            if (null === $scope) {
                if (null === $readonlyScope && 1 !== $parent) {
                    return $instance->$name;
                }
                $value = $instance->$name;

                return $value;
            }
            $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope);

            return $accessor['get']($instance$name, null !== $readonlyScope || 1 === $parent);
        } catch (\Error $e) {
            if (\Error::class !== $e::class || !str_starts_with($e->getMessage(), 'Cannot access uninitialized non-nullable property')) {
                throw $e;
            }

            try {
                if (null === $scope) {
                    $instance->$name = [];

                    
if (null === $values) {
                if (!\is_array($values = ($state->initializer["\0"])($this, Registry::$defaultProperties[$class]))) {
                    throw new \TypeError(sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $classget_debug_type($values)));
                }

                if (\array_key_exists($key$properties = (array) $this)) {
                    continue;
                }
            }

            if (\array_key_exists($key$values)) {
                $accessor = Registry::$classAccessors[$scope] ??= Registry::getClassAccessors($scope);
                $accessor['set']($this$name$properties[$key] = $values[$key]);
            } else {
                $state->initialize($this$name$scope);
                $properties = (array) $this;
            }
        }

        return $this;
    }

    /** * @return bool Returns false when the object cannot be reset, ie when it's not a lazy object */
return self::STATUS_INITIALIZED_FULL;
        }

        if (\is_array($this->initializer)) {
            $class = $instance::class;
            $propertyScope ??= $class;
            $propertyScopes = Hydrator::$propertyScopes[$class];
            $propertyScopes[$k = "\0$propertyScope\0$propertyName"] ?? $propertyScopes[$k = "\0*\0$propertyName"] ?? $k = $propertyName;

            if ($initializer = $this->initializer[$k] ?? null) {
                $value = $initializer(...[$instance$propertyName$propertyScope, LazyObjectRegistry::$defaultProperties[$class][$k] ?? null]);
                $accessor = LazyObjectRegistry::$classAccessors[$propertyScope] ??= LazyObjectRegistry::getClassAccessors($propertyScope);
                $accessor['set']($instance$propertyName$value);

                return $this->status = self::STATUS_INITIALIZED_PARTIAL;
            }

            $status = self::STATUS_UNINITIALIZED_PARTIAL;

            if ($initializer = $this->initializer["\0"] ?? null) {
                if (!\is_array($values = $initializer($instance, LazyObjectRegistry::$defaultProperties[$class]))) {
                    throw new \TypeError(sprintf('The lazy-initializer defined for instance of "%s" must return an array, got "%s".', $classget_debug_type($values)));
                }
                
Home | Imprint | This part of the site doesn't use cookies.