Here is sketched simple version of your project using __get()
overloading:
<?php
class Template
{
public function name()
{
return 'Template';
}
}
class Project
{
public $template;
public function __construct(Template $template)
{
$this->template = $template;
}
}
class Plugin
{
public $project;
public function __construct(Project $project)
{
$this->project = $project;
}
// here it is. It will be called, if $template property doesn't exist in this Plugin.
public function __get($val)
{
return $this->project->$val;
}
}
class newPlugin extends Plugin { // constructor is now in plugin class
public function Something() {
echo $this->template->name(); // using this we will call __get() method because $template property doesn't exist. It will be transformed to $this->project->template->name();
}
}
$template = new Template();
$project = new Project($template);
$plugin = new newPlugin($project);
$plugin->Something();
Output:
Template