mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-09 00:16:32 +02:00
start a restructure
This commit is contained in:
34
Behavioral/NullObject/Service.php
Normal file
34
Behavioral/NullObject/Service.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\NullObject;
|
||||
|
||||
/**
|
||||
* Service is dummy service that uses a logger
|
||||
*/
|
||||
class Service
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* we inject the logger in ctor and it is mandatory
|
||||
*
|
||||
* @param LoggerInterface $log
|
||||
*/
|
||||
public function __construct(LoggerInterface $log)
|
||||
{
|
||||
$this->logger = $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* do something ...
|
||||
*/
|
||||
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...
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user