1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php
namespace hji\membership\extension\abstracts;
use hji\membership\abstracts\Component as MembershipComponent;
use hji\membership\extension\interfaces\ExtensionInterface;
abstract class Component extends MembershipComponent implements ExtensionInterface
{
public function membershipServices()
{
return parent::getServiceContainer();
}
public function services()
{
$className = get_class($this);
$parts = explode('\\', $className);
if (isset($parts[0]) && $parts[0] == 'hji' && isset($parts[1]) && !empty($parts[1]))
{
$serviceContainerClassName = "\\hji\\{$parts[1]}\\ServiceContainer";
if (class_exists($serviceContainerClassName))
{
return $this->di()->get($serviceContainerClassName);
}
}
return $this->membershipServices();
}
public function getMembershipServices()
{
_deprecated_function(__FUNCTION__, '2.2.2', $replacement='Component::membershipServices()');
return parent::getServiceContainer();
}
public function getServices()
{
_deprecated_function(__FUNCTION__, '2.2.2', $replacement='Component::services()');
return $this->services();
}
function getProjectRoute($projectNamespace = null)
{
if (!$route = $this->services()->getRouter()->getRoute())
{
return;
}
if (!$projectNamespace)
{
$trace = debug_backtrace();
if (isset($trace[1]['class']))
{
$projectNamespace = $trace[1]['class'];
}
else
{
trigger_error('Project Namespace can not be detected.', E_USER_ERROR);
}
}
$namespace = trim($projectNamespace, '\\');
$parts = explode('\\', $namespace);
$baseNamespace = $parts[0] . '\\' . $parts[1] . '\\';
$route = $this->services()->getRouter()->getRoute();
if (substr($route->controllerClassName, 0, strlen($baseNamespace)) === $baseNamespace)
{
return $route;
}
return;
}
}