1. Go to this page and download the library: Download brightnucleus/dependencies library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brightnucleus / dependencies example snippets
// Configure all your styles and scripts here.
$dependencies_config = [
'styles' => [ <individual style dependencies go here> ],
'scripts' => [ <individual script dependencies go here> ],
'handlers' => [
'scripts' => 'BrightNucleus\Dependency\ScriptHandler',
'styles' => 'BrightNucleus\Dependency\StyleHandler',
],
];
// Pass the Config to the 'DependencyManager', with a vendor/package prefix.
return 'BrightNucleus' => [
'Example' => [
'DependencyManager' => $dependencies_config,
],
];
namespace BrightNucleus\Example;
use BrightNucleus\Config\ConfigInterface;
use BrightNucleus\Config\ConfigTrait;
use BrightNucleus\Dependency\DependencyManager;
class ExamplePlugin {
use ConfigTrait;
/**
* Instantiate a Plugin object.
*
* @param ConfigInterface $config Config to parametrize the object.
*/
public function __construct( ConfigInterface $config ) {
$this->processConfig( $config );
}
/**
* Launch the initialization process.
*/
public function run() {
add_action( 'plugins_loaded', [ $this, 'init_dependencies' ] );
}
/**
* Initialize DependencyManager and hook it up to WordPress.
*/
public function init_dependencies() {
// Initialize dependencies.
$dependencies = new DependencyManager(
$this->config->getSubConfig( 'DependencyManager' )
);
// Register dependencies.
add_action( 'init', [ $dependencies, 'register' ] );
}
}
/**
* Register all dependencies.
*
* @param mixed $context Optional. The context to pass to the dependencies.
*/
public function register( $context = null );
class ExamplePlugin {
// <...>
/** @var BrightNucleus\Dependency\DependencyManager $dependencies */
protected $dependencies;
/**
* Initialize DependencyManager and hook it up to WordPress.
*/
public function init_dependencies() {
// Initialize dependencies.
$this->dependencies = new DependencyManager( $this->config );
// Register dependencies.
add_action( 'init', [ $this, 'register_with_context' ], 20 );
}
/**
* Register dependencies and pass collected context into them.
*/
public function register_with_context() {
$context['example_key'] = 'example_value';
$this->dependencies->register( $context );
}
}
/**
* Enqueue a single dependency retrieved by its handle.
*
* @param string $handle The dependency handle to enqueue.
* @param mixed $context Optional. The context to pass to the
* dependencies.
* @param bool $fallback Whether to fall back to dependencies registered
* outside of DependencyManager. Defaults to false.
* @return bool Returns whether the handle was found or not.
*/
public function enqueue_handle( $handle, $context = null, $fallback = false );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.