Skip to content

Instantly share code, notes, and snippets.

@Nex-Otaku
Created February 16, 2021 14:46
Show Gist options
  • Save Nex-Otaku/7f55c16e2b5b45ca868bc6899884aac4 to your computer and use it in GitHub Desktop.
Save Nex-Otaku/7f55c16e2b5b45ca868bc6899884aac4 to your computer and use it in GitHub Desktop.
Dependency Injection supported on language level in PHP
<?php
// Now:
class Shop
{
private Log $log;
public function __construct(Log $log)
{
$this->log = $log;
}
public function createOrder(...): void
{
...
$this->log->write('Created order #' . $orderId);
}
}
// Proposed:
class Shop
{
inject Log $log;
public function createOrder(...): void
{
...
$this->log->write('Created order #' . $orderId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment