GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — xmlvalid-php/src/Document.php at main · xmlvalid/xmlvalid-php

Expand file tree

/

Document.php

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
88 lines (74 loc) · 2.51 KB
/

Document.php

Copy path

File metadata and controls

88 lines (74 loc) · 2.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace Xmlvalid;
use InvalidArgumentException;
/**
* The document to validate: a local file, a string, an open stream or a
* public URL that xmlvalid downloads itself.
*
* Files and streams are sent as they are read, so a large document is never
* held in memory. XML, gzip, .zip archives, EPUB and Factur-X / ZUGFeRD PDFs
* are accepted.
*/
final class Document
{
/**
* @param resource|null $stream
*/
private function __construct(
public readonly ?string $path,
public readonly ?string $contents,
private readonly mixed $stream,
public readonly ?string $url,
public readonly string $name,
) {}
/** A file on disk. */
public static function file(string $path, ?string $name = null): self
{
if (! is_file($path) || ! is_readable($path)) {
throw new InvalidArgumentException("Cannot read the file {$path}.");
}
return new self($path, null, null, null, $name ?? basename($path));
}
/** The document's text (or bytes). */
public static function string(string $contents, string $name = 'document.xml'): self
{
return new self(null, $contents, null, null, $name);
}
/**
* An open, readable stream; it is read to the end, not closed.
*
* @param resource $stream
*/
public static function stream($stream, string $name = 'document.xml'): self
{
if (! is_resource($stream)) {
throw new InvalidArgumentException('Expected an open stream.');
}
return new self(null, null, $stream, null, $name);
}
/** A public http(s) address, downloaded by xmlvalid's servers. */
public static function url(string $url): self
{
if (! preg_match('#^https?://#i', $url)) {
throw new InvalidArgumentException("Expected an http(s) URL, got {$url}.");
}
return new self(null, null, null, $url, basename((string) parse_url($url, PHP_URL_PATH)) ?: 'document.xml');
}
public function isUrl(): bool
{
return $this->url !== null;
}
/** @return resource|null */
public function resource()
{
return $this->stream;
}
/** The Content-Type to send it with, from its name. */
public function contentType(): string
{
return preg_match('/\.(xml|xsd|rng|rdf|svg|atom|rss|xhtml|opf|ncx|plist|xlf|xliff|gpx|kml|dita|ditamap)$/i', $this->name) === 1
? 'application/xml'
: 'application/octet-stream';
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.