Jarves\Configuration\Model::propertyToArray PHP Method

propertyToArray() public method

public propertyToArray ( string $k, $printDefaults = false ) : mixed
$k string name of the property
$printDefaults
return mixed
    public function propertyToArray($k, $printDefaults = false)
    {
        if (!$this->canPropertyBeExported($k)) {
            return;
        }
        $reflection = new \ReflectionClass($this);
        $properties = $reflection->getDefaultProperties();
        $getter = 'get' . ucfirst($k) . 'Array';
        if (!method_exists($this, $getter) || !is_callable(array($this, $getter))) {
            $getter = 'get' . ucfirst($k);
            if (!method_exists($this, $getter) || !is_callable(array($this, $getter))) {
                return null;
            }
        }
        $value = $this->{$getter}();
        if (!$printDefaults && $value === $properties[$k]) {
            return null;
        }
        if (is_array($value)) {
            $result = [];
            foreach ($value as $key => $item) {
                if (is_object($item)) {
                    if ($item instanceof Model) {
                        $result[$item->getArrayKey() ? $item->getArrayKeyValue() : $key] = $item->toArray($printDefaults);
                    } else {
                        $result[$key] = (array) $item;
                    }
                } else {
                    $result[$key] = $item;
                }
            }
            return $result;
        } else {
            if (is_object($value) && $value instanceof Model) {
                $value = $value->toArray($printDefaults);
            }
        }
        return $value;
    }