<?php
interface SessionInterface
{
public function put($key, $value);
public function push(string $key, $value);
}
class BaseHandler implements SessionInterface
{
public function put($key, $value)
{
echo 'put';
}
public function push(string $key, $value)
{
echo 'push';
}
}
class Session
{
public function __construct()
{
$config = 'BaseHandler';
if ($config == 'BaseHandler') {
// нужно использовать class BaseHandler
}
echo 'Session...';
}
}
$Session = new Session();
class Session
{
protected $handler;
public function __construct(SessionInterface $handler)
{
$this->handler = $handler;
}
}
$session = new Session(new BaseHandler);
class Session
{
public BaseHandler $Interface;
public function __construct()
{
$config = 'BaseHandler';
if ($config == 'BaseHandler') {
$this->$Interface = new BaseHandler();
$Session->$Interface->push('test1', true);
}
echo 'Session...';
}
}
$Session = new Session();
if($Session->$Interface) {
$Session->$Interface->push('test2', true);
}
<?php
interface SessionInterface
{
public function put($key, $value);
public function push(string $key, $value);
}
class BaseHandler implements SessionInterface
{
public function put($key, $value)
{
echo 'put';
}
public function push(string $key, $value)
{
echo 'push';
}
}
class Session extends BaseHandler
{
public function __construct()
{
echo 'Session...';
}
}
$Session = new Session();
// Можно использовать методы class BaseHandler