Last active
October 20, 2016 10:15
-
-
Save lucasdavies/44031115f18dc00b1cb75849032dbb00 to your computer and use it in GitHub Desktop.
Example of a Service Locator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserRepository | |
{ | |
public function __construct(Container $container) | |
{ | |
$this->container = $container; | |
} | |
public function getUser($id) | |
{ | |
$db = $this->container->get('db'); | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from http://shadowhand.me/dependency-injection-with-auryn/