mirror of
https://github.com/namibia/awesome-cheatsheets.git
synced 2024-11-28 15:56:36 +00:00
Merge pull request #89 from arkadiusjonczek/master
Add trait example to php language
This commit is contained in:
commit
92b9bd8403
@ -303,3 +303,39 @@ abstract class AbstractClassName
|
|||||||
abstract function abstractFunction(Type $var = null): Type;
|
abstract function abstractFunction(Type $var = null): Type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic Implementation of LoggerAwareInterface.
|
||||||
|
* @see https://github.com/php-fig/log/blob/master/Psr/Log/LoggerAwareTrait.php
|
||||||
|
*/
|
||||||
|
trait LoggerAwareTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The logger instance.
|
||||||
|
*
|
||||||
|
* @var LoggerInterface
|
||||||
|
*/
|
||||||
|
protected $logger;
|
||||||
|
/**
|
||||||
|
* Sets a logger.
|
||||||
|
*
|
||||||
|
* @param LoggerInterface $logger
|
||||||
|
*/
|
||||||
|
public function setLogger(LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example with use of LoggerAwareTrait.
|
||||||
|
*/
|
||||||
|
class ClassWithLogger
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Use the LoggerAwareTrait in this class.
|
||||||
|
*/
|
||||||
|
use LoggerAwareTrait;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user