1. Go to this page and download the library: Download azaharizaman/nexus-content 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-content example snippets
use Nexus\Content\Services\ArticleManager;
use Nexus\Content\ValueObjects\ArticleCategory;
// Inject dependencies (see Integration Guide)
$articleManager = new ArticleManager($repository, $searchEngine);
// Create category
$category = ArticleCategory::createRoot(
categoryId: 'cat-001',
name: 'Getting Started',
slug: 'getting-started',
description: 'Beginner guides and tutorials'
);
// Create article with initial draft
$article = $articleManager->createArticle(
articleId: 'art-001',
title: 'How to Get Started',
slug: 'how-to-get-started',
category: $category,
textContent: '# Getting Started\n\nWelcome to our platform...',
authorId: 'user-123',
isPublic: true
);
// Publish latest draft
$publishedArticle = $articleManager->publish('art-001');
// Article is now searchable via ContentSearchInterface
$updatedArticle = $articleManager->updateContent(
articleId: 'art-001',
textContent: '# Getting Started\n\nUpdated content...',
authorId: 'user-123'
);
// New draft version created, previous version preserved in history
// Submit for review
$article = $articleManager->submitForReview('art-001');
// Approve and publish
$article = $articleManager->publish('art-001');
// Create and publish in one flow
$article = $articleManager->createArticle(/* ... */);
$publishedArticle = $articleManager->publish($article->articleId);
// Get canonical URL
$url = $articleManager->getCanonicalUrl($article, 'https://kb.example.com');
// Returns: https://kb.example.com/kb/how-to-get-started
// app/Repositories/EloquentContentRepository.php
namespace App\Repositories;
use Nexus\Content\Contracts\ContentRepositoryInterface;
use Nexus\Content\ValueObjects\Article;
use App\Models\Article as ArticleModel;
final class EloquentContentRepository implements ContentRepositoryInterface
{
public function saveArticle(Article $article): void
{
ArticleModel::updateOrCreate(
['article_id' => $article->articleId],
[
'title' => $article->title,
'slug' => $article->slug,
'category_id' => $article->category->categoryId,
'is_public' => $article->isPublic,
'version_history' => json_encode($article->versionHistory),
// ... other fields
]
);
}
public function findById(string $articleId): ?Article
{
$model = ArticleModel::where('article_id', $articleId)->first();
if (!$model) {
return null;
}
// Reconstruct Article value object from model
return $this->hydrateArticle($model);
}
// ... implement other methods
}
// app/Providers/ContentServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Nexus\Content\Contracts\ContentRepositoryInterface;
use Nexus\Content\Contracts\ContentSearchInterface;
use App\Repositories\EloquentContentRepository;
use App\Services\MeilisearchContentSearch;
class ContentServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(ContentRepositoryInterface::class, EloquentContentRepository::class);
$this->app->singleton(ContentSearchInterface::class, MeilisearchContentSearch::class);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.