4ZNGPOZ $BLF1)1 -BSBWFM :JJ $PEF*HOJUFS 3PVUJOH P P P P P %BUBCBTF P P P P P 03. P P P P $BDIF P P P P P 7JFXIFMQFST P P P P P 'PSNWBMJEBUJPO P P P P P -PHHJOH P P P P P $43'QSPUFDUJPO P P P P P 5FTUTVQQPSU P P P P P %FCVH6* P P P P *:3rd party
namespace Psr\Log; interface LoggerInterface { public function emergency($message, array $context = array()); public function alert($message, array $context = array()); public function critical($message, array $context = array()); public function error($message, array $context = array()); public function warning($message, array $context = array()); public function notice($message, array $context = array()); public function info($message, array $context = array()); public function debug($message, array $context = array()); public function log($level, $message, array $context = array()); } ྫ 143-PHHFS*OUFSGBDF
1.3 Recommended usage Users SHOULD NOT pass a container into an object so that the object can retrieve its own dependencies. This means the container is used as a Service Locator which is a pattern that is generally discouraged.
class Foo { protected $logger; public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } public function bar() { $this->logger->error('...'); } } ʮऔΓʹߦ͔ͳ͍ʯ ʮ༩͑ͯΒ͏ʯ
$container->set('foo', function () use ($container) { $object = new Foo(); $object->setLogger($container->get('logger')); return $object; }); class Foo { public function setLogger(LoggerInterface $logger) public function bar() } ੜ ༻ ˞͜ΕઃఆϑΝΠϧͳͷͰػೳ࣮Ͱ͋Γ·ͤΜ