<?php
/**
* Module creator
*/
Class Module
{
public function __construct($module)
{
$this->module = new System;
}
public function extensions($extension)
{
// In real life, we scan the $extension directory for class names
// For now we hardcode a few here
return [
'SystemSettingsProfile',
'SystemSettingsPrivacy',
'SystemSettingsAccount',
];
}
}
/**
* System service provider
*/
class System {}
/**
* System profile extensions
*/
abstract class Extension {
public function render() { return get_called_class(); }
public static function getTabs() { return get_called_class(); }
}
class SystemSettingsProfile extends Extension {}
class SystemSettingsPrivacy extends Extension {}
class SystemSettingsAccount extends Extension {}
/**
* Controller
*/
class Controller
{
public function index()
{
$extensions = (new Module('system'))->extensions('profile');
foreach($extensions as $extension)
{
$tabs[] = $extension::getTabs();
// Real-life: control structure checks if route key matches extension key
// Except now we just keep overriding $content with the last
$content = (new $extension)->render();
}
var_dump($tabs, $content);
}
}
(new Controller)->index();
Parse error: syntax error, unexpected '[' in /in/1pRTr on line 17
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/1pRTr on line 17
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/1pRTr on line 8
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/1pRTr on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/1pRTr on line 8
Process exited with code 255.