url = $this->get_topic_url($server, $subject); if (!filter_var($this->url, FILTER_VALIDATE_URL)) { throw new TypeError('"'.$subject.'" is not property topic name.'); } } /** * That function create new subject directly from server name and * subject name. It use empty authorization method by default, but it * could be changed. When server URL is invalid throws TypeError. * * @throws TypeError When server URL is invalid. * * @param string $server URL of the server. * @param string $subject Name of the subject. * * @return subject New created subject. */ public static function create(string $server, string $subject): subject { if (!filter_var($server, FILTER_VALIDATE_URL)) { throw new TypeError('"'.$server.'" is not property URL.'); } return new self($server, $subject, new empty_authorization()); } /** * This return full subject url. * * This function return full URL to the subject. It require server * URL and subject name. * * @param string $server Server URL. * @param string $subject Subject to use. * * @return string Full subject URL. */ private function get_topic_url( string $server, string $subject ): string { if ($server[strlen($server) - 1] === '/') { return $server.$subject; } return $server.'/'.$subject; } /** * This function generate new notification to publish in subject. * * This create new notification, to publish in that subject. Content * given as parameter is content of the notofication. Notification * could be infill with more data before send, that function not sending * notification, but only create it. * * @param string $content Content of the new notification. * * @return notification New notification to infill with data and send. */ public function new_notification(string $content): notification { return new notification( $this->url, $content, $this->get_access_method() ); } }