pdftract/sdk/php/src/Pdftract/Source.php
jedarden 246befd8d1 feat(pdftract-2m3gl): implement PHP SDK with Packagist publishing
- Add jedarden/pdftract Composer package (sdk/php/)
- Implement Client.php with proc_open subprocess execution
- Add PSR-3 LoggerInterface integration (defaults to NullLogger)
- Add 9 contract methods: extract, extractText, extractMarkdown, extractStream, search, getMetadata, hash, classify, verifyReceipt
- Add readonly model classes: Document, Page, Metadata, Fingerprint, Classification, Match, Receipt
- Add exception classes: PdftractException base + 8 subclasses
- Add PHPUnit conformance test suite
- Add phpunit.xml configuration
- Add composer.json with jedarden/pdftract package name
- Add .ci/argo-workflows/pdftract-php-publish.yaml (Packagist auto-discovery from git tags)

Also includes Ruby SDK scaffold from parallel workflow.

Closes pdftract-2m3gl
2026-06-01 10:27:03 -04:00

74 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Jedarden\Pdftract;
/**
* Source specification for pdftract commands
*
* Represents a PDF source (file path, URL, or stdin)
*/
class Source
{
private string $type;
private string $value;
/**
* Constructor
*
* @param string $type Source type: 'file', 'url', or 'stdin'
* @param string $value File path, URL, or '-' for stdin
*/
private function __construct(string $type, string $value)
{
$this->type = $type;
$this->value = $value;
}
/**
* Create a file source
*
* @param string $path Path to PDF file
* @return self
*/
public static function file(string $path): self
{
return new self('file', $path);
}
/**
* Create a URL source
*
* @param string $url URL to PDF
* @return self
*/
public static function url(string $url): self
{
return new self('url', $url);
}
/**
* Create a stdin source
*
* @return self
*/
public static function stdin(): self
{
return new self('stdin', '-');
}
/**
* Convert source to CLI arguments
*
* @return array CLI arguments
*/
public function toArgs(): array
{
if ($this->type === 'url') {
return ['--url', $this->value];
}
return [$this->value];
}
}