friendship ended with social-app. php is my new best friend
1<?php
2/**
3 * Interface SettingsContainerInterface
4 *
5 * @created 28.08.2018
6 * @author Smiley <smiley@chillerlan.net>
7 * @copyright 2018 Smiley
8 * @license MIT
9 */
10declare(strict_types=1);
11
12namespace chillerlan\Settings;
13
14use JsonSerializable, Serializable;
15
16/**
17 * a generic container with magic getter and setter
18 */
19interface SettingsContainerInterface extends JsonSerializable, Serializable{
20
21 /**
22 * Retrieve the value of $property
23 *
24 * @return mixed|null
25 */
26 public function __get(string $property):mixed;
27
28 /**
29 * Set $property to $value while avoiding private and non-existing properties
30 */
31 public function __set(string $property, mixed $value):void;
32
33 /**
34 * Checks if $property is set (aka. not null), excluding private properties
35 */
36 public function __isset(string $property):bool;
37
38 /**
39 * Unsets $property while avoiding private and non-existing properties
40 */
41 public function __unset(string $property):void;
42
43 /**
44 * @see \chillerlan\Settings\SettingsContainerInterface::toJSON()
45 */
46 public function __toString():string;
47
48 /**
49 * Returns an array representation of the settings object
50 *
51 * The values will be run through the magic __get(), which may also call custom getters.
52 *
53 * @return array<string, mixed>
54 */
55 public function toArray():array;
56
57 /**
58 * Sets properties from a given iterable
59 *
60 * The values will be run through the magic __set(), which may also call custom setters.
61 *
62 * @phpstan-param array<string, mixed> $properties
63 */
64 public function fromIterable(iterable $properties):static;
65
66 /**
67 * Returns a JSON representation of the settings object
68 *
69 * @see \json_encode()
70 * @see \chillerlan\Settings\SettingsContainerInterface::toArray()
71 *
72 * @throws \JsonException
73 */
74 public function toJSON(int|null $jsonOptions = null):string;
75
76 /**
77 * Sets properties from a given JSON string
78 *
79 * @see \chillerlan\Settings\SettingsContainerInterface::fromIterable()
80 *
81 * @throws \Exception
82 * @throws \JsonException
83 */
84 public function fromJSON(string $json):static;
85
86}