Last active
March 7, 2016 11:39
-
-
Save bobbybouwmann/a8b33ebbeec33ccd64f5 to your computer and use it in GitHub Desktop.
HRManager
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 HRManager extends Manager | |
| { | |
| protected $driver; | |
| public function __construct(Application $app, $driver) { | |
| parent::__construct($app); | |
| $this->driver = $driver; | |
| $this->driver($driver); // Create the import driver | |
| $this->driver('local'); // Create the backup driver | |
| } | |
| public function getProvider($interface) | |
| { | |
| $provider = $this->getDrivers()[$this->driver]; | |
| if ($provider instanceof $interface) { | |
| return $provider; | |
| } | |
| return $this->getDrivers()[$this->getDefaultDriver()]; | |
| } | |
| public function documents() | |
| { | |
| $provider = $this->getProvider(DocumentProvider::class); | |
| $provider->documents(); | |
| } | |
| public function user() | |
| { | |
| $provider = $this->getProvider(UserProvider::class); | |
| $provider->user(); | |
| } | |
| public function createVismaDriver() | |
| { | |
| echo 'CreateVismaProvider<br>'; | |
| return new VismaProvider(); | |
| } | |
| public function createLocalDriver() | |
| { | |
| echo 'CreateLocalDriver<br>'; | |
| return new LocalProvider(); | |
| } | |
| public function getDefaultDriver() | |
| { | |
| return 'local'; | |
| } | |
| } |
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 | |
| // Create the manager that will generate the providers | |
| $manager = new \App\HR\HRManager(app(), 'visma'); | |
| $manager->documents(); // Get the documents from the provider | |
| $manager->user(); // Get the user from the provider | |
| // Expected outcome | |
| CreateVismaProvider | |
| CreateLocalProvider | |
| Local documents | |
| Visma user |
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 LocalProvider implements DocumentProvider, UserProvider | |
| { | |
| public function documents() | |
| { | |
| echo 'Local documents<br>'; | |
| } | |
| public function user() | |
| { | |
| echo 'Local user<br>'; | |
| } | |
| } |
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 VismaProvider implements UserProvider | |
| { | |
| public function user() | |
| { | |
| echo 'Visma user<br>'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment