Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
},
"require": {
"php": "~8.4.1 || ~8.5.0",
"php": "~8.4.1 || ~8.5.0 || ~8.6.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand All @@ -30,6 +30,7 @@
"laminas/laminas-servicemanager": "^4.5",
"laminas/laminas-view": "^3.1",
"league/commonmark": "^2.10",
"mezzio/mezzio-laminasviewrenderer": "^3.0",
"psr/container": "^2.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.1",
Expand Down
216 changes: 112 additions & 104 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/autoload/commonmark.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
'internal_hosts' => [],
'open_in_new_window' => false,
'html_class' => '',
// Each of these takes 'none', 'all', 'internal' or 'external'.
'nofollow' => 'none',
// Each of these takes '' (apply to none), 'all', 'internal' or 'external'.
'nofollow' => '',
'noopener' => 'external',
'noreferrer' => 'external',
],
Expand Down
42 changes: 27 additions & 15 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
use CommonDoc\Container\BuildSiteHandlerFactory;
use CommonDoc\Container\CommandPostHandleListenerFactory;
use CommonDoc\Container\CommandPreHandleListenerFactory;
use CommonDoc\Container\DocumentViewRendererFactory;
use CommonDoc\Container\EnvironmentFactory;
use CommonDoc\Container\ExtensionPluginManager;
use CommonDoc\Container\ExtensionPluginManagerFactory;
use CommonDoc\Container\LayoutWrappingMiddlewareFactory;
use CommonDoc\Container\MarkdownConverterFactory;
use CommonDoc\Container\PageContextFactory;
use CommonDoc\Container\PageContextListenerFactory;
use CommonDoc\Container\SourceLoadingMiddlewareFactory;
use CommonDoc\Listener\CommandPostHandleListener;
use CommonDoc\Listener\CommandPreHandleListener;
use CommonDoc\Middleware\LayoutWrappingMiddleware;
use CommonDoc\Middleware\SourceLoadingMiddleware;
use CommonDoc\View\DocumentViewRenderer;
use CommonDoc\View\PageContext;
use CommonDoc\View\PageContextListener;
use League\CommonMark\ConverterInterface;
use League\CommonMark\Environment\EnvironmentInterface;
use League\CommonMark\MarkdownConverter;
Expand Down Expand Up @@ -62,8 +66,15 @@
*
* The middleware pipeline merges the same way, and the priorities are the
* ordering contract: 100 pre-handle event, 50 source loading, 1 message handler,
* 0 layout wrapping, -100 post-handle event. `SplPriorityQueue` is not stable,
* so each custom middleware needs a priority of its own rather than a shared one.
* -100 post-handle event. `SplPriorityQueue` is not stable, so the one custom
* middleware carries a priority of its own rather than a shared one.
*
* The view configuration is contributed here rather than in an autoload file for
* the same reason: a host that overrides a local file still aggregates this
* provider, so the body and layout addresses always resolve. Both are map
* entries, which is the override seam a site uses when it wants a different body
* without a code change: adding the same address to its own `templates.map`
* replaces the entry, and the map outranks the path stack.
*
* The extension plugin manager is wired here in both halves: its factory entry
* and the plugin manager's class-name key. Neither half belongs in an autoload
Expand Down Expand Up @@ -98,13 +109,14 @@
* invokables?: array<class-string, class-string>,
* }
* @type Dependencies = array{
* aliases: array<class-string, class-string>,
* aliases: array<interface-string, class-string>,
* factories: array<class-string, class-string>,
* }
* @type ViewConfig = array{template_path_stack: list<non-empty-string>}
* @type TemplateMap = array<non-empty-string, non-empty-string>
* @type ViewConfig = array{map: TemplateMap, layout: non-empty-string}
* @type ProviderConfig = array{
* dependencies: Dependencies,
* view_manager: ViewConfig,
* templates: ViewConfig,
* Webware\Console\ConsoleInterface: ConsoleConfig,
* Webware\MessageBus\MessageBusInterface: BusConfig,
* listeners: ListenerConfig,
Expand All @@ -126,10 +138,6 @@ public function getBusConfig(): array
'middleware' => SourceLoadingMiddleware::class,
'priority' => 50,
],
[
'middleware' => LayoutWrappingMiddleware::class,
'priority' => 0,
],
],
];
}
Expand All @@ -156,10 +164,12 @@ public function getDependencies(): array
BuildSiteHandler::class => BuildSiteHandlerFactory::class,
CommandPostHandleListener::class => CommandPostHandleListenerFactory::class,
CommandPreHandleListener::class => CommandPreHandleListenerFactory::class,
DocumentViewRenderer::class => DocumentViewRendererFactory::class,
EnvironmentInterface::class => EnvironmentFactory::class,
ExtensionPluginManager::class => ExtensionPluginManagerFactory::class,
LayoutWrappingMiddleware::class => LayoutWrappingMiddlewareFactory::class,
MarkdownConverter::class => MarkdownConverterFactory::class,
PageContext::class => PageContextFactory::class,
PageContextListener::class => PageContextListenerFactory::class,
SourceLoadingMiddleware::class => SourceLoadingMiddlewareFactory::class,
],
];
Expand Down Expand Up @@ -193,9 +203,11 @@ public function getListenerConfig(): array
public function getViewConfig(): array
{
return [
'template_path_stack' => [
dirname(__DIR__) . '/templates',
'map' => [
'commondoc::document' => dirname(__DIR__) . '/templates/commondoc/document.phtml',
'commondoc::layout' => dirname(__DIR__) . '/templates/commondoc/layout.phtml',
],
'layout' => 'commondoc::layout',
];
}

Expand All @@ -204,7 +216,7 @@ public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'view_manager' => $this->getViewConfig(),
'templates' => $this->getViewConfig(),
ConsoleInterface::class => $this->getConsoleConfig(),
MessageBusInterface::class => $this->getBusConfig(),
EventProvider::LISTENER_KEY => $this->getListenerConfig(),
Expand Down
44 changes: 44 additions & 0 deletions src/Container/DocumentViewRendererFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

/**
* This file is part of the commondoc package.
*
* Copyright (c) 2026 Joey Smith <jsmith@webinertia.net>
* and contributors.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CommonDoc\Container;

use CommonDoc\View\DocumentViewRenderer;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Mezzio\Template\TemplateRendererInterface;
use Override;
use Psr\Container\ContainerInterface;

/**
* Construction seam for the document view renderer.
*
* The template renderer is the framework's, so the layout, the resolver chain
* and every view helper come from the host container rather than from here.
*
* @internal
*/
final readonly class DocumentViewRendererFactory implements FactoryInterface
{
/**
* @param ?array<array-key, mixed> $options
*/
#[Override]
public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null,
): DocumentViewRenderer {
return new DocumentViewRenderer($container->get(TemplateRendererInterface::class));
}
}
16 changes: 16 additions & 0 deletions src/Container/EnvironmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

namespace CommonDoc\Container;

use CommonDoc\View\DocumentViewRenderer;
use CommonDoc\View\PageContextListener;
use Laminas\ServiceManager\Factory\FactoryInterface;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Environment\EnvironmentInterface;
use League\CommonMark\Event\DocumentPreRenderEvent;
use League\CommonMark\Exception\AlreadyInitializedException;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\ExtensionInterface;
use League\CommonMark\Node\Block\Document;
use Override;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
Expand All @@ -39,6 +43,12 @@
* constructed with the const defaults already merged into the application's
* section, so this class never re-reads the section and cannot load a name twice.
*
* The document node is then pointed at the view renderer at priority 10, so it
* outranks the core HTML renderer for the same class and the whole document is
* rendered as a view rather than as finished HTML. The page context listener is
* registered on the pre-render event, which is where the page reaches the
* document's own data. Both collaborators come from the container.
*
* @internal
*/
final readonly class EnvironmentFactory implements FactoryInterface
Expand Down Expand Up @@ -80,6 +90,12 @@
$environment->addExtension($extension);
}

$environment->addRenderer(Document::class, $container->get(DocumentViewRenderer::class), 10);

Check warning on line 93 in src/Container/EnvironmentFactory.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "IncrementInteger": @@ @@ $environment->addExtension($extension); } - $environment->addRenderer(Document::class, $container->get(DocumentViewRenderer::class), 10); + $environment->addRenderer(Document::class, $container->get(DocumentViewRenderer::class), 11); $environment->addEventListener( DocumentPreRenderEvent::class, $container->get(PageContextListener::class),

Check warning on line 93 in src/Container/EnvironmentFactory.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "DecrementInteger": @@ @@ $environment->addExtension($extension); } - $environment->addRenderer(Document::class, $container->get(DocumentViewRenderer::class), 10); + $environment->addRenderer(Document::class, $container->get(DocumentViewRenderer::class), 9); $environment->addEventListener( DocumentPreRenderEvent::class, $container->get(PageContextListener::class),
$environment->addEventListener(
DocumentPreRenderEvent::class,
$container->get(PageContextListener::class),
);

return $environment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@

namespace CommonDoc\Container;

use CommonDoc\Middleware\LayoutWrappingMiddleware;
use CommonDoc\View\PageContext;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Override;
use Psr\Container\ContainerInterface;

/**
* Construction seam for the layout wrapping middleware.
* Construction seam for the page context.
*
* This factory is load bearing: the pipeline factory skips any spec the
* container cannot resolve, so without it the middleware would vanish from the
* pipeline without an error.
* The service manager shares a factory result by default, so the listener and
* the caller that sets the page resolve the same slot.
*
* @internal
*/
final readonly class LayoutWrappingMiddlewareFactory implements FactoryInterface
final readonly class PageContextFactory implements FactoryInterface
{
/**
* @param ?array<array-key, mixed> $options
Expand All @@ -38,7 +37,7 @@ public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null,
): LayoutWrappingMiddleware {
return new LayoutWrappingMiddleware();
): PageContext {
return new PageContext();
}
}
41 changes: 41 additions & 0 deletions src/Container/PageContextListenerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/**
* This file is part of the commondoc package.
*
* Copyright (c) 2026 Joey Smith <jsmith@webinertia.net>
* and contributors.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CommonDoc\Container;

use CommonDoc\View\PageContext;
use CommonDoc\View\PageContextListener;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Override;
use Psr\Container\ContainerInterface;

/**
* Construction seam for the page context listener.
*
* @internal
*/
final readonly class PageContextListenerFactory implements FactoryInterface
{
/**
* @param ?array<array-key, mixed> $options
*/
#[Override]
public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null,
): PageContextListener {
return new PageContextListener($container->get(PageContext::class));
}
}
39 changes: 0 additions & 39 deletions src/Middleware/LayoutWrappingMiddleware.php

This file was deleted.

Loading
Loading