namespace project;
abstract class Helper
{
....
}
namespace project\soft;
class Helper extends \project\Helper
{
....
}
namespace project;
abstract class Helper
{
public fucntion getMapper()
{
return new __STATIC_NAMESPACE__\Mapper(new static);
}
}
<?php
namespace project {
abstract class Helper
{
public static function getMapper()
{
$self = new static();
$ref = new \ReflectionClass($self);
$ns = $ref->getNamespaceName();
$mapper = sprintf('%s\\Mapper', $ns);
return new $mapper($self);
}
}
}
namespace project\soft {
use project\Helper as BaseHelper;
class Helper extends BaseHelper
{
}
class Mapper
{
private $helper;
public function __construct($helper)
{
$this->helper = $helper;
}
}
}
namespace {
$mapper = \project\soft\Helper::getMapper();
var_dump($mapper);
}
$self = static::Class;
$self = get_called_class();
abstract class StaticFactory
{
protected static function getForNS($class_name, ...$args)
{
$self_class = '\\'.static::Class; // (Or get_called_class())
$ns = substr($self_class, 0, strrpos($self_class, '\\'));
$class_full_name = $ns.'\\'.$class_name;
return new $class_full_name(...$args);
}
public static function getDomainObjectAssembler()
{
$self = static::Class;
return self::getForNS('DomainObjectAssembler', static::Class);
}
}