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

Updated use of singleton to ensure classes get used #6

Merged
merged 1 commit into from
Jun 10, 2024
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 includes/classes/MailCatcher/MailCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* Disables all emails from being sent and instead
* routes to a local mailcatcher instance if available.
*/
class MailCatcher extends Singleton {
class MailCatcher {

use Environment;
use Singleton;

/**
* SMTP hostname or IP
Expand Down
3 changes: 2 additions & 1 deletion includes/classes/RemoteFiles/RemoteFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* This class is built upon BE Media from Production so all due credit to those authors.
* http://www.github.com/billerickson/be-media-from-production
*/
class RemoteFiles extends Singleton {
class RemoteFiles {

use Environment;
use Singleton;

/**
* Production URL
Expand Down
48 changes: 30 additions & 18 deletions includes/classes/Singleton.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
<?php
/**
* Singleton definition for this plugin's classes
* Singleton trait
*
* @package Satellite
*/

namespace Eighteen73\Satellite;

/**
* Abstract class
*/
abstract class Singleton {
trait Singleton {

/**
* Return instance of class
* The class instance
*
* @return self
* @var self|null
*/
public static function instance(): Singleton {
static $instance;

if ( empty( $instance ) ) {
$class = get_called_class();
private static $instance = null;

$instance = new $class();

if ( method_exists( $instance, 'setup' ) ) {
$instance->setup();
}
/**
* Get the current instance
*
* @return Singleton
*/
final public static function instance(): self {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}

/**
* Constructor
*/
private function __construct() {
// Intentionally empty
}

return $instance;
/**
* Class clone
*
* @return void
*/
private function __clone() {
// Intentionally empty
}
}
Loading