mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 17:52:25 +01:00
30 lines
542 B
PHP
30 lines
542 B
PHP
<?php
|
|
|
|
/*
|
|
* DesignPatternPHP
|
|
*/
|
|
|
|
namespace DesignPatterns\NullObject;
|
|
|
|
/**
|
|
* Service is dummy service that uses a logger
|
|
*/
|
|
class Service
|
|
{
|
|
|
|
protected $logger;
|
|
|
|
// we inject the logger in ctor and it is mandatory
|
|
public function __construct(LoggerInterface $log)
|
|
{
|
|
$this->logger = $log;
|
|
}
|
|
|
|
public function doSomething()
|
|
{
|
|
// no more check "if (!is_null($this->logger))..." with the NullObject pattern
|
|
$this->logger->log('We are in ' . __METHOD__);
|
|
// something to do...
|
|
}
|
|
|
|
} |