PHP code example of contenir / contenir-workflow-mezzio
1. Go to this page and download the library: Download contenir/contenir-workflow-mezzio 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/ */
contenir / contenir-workflow-mezzio example snippets
use Contenir\Workflow\ResourceInterface;
final class Page implements ResourceInterface
{
public function getSlug(): string { return $this->slug; } // "about/team"
public function getPrimaryKeys(): array { return ['page_id' => $this->id]; }
public function getType(): string { return 'page'; } // route id prefix
public function getId(): int|string { return $this->id; }
public function getChildren(): iterable { return $this->children; } // array or Traversable
/** Optional: PageWorkflow routes the page to this middleware service. */
public function getMiddleware(): ?string { return $this->handler; }
}
use Contenir\Workflow\Repository\ResourceAdapterInterface;
final class PageRepositoryAdapter implements ResourceAdapterInterface
{
public function __construct(private PageRepository $pages) {}
public function getWorkflowResources(): iterable
{
return $this->pages->findRootPages(); // top-level pages, children loaded
}
}
// config/autoload/workflow.global.php
use App\Repository\PageRepositoryAdapter;
use Contenir\Workflow\Factory\WorkflowApplicationDelegatorFactory;
use Contenir\Workflow\Strategy\ResourceStrategy;
use Mezzio\Application;
return [
'workflow_manager' => [
'strategy' => ResourceStrategy::class,
'repository' => PageRepositoryAdapter::class,
'cache' => 'FilesystemCache',
'cache_key' => 'WorkflowResourceCache',
],
'dependencies' => [
'delegators' => [
Application::class => [WorkflowApplicationDelegatorFactory::class],
],
],
];
final class PageHandler implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
$pageId = $request->getAttribute('id')['page_id'];
// load and render the page
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.