| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | <?phpnamespace phpnotify;use \TypeError as TypeError;/** * This represents notification server, in library named notifier. *  * This class represents notification server in the system. It is required * to subscribe new subject. It also store auth service like login and  * password, or auth token. That class would be used to generate new subjects * with same server url, and potentially same authorization methods. It makes  * generating that subjects much easier, without passing same authentication  * and server URL to all new subjects. Change authentication method in new  * subject generated by notifier would not change notifier authentication * method. */class notifier extends authorization_store {    /**     * This store URL of the notifications server.     * @var string     */    private string $url;    /**      * This function initialize new notifier by the server URL.     *     * This create new notifications server wrapper, from that URL. It      * use empty authorization as default authorization method. URL is      * validating, and when incorrect URL format had been incorrect throws     * TypeError.     *      * @throws TypeError When URL is bad formated.     *     * @param string URL of the server.     */    public function __construct(string $url) {        parent::__construct();                if (!filter_var($url, FILTER_VALIDATE_URL)) {            throw new TypeError('"'.$url.'" is not property URL.');        }                $this->url = $url;    }    /**     * This function create new notifier from URL.     *      * That function create new notifier from URL, but it not use 'new'      * keyword, which results in the better look code with chainloading.     * It use same constructor as {@see notifier::__construct}.     *     * @throws TypeError Whem URL is bad formated.     *     * @param string $url URL for the notifications server.     * @return notifier New notification server.     */    public static function create(string $url): object {        return new self($url);    }    /**      * This function would be use to select a subject.     *      * This function select a subject to notify in. It return new subject      * which is initialized from notifier URL and authorization method.     * When authorization method of the subject had been changed, notifier      * still use own authorization method for new subjects.     *     * @param string $subject Name of the subject to use.     *     * @return subject New subject to send notifications in.     */    public function topic(string $subject): subject {        return new subject(            $this->url,             $subject,             $this->get_access_method()        );    }}
 |