1. Go to this page and download the library: Download azaharizaman/nexus-document library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
azaharizaman / nexus-document example snippets
enum DocumentType: string {
case CONTRACT = 'contract';
case INVOICE = 'invoice';
case REPORT = 'report';
case IMAGE = 'image';
case SPREADSHEET = 'spreadsheet';
case PRESENTATION = 'presentation';
case PDF = 'pdf';
case OTHER = 'other';
}
enum DocumentState: string {
case DRAFT = 'draft';
case PUBLISHED = 'published';
case ARCHIVED = 'archived';
case DELETED = 'deleted';
}
enum RelationshipType: string {
case AMENDMENT = 'amendment';
case SUPERSEDES = 'supersedes';
case RELATED = 'related';
case ATTACHMENT = 'attachment';
}
enum DocumentFormat: string {
case PDF = 'pdf';
case HTML = 'html';
case DOCX = 'docx';
}
$document = $documentManager->upload($stream, [
'original_filename' => 'scanned-document.pdf',
'mime_type' => 'application/pdf'
], $ownerId, autoAnalyze: true);
// ContentProcessorInterface::analyze() is called
// ML predicts DocumentType::INVOICE with 0.98 confidence
// Metadata automatically populated with extracted fields
try {
$stream = $documentManager->download($documentId, $userId);
// Permission verified via PermissionCheckerInterface::canView()
// Checksum verified against stored value
// Audit log created: "User downloaded document"
return response()->stream(function() use ($stream) {
fpassthru($stream);
});
} catch (PermissionDeniedException $e) {
// User lacks permission
} catch (ChecksumMismatchException $e) {
// Data corruption detected - security alert!
}
$url = $documentManager->getTemporaryDownloadUrl($documentId, $userId, ttl: 3600);
// Permission check performed first
// Delegates to StorageDriverInterface::getTemporaryUrl()
// Returns signed URL valid for 1 hour
// Audit log created: "Temporary URL generated"
use Nexus\Document\Services\VersionManager;
$versionManager = app(VersionManager::class);
$newStream = fopen('/path/to/invoice-revised.pdf', 'r');
$version = $versionManager->createVersion(
$documentId,
$newStream,
'Updated vendor address and payment terms',
$userId
);
// New version created: {tenantId}/2025/11/{uuid}/v2.pdf
// Document version incremented to 2
// Version history preserved
// Audit log created: "Version 2 created by User X"
use Nexus\Document\Services\RelationshipManager;
use Nexus\Document\ValueObjects\RelationshipType;
$relationshipManager = app(RelationshipManager::class);
$relationship = $relationshipManager->createRelationship(
$invoiceDocId,
$receiptDocId,
RelationshipType::RELATED,
$userId
);
// Link created between invoice and receipt
// Permission verified on source document
// Audit log created: "Relationship created"
use Nexus\Document\Services\DocumentSearchService;
use Nexus\Document\ValueObjects\DocumentType;
$searchService = app(DocumentSearchService::class);
// Search by tags
$documents = $searchService->findByTags(['finance', 'urgent'], $userId);
// Search by type with filters
$documents = $searchService->findByType(
DocumentType::INVOICE,
[
'dateFrom' => '2025-01-01',
'dateTo' => '2025-12-31',
'ownerId' => $userId
],
$userId
);
// Search by metadata
$documents = $searchService->findByMetadata([
'customFields.vendor_id' => 'VND-001',
'customFields.amount' => ['>=', 1000.00]
], $userId);
// All results filtered by permissions and tenant scope
interface ContentProcessorInterface
{
/**
* Render data into a document format (e.g., Service Report to PDF)
*/
public function render(
string $templateName,
array $data,
DocumentFormat $format
): string;
/**
* Analyze document content using ML (OCR, classification, metadata extraction)
*/
public function analyze(string $documentPath): ContentAnalysisResult;
}
// No Intelligence package configured
$result = $contentProcessor->analyze($documentPath);
// Returns: ContentAnalysisResult with null predictions and 0.0 confidence
$this->app->singleton(
ContentProcessorInterface::class,
IntelligenceContentProcessor::class
);
// Now analyze() calls ML models for real predictions
// Now render() generates professional PDFs from templates
// apps/Atomy/app/Models/Document.php
class Document extends Model implements DocumentInterface
{
use SoftDeletes;
protected $casts = [
'metadata' => 'array',
'type' => DocumentType::class,
'state' => DocumentState::class
];
// Tenant scoping applied automatically in booted()
}
// apps/Atomy/app/Repositories/DbDocumentRepository.php
class DbDocumentRepository implements DocumentRepositoryInterface
{
public function findById(string $id): ?DocumentInterface
{
return Document::find($id);
}
// ... other methods using Eloquent
}
// apps/Atomy/app/Providers/DocumentServiceProvider.php
class DocumentServiceProvider extends ServiceProvider
{
public function register(): void
{
// Bind repositories
$this->app->singleton(
DocumentRepositoryInterface::class,
DbDocumentRepository::class
);
// Bind services
$this->app->singleton(
PermissionCheckerInterface::class,
DocumentPermissionChecker::class
);
$this->app->singleton(
ContentProcessorInterface::class,
NullContentProcessor::class // Override when Intelligence available
);
// Register package services
$this->app->singleton(DocumentManager::class);
$this->app->singleton(VersionManager::class);
$this->app->singleton(RelationshipManager::class);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.