Last active
August 4, 2022 08:29
-
-
Save Shelob9/9bd9884ed7a02eab1b34f1c328f7d4d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
composer require illuminate/container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Candles; | |
use Illuminate\Container\Container; | |
class Plugin extends Container | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Candles; | |
use Illuminate\Container\Container; | |
class Plugin | |
{ | |
protected $container; | |
public function __construct(){ | |
$this->container = new Container(); | |
} | |
public function getContainer(){ | |
return $this->container; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Candles\ApiClient; | |
$client = candle()->make( ApiClient::class ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Caldles\Plugin; | |
use Candles\ApiClient; | |
add_action( 'candle', function($candle){ | |
$api = new ApiClient( | |
'key' | |
); | |
$candle->instance( ApiClient::class, $api); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Caldles\Product; | |
$product = candle()->make( Product::class, ['Space Person Toy'] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Caldles\Product; | |
add_action( 'candle', function($candle){ | |
$candle->bind( Product::class, function($plugin,$args){ | |
return new Product($args[0]); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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