$item) { if (! isset($item['name']) && ! is_numeric($name)) { $item['name'] = $name; } $servers[] = Port::build($item); } $this->setType($config['type'] ?? Server::class) ->setMode($config['mode'] ?? 0) ->setServers($servers) ->setProcesses($config['processes'] ?? []) ->setSettings($config['settings'] ?? []) ->setCallbacks($config['callbacks'] ?? []); } public function __set($name, $value) { $this->set($name, $value); } public function __get($name) { if (! $this->isAvailableProperty($name)) { throw new \InvalidArgumentException(sprintf('Invalid property %s', $name)); } return $this->config[$name] ?? null; } public function __call($name, $arguments) { $prefix = strtolower(substr($name, 0, 3)); if (in_array($prefix, ['set', 'get'])) { $propertyName = strtolower(substr($name, 3)); if (! $this->isAvailableProperty($propertyName)) { throw new \InvalidArgumentException(sprintf('Invalid property %s', $propertyName)); } return $prefix === 'set' ? $this->set($propertyName, ...$arguments) : $this->__get($propertyName); } throw new \InvalidArgumentException(sprintf('Invalid method %s', $name)); } public function addServer(Port $port): static { $this->config['servers'][] = $port; return $this; } public function toArray(): array { return $this->config; } protected function set($name, $value): self { if (! $this->isAvailableProperty($name)) { throw new \InvalidArgumentException(sprintf('Invalid property %s', $name)); } $this->config[$name] = $value; return $this; } private function isAvailableProperty(string $name) { return in_array($name, [ 'type', 'mode', 'servers', 'processes', 'settings', 'callbacks', ]); } }