Mike42\Escpos\PrintConnectors\WindowsPrintConnector::__construct PHP Method

__construct() public method

public __construct ( string $dest )
$dest string
    public function __construct($dest)
    {
        $this->platform = $this->getCurrentPlatform();
        $this->isLocal = false;
        $this->buffer = null;
        $this->userName = null;
        $this->userPassword = null;
        $this->workgroup = null;
        if (preg_match(self::REGEX_LOCAL, $dest) == 1) {
            // Straight to LPT1, COM1 or other local port. Allowed only if we are actually on windows.
            if ($this->platform !== self::PLATFORM_WIN) {
                throw new BadMethodCallException("WindowsPrintConnector can only be " . "used to print to a local printer ('" . $dest . "') on a Windows computer.");
            }
            $this->isLocal = true;
            $this->hostname = null;
            $this->printerName = $dest;
        } elseif (preg_match(self::REGEX_SMB, $dest) == 1) {
            // Connect to samba share, eg smb://host/printer
            $part = parse_url($dest);
            $this->hostname = $part['host'];
            /* Printer name and optional workgroup */
            $path = ltrim($part['path'], '/');
            if (strpos($path, "/") !== false) {
                $pathPart = explode("/", $path);
                $this->workgroup = $pathPart[0];
                $this->printerName = $pathPart[1];
            } else {
                $this->printerName = $path;
            }
            /* Username and password if set */
            if (isset($part['user'])) {
                $this->userName = $part['user'];
                if (isset($part['pass'])) {
                    $this->userPassword = $part['pass'];
                }
            }
        } elseif (preg_match(self::REGEX_PRINTERNAME, $dest) == 1) {
            // Just got a printer name. Assume it's on the current computer.
            $hostname = gethostname();
            if (!$hostname) {
                $hostname = "localhost";
            }
            $this->hostname = $hostname;
            $this->printerName = $dest;
        } else {
            throw new BadMethodCallException("Printer '" . $dest . "' is not a valid " . "printer name. Use local port (LPT1, COM1, etc) or smb://computer/printer notation.");
        }
        $this->buffer = array();
    }