File: src/Generics/Socket/Endpoint.php

Recommend this page to a friend!
  Classes of Maik Greubel  >  PHP Generics  >  src/Generics/Socket/Endpoint.php  >  Download  
File: src/Generics/Socket/Endpoint.php
Role: Class source
Content type: text/plain
Description: Socket enpoint dataholder
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Add strict return types & fix socket write bug
Date: 3 years ago
Size: 1,326 bytes
 

Contents

Class file image Download
<?php

/**
 * This file is part of the PHP Generics package.
 *
 * @package Generics
 */
namespace Generics\Socket;

/**
 * This class provides a data holder for a socket endpoint
 *
 * @author Maik Greubel <greubel@nkey.de>
 */
class Endpoint
{

   
/**
     * The address for the socket
     *
     * @var string
     */
   
private $address;

   
/**
     * The port for the socket
     *
     * @var int
     */
   
private $port;

   
/**
     * Create a new endpoint
     *
     * @param string $address
     * The address for the socket
     * @param int $port
     * The port for the socket
     */
   
public function __construct($address, $port)
    {
       
$this->address = strval($address);
       
$this->port = intval($port);
    }

   
/**
     * Retrieve the address of the endpoint
     *
     * @return string The address
     */
   
public function getAddress(): string
   
{
        return
$this->address;
    }

   
/**
     * Retrieve the port of the endpoint
     *
     * @return int The port
     */
   
public function getPort(): int
   
{
        return
$this->port;
    }

   
/**
     * Retrieve the endpoint as string
     *
     * @return string
     */
   
public function __toString(): string
   
{
        return
sprintf("%s:%d", $this->address, $this->port);
    }
}


For more information send a message to info at phpclasses dot org.