Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active August 4, 2022 08:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/9bd9884ed7a02eab1b34f1c328f7d4d7 to your computer and use it in GitHub Desktop.
Save Shelob9/9bd9884ed7a02eab1b34f1c328f7d4d7 to your computer and use it in GitHub Desktop.
composer require illuminate/container
<?php
namespace Candles;
use Illuminate\Container\Container;
class Plugin extends Container
{
}
<?php
namespace Candles;
use Illuminate\Container\Container;
class Plugin
{
protected $container;
public function __construct(){
$this->container = new Container();
}
public function getContainer(){
return $this->container;
}
}
<?php
use Caldles\Plugin;
/**
* Get main plugin class
*
* @return Plugin
*/
function candle(){
static $candle;
if( ! $candle ){
$candle = new Plugin();
do_action( "candle", $candle );
}
return $candle;
}
<?php
use Candles\ApiClient;
$client = candle()->make( ApiClient::class );
<?php
use Caldles\Plugin;
use Candles\ApiClient;
add_action( 'candle', function($candle){
$api = new ApiClient(
'key'
);
$candle->instance( ApiClient::class, $api);
});
<?php
use Caldles\Product;
$product = candle()->make( Product::class, ['Space Person Toy'] );
<?php
use Caldles\Product;
add_action( 'candle', function($candle){
$candle->bind( Product::class, function($plugin,$args){
return new Product($args[0]);
});
});
<?php
use Caldles\Product;
add_action( 'candle', function($candle){
$candle->bind( Product::class, function($plugin,$args){
return new Product(...$args);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment