move admin-notices in own repository

This commit is contained in:
David Remer 2020-04-28 12:56:54 +03:00
parent 9dc3c073d2
commit 95f608bf40
11 changed files with 0 additions and 220 deletions

View file

@ -23,16 +23,11 @@
{
"type": "path",
"url": "modules.local/ppcp-wc-gateway"
},
{
"type": "path",
"url": "modules.local/ppcp-admin-notices"
}
],
"require": {
"dhii/module-interface": "0.2.x-dev",
"psr/container": "^1.0",
"inpsyde/ppcp-admin-notices": "dev-master",
"inpsyde/ppcp-button": "dev-master",
"inpsyde/ppcp-wc-gateway": "dev-master",
"oomphinc/composer-installers-extender": "^1.1",

View file

@ -1,12 +0,0 @@
{
"name": "inpsyde/ppcp-admin-notices",
"type": "inpsyde-module",
"require": {
"dhii/module-interface": "0.2.x-dev"
},
"autoload": {
"psr-4": {
"Inpsyde\\PayPalCommerce\\AdminNotices\\": "src/"
}
}
}

View file

@ -1,6 +0,0 @@
<?php
declare(strict_types=1);
return [
];

View file

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices;
use Dhii\Modular\Module\ModuleInterface;
return static function (): ModuleInterface {
return new AdminNotices();
};

View file

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Button;
use Dhii\Data\Container\ContainerInterface;
use Inpsyde\PayPalCommerce\AdminNotices\Renderer\Renderer;
use Inpsyde\PayPalCommerce\AdminNotices\Renderer\RendererInterface;
use Inpsyde\PayPalCommerce\AdminNotices\Repository\Repository;
use Inpsyde\PayPalCommerce\AdminNotices\Repository\RepositoryInterface;
use Inpsyde\PayPalCommerce\Button\Assets\DisabledSmartButton;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButtonInterface;
use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
return [
'admin-notices.renderer' => static function (ContainerInterface $container): RendererInterface {
$repository = $container->get('admin-notices.repository');
return new Renderer($repository);
},
'admin-notices.repository' => static function (ContainerInterface $container): RepositoryInterface {
return new Repository();
},
];

View file

@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices;
use Dhii\Container\ServiceProvider;
use Dhii\Modular\Module\ModuleInterface;
use Interop\Container\ServiceProviderInterface;
use Psr\Container\ContainerInterface;
class AdminNotices implements ModuleInterface
{
public function setup(): ServiceProviderInterface
{
return new ServiceProvider(
require __DIR__.'/../services.php',
require __DIR__.'/../extensions.php'
);
}
/**
* @inheritDoc
*/
public function run(ContainerInterface $container)
{
add_action(
'admin_notices',
function() use ($container) {
$renderer = $container->get('admin-notices.renderer');
$renderer->render();
}
);
}
}

View file

@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Entity;
class Message
{
private $message;
private $type;
private $dismissable;
public function __construct(string $message, string $type, bool $dismissable = true)
{
$this->type = $type;
$this->message = $message;
$this->dismissable = $dismissable;
}
public function message(): string
{
return $this->message;
}
public function type(): string
{
return $this->type;
}
public function isDismissable(): bool
{
return $this->dismissable;
}
}

View file

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Renderer;
use Inpsyde\PayPalCommerce\AdminNotices\Repository\RepositoryInterface;
class Renderer implements RendererInterface
{
private $repository;
public function __construct(RepositoryInterface $repository)
{
$this->repository = $repository;
}
public function render(): bool
{
$messages = $this->repository->currentMessages();
foreach ($messages as $message) {
printf(
'<div class="notice notice-%s %s"><p>%s</p></div>',
$message->type(),
($message->isDismissable()) ? 'is-dismissible' : '',
wp_kses_post($message->message())
);
}
return (bool) count($messages);
}
}

View file

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Renderer;
interface RendererInterface
{
public function render(): bool;
}

View file

@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Repository;
use Inpsyde\PayPalCommerce\AdminNotices\Entity\Message;
class Repository implements RepositoryInterface
{
const NOTICES_FILTER = 'ppcp.admin-notices.current-notices';
public function currentMessages(): array
{
return array_filter(
(array) apply_filters(
self::NOTICES_FILTER,
[]
),
function($element) : bool {
return is_a($element, Message::class);
}
);
}
}

View file

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Repository;
use Inpsyde\PayPalCommerce\AdminNotices\Entity\Message;
interface RepositoryInterface
{
/**
* @return Message[]
*/
public function currentMessages(): array;
}