Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Last active August 29, 2015 14:25
Show Gist options
  • Save GaryJones/4be773657881860336f3 to your computer and use it in GitHub Desktop.
Save GaryJones/4be773657881860336f3 to your computer and use it in GitHub Desktop.
<?php
namespace GMJ\Foobar;
class Config extends \ArrayObject {}
<?php
namespace GMJ\Foobar;
class Plugin {
function run() {
$shortcode_config = new Config( include DT_EIA_DIR . 'config/shortcode.php', \ArrayObject::ARRAY_AS_PROPS );
$shortcodeui_config = new Config( include DT_EIA_DIR . 'config/shortcodeui.php', \ArrayObject::ARRAY_AS_PROPS );
$dependencies_config = new Config( include DT_EIA_DIR . 'config/dependencies.php', \ArrayObject::ARRAY_AS_PROPS );
$dependencies = new Dependencies( $dependencies_config );
$shortcode = new Shortcode( $shortcode_config, new Shortcode_Atts_Parser, $dependencies );
$shortcodeui = new ShortcodeUI( $shortcodeui_config, $shortcode_config->shortcode_tag );
add_action( 'init', [ $shortcode, 'register' ] );
add_action( 'init', [ $shortcodeui, 'register' ] );
add_action( 'wp_enqueue_scripts', [ $dependencies, 'register' ] );
add_action( 'admin_enqueue_scripts', [ $dependencies, 'register' ] );
add_action( 'shortcode_ui_before_do_shortcode', array( $dependencies, 'admin_output' ) );
}
}
<?php
namespace GMJ\Foobar;
class Shortcode {
protected $config;
function __construct( Config $config ) { // minimal example
$this->config = $config;
}
function tag() {
return $this->config->shortcode_tag;
}
// ...
}
@hellofromtonya
Copy link

Hey Gary,

In DT\EIA\Plugin, add use GMJ\Foobar to bring the class Config into scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment