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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

abstract class WP_Notify_Aggregate_Factory {
namespace WP\Notifications;

abstract class Aggregate_Factory {

/**
* Array of factories that this aggregate factory represents.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php

class WP_Notify_Base_Notification implements WP_Notify_Notification {
namespace WP\Notifications;

use ReflectionClass;
use WP\Notifications\Messages;
use WP\Notifications\Recipients;
use WP\Notifications\Senders;

class Base_Notification implements Notification {

/**
* ID of the notification.
Expand All @@ -12,7 +19,7 @@ class WP_Notify_Base_Notification implements WP_Notify_Notification {
/**
* Sender of the notification.
*
* @var WP_Notify_Sender
* @var Senders\Sender
*/
protected $sender;

Expand All @@ -26,14 +33,14 @@ class WP_Notify_Base_Notification implements WP_Notify_Notification {
/**
* Collection of notification recipients.
*
* @var WP_Notify_Recipient_Collection
* @var Recipients\Collection
*/
protected $recipients;

/**
* Notification message.
*
* @var WP_Notify_Message
* @var Messages\Message
*/
protected $message;

Expand All @@ -42,31 +49,22 @@ class WP_Notify_Base_Notification implements WP_Notify_Notification {
*
* @var string
*/
protected $status = WP_Notify_Status::UNREAD;
protected $status = Status::UNREAD;

/**
* Instantiates a WPNotify_Base_Notification object.
* Instantiates a Base_Notification object.
*
* @param WP_Notify_Sender $sender Sender that sent the
* notification.
* @param WP_Notify_Recipient_Collection $recipients Recipients that should
* receive the
* notification.
* @param WP_Notify_Message $message Message of the
* notification.
* @param mixed $timestamp Optional. Timestamp of
* when the notification
* was triggered. Defaults
* to the moment of
* instantiation.
* @param int $id Optional. ID of the
* notification. Defaults
* to -1.
* @param Senders\Sender $sender Sender that sent the notification.
* @param Recipients\Collection $recipients Recipients that should receive the notification.
* @param Messages\Message $message Message of the notification.
* @param mixed $timestamp Optional. Timestamp of when the notification was
* triggered. Defaults to the moment of instantiation.
* @param int $id Optional. ID of the notification. Defaults to -1.
*/
public function __construct(
WP_Notify_Sender $sender,
WP_Notify_Recipient_Collection $recipients,
WP_Notify_Message $message,
Senders\Sender $sender,
Recipients\Collection $recipients,
Messages\Message $message,
$timestamp = null,
$id = - 1
) {
Expand Down Expand Up @@ -113,7 +111,7 @@ protected function validate_timestamp( $timestamp ) {
/**
* Get the sender of the notification.
*
* @return WP_Notify_Sender Sender of the notification.
* @return Senders\Sender Sender of the notification.
*/
public function get_sender() {
return $this->sender;
Expand All @@ -122,7 +120,7 @@ public function get_sender() {
/**
* Gets the recipients for the notification.
*
* @return WP_Notify_Recipient_Collection Notification recipients.
* @return Recipients\Collection Notification recipients.
*/
public function get_recipients() {
return $this->recipients;
Expand All @@ -131,7 +129,7 @@ public function get_recipients() {
/**
* Gets the message for the notification.
*
* @return WP_Notify_Message Notification message.
* @return Messages\Message Notification message.
*/
public function get_message() {
return $this->message;
Expand Down
26 changes: 16 additions & 10 deletions includes/class-wp-notify-factory.php → includes/class-factory.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
<?php

class WP_Notify_Factory {
namespace WP\Notifications;

use WP\Notifications\Messages;
use WP\Notifications\Recipients;
use WP\Notifications\Senders;

class Factory {

const MESSAGE = 'message';
const RECIPIENTS = 'recipients';

/**
* Message factory implementation to use.
*
* @var WP_Notify_Message_Factory
* @var Messages\Factory
*/
private $message_factory;

/**
* Recipient factory implementation to use.
*
* @var WP_Notify_Recipient_Factory
* @var Recipients\Factory
*/
private $recipient_factory;

/**
* Sender factory implementation to use
*
* @var WP_Notify_Sender_Factory
* @var Senders\Factory
*/
private $sender_factory;

public function __construct(
WP_Notify_Message_Factory $message_factory,
WP_Notify_Recipient_Factory $recipient_factory,
WP_Notify_Sender_Factory $sender_factory
Messages\Factory $message_factory,
Recipients\Factory $recipient_factory,
Senders\Factory $sender_factory
) {
$this->message_factory = $message_factory;
$this->recipient_factory = $recipient_factory;
Expand All @@ -41,14 +47,14 @@ public function __construct(
*
* @param $args
*
* @return WP_Notify_Base_Notification
* @return Base_Notification
*/
public function create( $args ) {

list( $message_args, $recipients_args, $sender_args ) = $this->validate( $args );

$sender = $this->sender_factory->create( $sender_args );
$recipients = new WP_Notify_Recipient_Collection();
$recipients = new Recipients\Collection();
$message = $this->message_factory->create( $message_args );

foreach ( $recipients_args as $type => $value ) {
Expand All @@ -57,7 +63,7 @@ public function create( $args ) {
);
}

return new WP_Notify_Base_Notification( $sender, $recipients, $message );
return new Base_Notification( $sender, $recipients, $message );
}

private function validate( $args ) {
Expand Down
39 changes: 22 additions & 17 deletions includes/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
* Development demo files
**/

namespace WP\Notifications;

use WP_Admin_Bar;
use WP_List_Table;

/**
* Adds WP Notify icon after the user avatar in the top admin bar in the "secondary" position
*
* @param WP_Admin_Bar $wp_admin_bar Toolbar instance.
*/
function wp_admin_bar_wp_notify_item( WP_Admin_Bar $wp_admin_bar ) {
function admin_bar_item( WP_Admin_Bar $wp_admin_bar ) {
if ( ! is_admin() ) {
return;
}
Expand All @@ -36,27 +41,27 @@ function wp_admin_bar_wp_notify_item( WP_Admin_Bar $wp_admin_bar ) {
);
$wp_admin_bar->add_node( $args );
}
add_action( 'admin_bar_menu', 'wp_admin_bar_wp_notify_item', 1 );
add_action( 'admin_bar_menu', '\WP\Notifications\admin_bar_item', 1 );

/**
* Adds WP Notify area at the top of the dashboard
*/
function wp_notify_admin_notice() {
function admin_notice() {
echo '<div id="wp-notify-dashboard" class="wrap"></div>';
}
add_action( 'admin_notices', 'wp_notify_admin_notice' );
add_action( 'admin_notices', '\WP\Notifications\admin_notice' );

/**
* Register and enqueue a wp notify scripts and stylesheet in WordPress admin.
*/
function wp_notify_enqueue_admin_assets() {
function enqueue_admin_assets() {
Comment thread
johnhooks marked this conversation as resolved.
/* Load styles */
wp_register_style( 'wp_notify_css', WP_NOTIFICATION_CENTER_PLUGIN_DIR_URL . '/build/wp-notify.css', array(), WP_NOTIFICATION_CENTER_PLUGIN_VERSION );
wp_register_style( 'wp_notify_css', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notify.css', array(), WP_FEATURE_NOTIFICATION_PLUGIN_VERSION );
wp_enqueue_style( 'wp_notify_css' );

/* Load scripts */
$asset = include WP_NOTIFICATION_CENTER_PLUGIN_DIR . '/build/wp-notify.asset.php';
wp_register_script( 'wp_notify_js', WP_NOTIFICATION_CENTER_PLUGIN_DIR_URL . '/build/wp-notify.js', $asset['dependencies'], WP_NOTIFICATION_CENTER_PLUGIN_VERSION, true );
$asset = include WP_FEATURE_NOTIFICATION_PLUGIN_DIR . '/build/wp-notify.asset.php';
wp_register_script( 'wp_notify_js', WP_FEATURE_NOTIFICATION_PLUGIN_DIR_URL . '/build/wp-notify.js', $asset['dependencies'], WP_FEATURE_NOTIFICATION_PLUGIN_VERSION, true );
wp_enqueue_script( 'wp_notify_js' );
wp_localize_script(
'wp_notify_js',
Expand All @@ -67,25 +72,25 @@ function wp_notify_enqueue_admin_assets() {
);
}

add_action( 'admin_enqueue_scripts', 'wp_notify_enqueue_admin_assets', 0 );
add_action( 'admin_enqueue_scripts', '\WP\Notifications\enqueue_admin_assets', 0 );


/**
* Registers the options page.
*
* @return void
*/
function wp_notify_add_admin_options_page() {
add_options_page( 'Notifications', 'Notifications', 'manage_options', 'wp-notify', 'wp_notify_render_admin_options_page' );
function add_admin_options_page() {
add_options_page( 'Notifications', 'Notifications', 'manage_options', 'wp-notify', '\WP\Notifications\render_admin_options_page' );
}
add_action( 'admin_menu', 'wp_notify_add_admin_options_page' );
add_action( 'admin_menu', '\WP\Notifications\add_admin_options_page' );



/**
* Renders the options page.
*/
function wp_notify_render_admin_options_page() { ?>
function render_admin_options_page() { ?>

<h1><?php _e( 'Notifications settings' ); ?></h1>

Expand Down Expand Up @@ -227,16 +232,16 @@ function init_table() {
/**
* Registers our dashboard widget.
*/
function wp_notify_dashboard_widget() {
add_meta_box( 'wp_notify', __( 'WP Notify' ), 'wp_notify_render_dashboard_widget', 'dashboard', 'side', 'high' );
function dashboard_widget() {
add_meta_box( 'wp_notify', __( 'WP Notify' ), '\WP\Notifications\render_dashboard_widget', 'dashboard', 'side', 'high' );
}
add_action( 'wp_dashboard_setup', 'wp_notify_dashboard_widget' );
add_action( 'wp_dashboard_setup', '\WP\Notifications\dashboard_widget' );


/**
* Renders our dashboard widget.
*/
function wp_notify_render_dashboard_widget() {
function render_dashboard_widget() {
?>
<div id="wp-notification-metabox">
<form id="wp-notification-metabox-form" class="initial-form hide-if-no-js">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class WP_Notify_Failed_To_Add_Recipient extends WP_Notify_Runtime_Exception {
namespace WP\Notifications\Exceptions;

class Failed_To_Add_Recipient extends Runtime_Exception {

public static function from_invalid_recipient(
$recipient
Expand All @@ -10,7 +12,7 @@ public static function from_invalid_recipient(
$message = sprintf(
/* translators: "%s" is a type of recipient. */
__(
'Failed to add invalid recipient type "%s" to recipient collection, only implementations of interface "WP_Notify_Recipient" allowed.',
'Failed to add invalid recipient type "%s" to recipient collection, only implementations of interface "Recipient" allowed.',
'wp-notification-center'
),
$type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class WP_Notify_Invalid_Recipient extends WP_Notify_Runtime_Exception {
namespace WP\Notifications\Exceptions;

class Invalid_Recipient extends Runtime_Exception {

public static function from_invalid_user_id( $user_id ) {
$type = is_object( $user_id ) ? get_class( $user_id ) : gettype( $user_id );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class WP_Notify_Invalid_Type extends WP_Notify_Runtime_Exception {
namespace WP\Notifications\Exceptions;

class Invalid_Type extends Runtime_Exception {

public static function from_message_type( $type ) {
$message = sprintf(
Expand Down
9 changes: 9 additions & 0 deletions includes/exceptions/class-runtime-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace WP\Notifications\Exceptions;

class Runtime_Exception
extends \RuntimeException
implements Exception {

}
7 changes: 0 additions & 7 deletions includes/exceptions/class-wp-notify-runtime-exception.php

This file was deleted.

7 changes: 7 additions & 0 deletions includes/exceptions/interface-exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace WP\Notifications\Exceptions;

interface Exception {

}
5 changes: 0 additions & 5 deletions includes/exceptions/interface-wp-notify-exception.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class WP_Notify_Base_Image implements WP_Notify_Image {
namespace WP\Notifications\Image;

class Base_Image implements Image {

/**
* It can be and URL of an image file or and data/image source
Expand Down Expand Up @@ -62,11 +64,11 @@ public function get_alt() {
}

/**
* Instantiates a WPNotify_BaseImage based on a JSON string
* Instantiates a BaseImage based on a JSON string
*
* @param string $json
*
* @return WP_Notify_Json_Unserializable
* @return Json_Unserializable
*/
public static function json_unserialize( $json ) {

Expand Down
Loading