Skip to content

Commit

Permalink
Allow developer to external access to plugin instance
Browse files Browse the repository at this point in the history
Instead create new instance by `new Loader()` use new instance container `Simpleshop::getInstance()`.
It makes container to prevent re-create it twice.
Developer still can force create new instance via argument $instanceId (`Simpleshop::getInstance('test')`).
  • Loading branch information
jakubboucek committed Oct 13, 2019
1 parent c0157fd commit d684e1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion simpleshop-cz.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
/**
* Start plugin
*/
new Plugin();
SimpleShop::getInstance();
34 changes: 34 additions & 0 deletions src/SimpleShop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* @package Redbit\SimpleShop\WpPlugin
* @license MIT
* @copyright 2016-2019 Redbit s.r.o.
* @author Redbit s.r.o. <[email protected]>
*/

namespace Redbit\SimpleShop\WpPlugin;

class SimpleShop {
/**
* @var Plugin
*/
private static $instance = [];

/**
* @return Plugin
*/
public static function getInstance() {
if ( self::$instance === null ) {
self::$instance = self::factory();
}

return self::$instance;
}

/**
* @return Plugin
*/
protected static function factory() {
return new Plugin();
}
}

0 comments on commit d684e1e

Please sign in to comment.