move module.local to module

This commit is contained in:
David Remer 2020-09-01 14:21:58 +03:00
parent c443e4053c
commit f8e82bdfaf
217 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,3 @@
#PPCP Admin Notices
Renders current notices in the admin.

View file

@ -0,0 +1,10 @@
<?php
/**
* The extensions of the admin notice module.
*
* @package Inpsyde\PayPalCommerce\Button
*/
declare(strict_types=1);
return array();

View file

@ -0,0 +1,16 @@
<?php
/**
* The admin notice module.
*
* @package Inpsyde\PayPalCommerce\Button
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices;
use Dhii\Modular\Module\ModuleInterface;
return static function (): ModuleInterface {
return new AdminNotices();
};

View file

@ -0,0 +1,36 @@
<?php
/**
* The services of the admin notice module.
*
* @package Inpsyde\PayPalCommerce\Button
*/
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 array(
'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

@ -0,0 +1,77 @@
<?php
/**
* The message entity.
*
* @package Inpsyde\PayPalCommerce\AdminNotices\Entity
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Entity;
/**
* Class Message
*/
class Message {
/**
* The messagte text.
*
* @var string
*/
private $message;
/**
* The message type.
*
* @var string
*/
private $type;
/**
* Whether the message is dismissable.
*
* @var bool
*/
private $dismissable;
/**
* Message constructor.
*
* @param string $message The message text.
* @param string $type The message type.
* @param bool $dismissable Whether the message is dismissable.
*/
public function __construct( string $message, string $type, bool $dismissable = true ) {
$this->type = $type;
$this->message = $message;
$this->dismissable = $dismissable;
}
/**
* Returns the message text.
*
* @return string
*/
public function message(): string {
return $this->message;
}
/**
* Returns the message type.
*
* @return string
*/
public function type(): string {
return $this->type;
}
/**
* Returns whether the message is dismissable.
*
* @return bool
*/
public function is_dismissable(): bool {
return $this->dismissable;
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* The renderer.
*
* @package Inpsyde\PayPalCommerce\AdminNotices\Renderer
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Renderer;
use Inpsyde\PayPalCommerce\AdminNotices\Repository\RepositoryInterface;
/**
* Class Renderer
*/
class Renderer implements RendererInterface {
/**
* The message repository.
*
* @var RepositoryInterface
*/
private $repository;
/**
* Renderer constructor.
*
* @param RepositoryInterface $repository The message repository.
*/
public function __construct( RepositoryInterface $repository ) {
$this->repository = $repository;
}
/**
* Renders the current messages.
*
* @return bool
*/
public function render(): bool {
$messages = $this->repository->current_message();
foreach ( $messages as $message ) {
printf(
'<div class="notice notice-%s %s"><p>%s</p></div>',
$message->type(),
( $message->is_dismissable() ) ? 'is-dismissible' : '',
wp_kses_post( $message->message() )
);
}
return (bool) count( $messages );
}
}

View file

@ -0,0 +1,23 @@
<?php
/**
* The renderer interface.
*
* @package Inpsyde\PayPalCommerce\AdminNotices\Renderer
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Renderer;
/**
* Interface RendererInterface
*/
interface RendererInterface {
/**
* Renders the messages.
*
* @return bool
*/
public function render(): bool;
}

View file

@ -0,0 +1,37 @@
<?php
/**
* The message repository.
*
* @package Inpsyde\PayPalCommerce\AdminNotices\Repository
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Repository;
use Inpsyde\PayPalCommerce\AdminNotices\Entity\Message;
/**
* Class Repository
*/
class Repository implements RepositoryInterface {
const NOTICES_FILTER = 'ppcp.admin-notices.current-notices';
/**
* Returns the current messages.
*
* @return Message[]
*/
public function current_message(): array {
return array_filter(
(array) apply_filters(
self::NOTICES_FILTER,
array()
),
function( $element ) : bool {
return is_a( $element, Message::class );
}
);
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* The repository interface.
*
* @package Inpsyde\PayPalCommerce\AdminNotices\Repository
*/
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\AdminNotices\Repository;
use Inpsyde\PayPalCommerce\AdminNotices\Entity\Message;
/**
* Interface RepositoryInterface
*/
interface RepositoryInterface {
/**
* Returns the current messages.
*
* @return Message[]
*/
public function current_message(): array;
}

View file

@ -0,0 +1,48 @@
<?php
/**
* The admin notice module.
*
* @package Inpsyde\PayPalCommerce\Button
*/
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
*/
class AdminNotices implements ModuleInterface {
/**
* Sets up the module.
*
* @return ServiceProviderInterface
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider(
require __DIR__ . '/../services.php',
require __DIR__ . '/../extensions.php'
);
}
/**
* Runs the module.
*
* @param ContainerInterface $container The container.
*/
public function run( ContainerInterface $container ) {
add_action(
'admin_notices',
function() use ( $container ) {
$renderer = $container->get( 'admin-notices.renderer' );
$renderer->render();
}
);
}
}