Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created August 10, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/993fea0174dcd5abcea45ce3f1598813 to your computer and use it in GitHub Desktop.
Save tommcfarlin/993fea0174dcd5abcea45ce3f1598813 to your computer and use it in GitHub Desktop.
[WordPress] How Much Is Too Much to Pass via Dependency Injection?
<?php
class Plugin
{
protected $plugin_path;
protected $plugin_url;
private $loaded;
public function __construct($file)
{
$this->loaded = false;
$this->plugin_path = plugin_dir_path($file);
$this->plugin_url = plugin_dir_url($file);
}
public function isLoaded()
{
return $this->loaded;
}
public function load()
{
// ...
}
private function isCurrentAdminStatus()
{
// ...
}
public function getSubscribers()
{
return [
new OtherPluginClass(...)
];
}
}
<?php
class Plugin
{
protected $plugin_path;
protected $plugin_url;
private $loaded;
public function __construct($file)
{
$this->loaded = false;
$this->plugin_path = plugin_dir_path($file);
$this->plugin_url = plugin_dir_url($file);
}
public function isLoaded()
{
return $this->loaded;
}
public function load()
{
// ...
}
private function isCurrentAdminStatus()
{
// ...
}
public function getSubscribers()
{
return [
new OtherPluginClass($this)
];
}
}
<?php
class Plugin
{
protected $plugin_path;
protected $plugin_url;
private $loaded;
public function __construct($file)
{
$this->loaded = false;
$this->plugin_path = plugin_dir_path($file);
$this->plugin_url = plugin_dir_url($file);
}
public function isLoaded()
{
return $this->loaded;
}
public function load()
{
// ...
}
private function isCurrentAdminStatus()
{
// ...
}
public function getSubscribers()
{
return [
new OtherPluginClass($this->plugin_path)
];
}
}
<?php
class Plugin
{
protected $plugin_path;
protected $plugin_url;
private $loaded;
public function __construct($file)
{
$this->loaded = false;
$this->plugin_path = plugin_dir_path($file);
$this->plugin_url = plugin_dir_url($file);
}
public function isLoaded()
{
return $this->loaded;
}
public function load()
{
// ...
}
private function isCurrentAdminStatus()
{
// ...
}
public function getSubscribers()
{
return [
new OtherPluginClass($this->isCurrentAdminStatus())
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment