Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve view engines and their integration in the Admin #70

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function results()
protected function setDependencies(Container $container)
{
parent::setDependencies($container);
$this->setEmailFactory($container['email/factory']);
$this->setEmailFactory($container['admin/email/factory']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected function setDependencies(Container $container)
parent::setdependencies($container);

$this->setWidgetFactory($container['widget/factory']);
$this->setWidgetView($container['view']);
$this->setWidgetView($container['admin/view']);
}


Expand Down
15 changes: 10 additions & 5 deletions packages/admin/src/Charcoal/Admin/AdminModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function setupHandlers(
$container->extend('notFoundHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -113,7 +114,7 @@ public function setupHandlers(
$config->merge($adminConfig['handlers.notFound']);
}

$handler->setConfig($config)->init();
$handler->setView($adminView)->setConfig($config)->init();
}

return $handler;
Expand All @@ -128,6 +129,7 @@ public function setupHandlers(
$container->extend('notAllowedHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -136,7 +138,7 @@ public function setupHandlers(
$config->merge($adminConfig['handlers.notAllowed']);
}

$handler->setConfig($config)->init();
$handler->setView($adminView)->setConfig($config)->init();
}

return $handler;
Expand All @@ -151,6 +153,7 @@ public function setupHandlers(
$container->extend('phpErrorHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -159,7 +162,7 @@ public function setupHandlers(
$config->merge($adminConfig['handlers.phpError']);
}

$handler->setConfig($config)->init();
$handler->setView($adminView)->setConfig($config)->init();
}

return $handler;
Expand All @@ -174,6 +177,7 @@ public function setupHandlers(
$container->extend('errorHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -182,7 +186,7 @@ public function setupHandlers(
$config->merge($adminConfig['handlers.error']);
}

$handler->setConfig($config)->init();
$handler->setView($adminView)->setConfig($config)->init();
}

return $handler;
Expand All @@ -199,6 +203,7 @@ public function setupHandlers(
$container->extend('maintenanceHandler', function ($handler, $container) {
$appConfig = $container['config'];
$adminConfig = $container['admin/config'];
$adminView = $container['admin/view'];
if ($handler instanceof HandlerInterface) {
$config = $handler->createConfig($appConfig['handlers.defaults']);
$config->merge($adminConfig['handlers.defaults']);
Expand All @@ -207,7 +212,7 @@ public function setupHandlers(
$config->merge($adminConfig['handlers.maintenance']);
}

$handler->setConfig($config)->init();
$handler->setView($adminView)->setConfig($config)->init();
}

return $handler;
Expand Down
1 change: 1 addition & 0 deletions packages/admin/src/Charcoal/Admin/AdminWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ protected function setDependencies(Container $container)

// Satisfies AdminWidget dependencies
$this->setModelFactory($container['model/factory']);
$this->setView($container['admin/view']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ protected function setDependencies(Container $container)
$this->setTranslator($container['translator']);

// Fulfills the ViewableTrait dependencies
$this->setView($container['view']);
$this->setView($container['admin/view']);

// Fulfills the DebugAwareTrait dependencies
$this->setDebug($container['debug']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

// From Pimple
use Pimple\Container;
// From 'charcoal-view'
use Charcoal\View\ViewableInterface;
use Charcoal\View\ViewableTrait;
// From 'charcoal-translator'
use Charcoal\Translator\Translation;
// From 'charcoal-admin'
Expand All @@ -32,11 +29,8 @@
* }
* ```
*/
class MessageDisplay extends AbstractPropertyDisplay implements
ViewableInterface
class MessageDisplay extends AbstractPropertyDisplay
{
use ViewableTrait;

/**
* @var Translation|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

// from 'charcoal-admin'
use Charcoal\Admin\Property\AbstractPropertyDisplay;
// from 'charcoal-view'
use Charcoal\View\ViewableInterface;
use Charcoal\View\ViewableTrait;
// from 'pimple'
use Pimple\Container;
use UnexpectedValueException;
Expand All @@ -16,10 +13,8 @@
*
* The default display for most properties; only output {@see AbstractProperty::displayVal()}.
*/
class StatusDisplay extends AbstractPropertyDisplay implements ViewableInterface
class StatusDisplay extends AbstractPropertyDisplay
{
use ViewableTrait;

public const STATE_PRIMARY = 'primary';
public const STATE_SUCCESS = 'success';
public const STATE_INFO = 'info';
Expand Down Expand Up @@ -68,9 +63,6 @@ class StatusDisplay extends AbstractPropertyDisplay implements ViewableInterface
protected function setDependencies(Container $container)
{
parent::setDependencies($container);

// Fulfills the ViewableTrait dependencies
$this->setView($container['view']);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions packages/admin/src/Charcoal/Admin/Route/TemplateRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Charcoal\Admin\Route;

// From PSR-7
use Psr\Http\Message\RequestInterface;
// From Pimple
use Pimple\Container;
// From 'charcoal-app'
use Charcoal\App\Route\TemplateRoute as AppTemplateRoute;

class TemplateRoute extends AppTemplateRoute
{
/**
* @param Container $container A DI (Pimple) container.
* @param RequestInterface $request The request to intialize the template with.
* @return string
*/
protected function renderTemplate(Container $container, RequestInterface $request)
{
$config = $this->config();
$template = $this->createTemplate($container, $request);

return $container['admin/view']->render($config['template'], $template);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function setDependencies(Container $container)
parent::setDependencies($container);
$this->setNotificationFactory($container['model/factory']);
$this->setRevisionFactory($container['model/factory']);
$this->emailFactory = $container['email/factory'];
$this->emailFactory = $container['admin/email/factory'];
$this->userFactory = $container['model/factory'];
$this->objectFactory = $container['model/factory'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
// From 'charcoal-config'
use Charcoal\Config\ConfigInterface;
use Charcoal\Config\GenericConfig as Config;
// From email
use Charcoal\Email\Email;
use Charcoal\Email\EmailInterface;
// From 'charcoal-factory'
use Charcoal\Factory\FactoryInterface;
use Charcoal\Factory\GenericFactory;
// From 'charcoal-core'
use Charcoal\Model\Service\MetadataConfig;
// From 'charcoal-ui'
Expand All @@ -40,6 +44,7 @@
use Charcoal\View\ViewInterface;
// From 'charcoal-admin'
use Charcoal\Admin\Config as AdminConfig;
use Charcoal\Admin\Route\TemplateRoute as AdminTemplateRoute;
use Charcoal\Admin\Property\PropertyInputInterface;
use Charcoal\Admin\Property\PropertyDisplayInterface;
use Charcoal\Admin\Service\SelectizeRenderer;
Expand Down Expand Up @@ -79,6 +84,8 @@ public function register(Container $container)
$this->registerFactoryServices($container);
$this->registerElfinderServices($container);
$this->registerSelectizeServices($container);
$this->registerModelDependencies($container);
$this->registerRouteServices($container);
$this->registerMetadataExtensions($container);
$this->registerAuthExtensions($container);
$this->registerViewExtensions($container);
Expand Down Expand Up @@ -175,17 +182,40 @@ protected function registerAdminServices(Container $container)
}

/**
* Overwrite view instance.
* @param Container $container Pimple DI Container.
* @return FactoryInterface
*/
$container['admin/email/factory'] = function (Container $container): FactoryInterface {
return new GenericFactory([
'map' => [
'email' => Email::class
],
'base_class' => EmailInterface::class,
'default_class' => Email::class,
'arguments' => [[
'logger' => $container['logger'],
'config' => $container['email/config'],
'view' => $container['admin/view'],
'template_factory' => $container['template/factory'],
'queue_item_factory' => $container['model/factory'],
'log_factory' => $container['model/factory'],
'tracker' => $container['email/tracker']
]]
mcaskill marked this conversation as resolved.
Show resolved Hide resolved
]);
};

/**
* The admin view instance.
*
* @param GenericView $view The view instance.
* @param Container $container A container instance.
* @return ViewInterface
*/
$container->extend('view', function (GenericView $view, Container $container): ViewInterface {
$container['admin/view'] = function (Container $container): ViewInterface {
return new GenericView([
'engine' => $container['view/engine/mustache']
]);
});
};

/**
* Extend view/config.
Expand All @@ -203,6 +233,31 @@ protected function registerAdminServices(Container $container)
});
}

/**
* @param Container $container A Pimple DI container.
* @return void
*/
protected function registerModelDependencies(Container $container)
{
/**
* @param Container $container A Pimple DI container.
* @return array The model dependencies array.
*/
$container->extend('model/dependencies', function (array $modelDependencies, Container $container) {
$modelDependencies['view'] = $container['admin/view'];
return $modelDependencies;
});
mcaskill marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @param Container $container A service container.
* @return void
*/
protected function registerRouteServices(Container $container)
{
$container['route/controller/template/class'] = AdminTemplateRoute::class;
mcaskill marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Registers metadata extensions.
*
Expand Down Expand Up @@ -468,7 +523,7 @@ protected function registerSelectizeServices(Container $container)
'logger' => $container['logger'],
'translator' => $container['translator'],
'template_factory' => $container['template/factory'],
'view' => $container['view']
'view' => $container['admin/view']
]);
};
}
Expand Down Expand Up @@ -539,7 +594,7 @@ protected function registerFactoryServices(Container $container)
'arguments' => [[
'container' => $container,
'logger' => $container['logger'],
'view' => $container['view'],
'view' => $container['admin/view'],
'layout_builder' => $container['layout/builder']
]],
'resolver_options' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function setDependencies(Container $container)
$this->setWidgetFactory($container['widget/factory']);

// Satisfies Charcoal\View\ViewableInterface dependencies
$this->setView($container['view']);
$this->setView($container['admin/view']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected function setDependencies(Container $container)
$this->setFormInputBuilder($container['form/input/builder']);

// Satisfies ViewableInterface dependencies
$this->setView($container['view']);
$this->setView($container['admin/view']);

// Satisfies LayoutAwareInterface dependencies
$this->setLayoutBuilder($container['layout/builder']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,6 @@ protected function setDependencies(Container $container)
{
parent::setDependencies($container);

$this->setView($container['view']);
$this->setPropertyFactory($container['property/factory']);
$this->setPropertyInputFactory($container['property/input/factory']);
$this->setPropertyDisplayFactory($container['property/display/factory']);
Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/Charcoal/Admin/Widget/TableWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,6 @@ protected function setDependencies(Container $container)
// Satisfies HttpAwareTrait dependencies
$this->setHttpRequest($container['request']);

$this->setView($container['view']);
$this->setCollectionLoader($container['model/collection/loader']);
$this->setWidgetFactory($container['widget/factory']);
$this->setPropertyFactory($container['property/factory']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function container()
$containerProvider->registerModelServiceProvider($container);
$containerProvider->registerTranslatorServiceProvider($container);

$container['view'] = $this->createMock('\Charcoal\View\ViewInterface');
$container['admin/view'] = $this->createMock('\Charcoal\View\ViewInterface');

$this->container = $container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function container()
$containerProvider->registerWidgetFactory($container);
$containerProvider->registerPropertyDisplayFactory($container);

$container['view'] = $this->createMock('\Charcoal\View\ViewInterface');
$container['admin/view'] = $this->createMock('\Charcoal\View\ViewInterface');

$this->container = $container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function setDependencies(Container $container)
}

// Satisfies Charcoal\View\ViewableInterface dependencies
$this->setView($container['view']);
$this->setView($container['admin/view']);
}

/**
Expand Down
Loading