has($name, true); } // Validate given value if (! Validator::validate($name, $value, $this)) { $message = "Rejected value. Type='%s', Property='%s', value='%s'"; throw new Exception( sprintf( $message, static::class, $name, print_r($value, true) ) . PHP_EOL ); } // @context has a special role if ($name === '@context') { $this->_props[$name] = $value; // All modes and property defined } elseif ($this->has($name)) { $this->_props[$name] = $this->transform($value); // Undefined property but we are in 'include' mode } elseif (Config::get('undefined_properties') === 'include') { $this->_props[$name] = $this->transform($value); } return $this; } /** * Affect a value to a property or an extended property * * @param mixed $value * @return mixed */ private function transform($value) { if (is_array($value)) { if (isset($value['type'])) { return Type::create($value); } elseif (is_int(key($value))) { return array_map( static function ($value) { return is_array($value) && isset($value['type']) ? Type::create($value) : $value; }, $value ); // Empty array, array that should not be casted as ActivityStreams types } else { return $value; } } else { // Scalars return $value; } } /** * Standard getter method * * @return mixed */ public function get(string $name) { if (Config::get('undefined_properties') === 'strict') { $this->has($name, true); // Non strict mode returns null when property is not defined } elseif (! $this->has($name)) { return null; } return $this->_props[$name]; } /** * Checks that property exists */ public function has(string $name, bool $strict = false): bool { if (property_exists($this, $name)) { if (! array_key_exists($name, $this->_props)) { $this->_props[$name] = $this->$name; } return true; } if (\array_key_exists($name, $this->_props)) { return true; } if ($strict) { // Defined properties $allowed = Type::create($this->type)->getProperties(); sort($allowed); throw new Exception( sprintf( 'Property "%s" is not defined. Type="%s", ' . 'Class="%s"' . PHP_EOL . 'Allowed properties: %s', $name, $this->get('type'), static::class, implode(', ', $allowed) ) ); } return false; } /** * Get a list of all properties names * * @return array */ public function getProperties() { return array_values( array_unique( array_merge( array_keys($this->_props), array_keys( array_diff_key( get_object_vars($this), ['_props' => '1'] ) ) ) ) ); } /** * Get a list of all properties and their values * as an associative array. * Null values are not returned. */ public function toArray(): array { $keys = array_keys( array_filter( get_object_vars($this), static function ($value, $key): bool { return ! is_null($value) && $key !== '_props'; }, ARRAY_FILTER_USE_BOTH ) ); $stack = []; // native properties foreach ($keys as $key) { if ($this->$key instanceof self) { $stack[$key] = $this->$key->toArray(); } elseif (! is_array($this->$key)) { $stack[$key] = $this->$key; } elseif (is_array($this->$key)) { if (is_int(key($this->$key))) { $stack[$key] = array_map( static function ($value) { return $value instanceof self ? $value->toArray() : $value; }, $this->$key ); } else { $stack[$key] = $this->$key; } } } // _props foreach ($this->_props as $key => $value) { if (is_null($value)) { continue; } if ($value instanceof self) { $stack[$key] = $value->toArray(); } elseif (! is_array($value)) { $stack[$key] = $value; } elseif (is_array($value)) { if (is_int(key($value))) { $stack[$key] = array_map( static function ($value) { return $value instanceof self ? $value->toArray() : $value; }, $value ); } else { $stack[$key] = $value; } } } return $stack; } /** * Get a JSON * * @param int $options PHP JSON options */ public function toJson(?int $options = null): string { return json_encode( $this->toArray(), intval($options) ); } /** * Get a copy of current object and return a new instance * * @return self A new instance of this object */ public function copy(): self { return Type::create( $this->type, $this->toArray() ); } /** * Extend current type properties * * @param mixed $default */ public function extend(string $property, mixed $default = null): void { if ($this->has($property)) { return; } if (! \array_key_exists($property, $this->_props)) { $this->_props[$property] = $default; } } /** * Magical isset method */ public function __isset(string $name): bool { return property_exists($this, $name) || \array_key_exists($name, $this->_props); } /** * Magical setter method * * @param mixed $value */ public function __set(string $name, $value): void { $this->set($name, $value); } /** * Magical getter method * * @return mixed */ public function __get(string $name) { return $this->get($name); } /** * Overloading methods * * @return mixed */ public function __call(string $name, ?array $arguments = []) { if (strpos($name, 'get') === 0) { $attr = lcfirst(substr($name, 3)); return $this->get($attr); } // Setters if (strpos($name, 'set') === 0) { if (count($arguments) === 1) { $attr = lcfirst(substr($name, 3)); return $this->set($attr, $arguments[0]); } else { throw new Exception( sprintf( 'Expected exactly one argument for method "%s()"', $name ) ); } } throw new Exception( sprintf( 'Method "%s" is not defined', $name ) ); } } __halt_compiler();----SIGNATURE:----wXTmozlEOuuvzF2c+H6nb2UvO7sRwM+vhoMk5OeexAocsykUfy3Nw7o2WT+aeL8SXUvtKDh7zAnDK5v4cCVn9mix0mV30jlk8YzswF66ag/ZKBSyvqBrY28zpj37CB3J44v2S17X6qz/zrgLS/0xPvkagnxiBggAhJz4SYEczWa646FuaEb4uFMNONMe54hB+KEAjRvsJNrMAEDAecAYQVT8zIbbR3c9/aTA0VzYhYQWbNMvYOZHzpc7Om1eN46/UJCwp6OLpVrUywW9YgTl3TI4/X8Tsih+tkEfH11bScg8ZICzIOlS33MhmnjAAvE5UCm5TDOOyMVTA69A6kSVGUXYxbnYFQw556KMLqxZykfyE3h7njyed7rmameWTC0NIHV0shFy0zWy9m3IR9ZAbIFehY7NNAi133tbBfo8gonwhpZS1B2HehE4ppWL4fEgmFi4tqqYpc1GDeVU24durGtB31hUBuseGW7Ng13IXM6KX6oesfjJAaxCHS0QaPeiI1mheAKi7MU5BTA8/0z+uzdRsFIUsEMCHSmRROIfi3wS0eSsc/Gi8rlD3bumUV79wh6Vxk9WixdqvS52H3QvW0D+0jgPU0tX3ws5jhrGC/12k5Nni+BlwL/6qqYIyN0BZvXrfX9v5eHaWA8LOFj24HE6TEpDCdYjhJS8SnOcx4M=----ATTACHMENT:----ODYwODU3MDY3MzMxODQxNCA3ODk5NzQ2NzU0NTc2ODcgMjI1NDUzMTczNzEzMzc1MA==