Hello, another example with "factories method"[1]:
```php
use MyProject\Framework;
abstract class AbstractController {
private const HELPER_PATH = static::namespace.'/Helpers';
private const SERVICE_PATH = static::namespace.'/Services';
public function instanceHelper( string $helperClass ) {
$helperClassName = self::HELPER_PATH."/{$helperClass}";
return new $helperClassName();
}
public function instanceService( string $serviceClass ) {
$serviceClassName = self::SERVICE_PATH."/{$serviceClass}";
return new $serviceClassName();
}
}
use MyProject\MyModule;
class Controller {
public function __invoke() {
//......
$date = $this->instanceHelper('Date');
//...
}
}
```
[1]: https://en.wikipedia.org/wiki/Factory_method_pattern
Regards
--
Manuel Canga
Zend Certified PHP Engineer
Websites: https://manuelcanga.dev | https://trasweb.net
Linkedin: https://es.linkedin.com/in/manuelcanga
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php