Skip to content

Instantly share code, notes, and snippets.

@bobbybouwmann
Last active March 7, 2016 11:39
Show Gist options
  • Select an option

  • Save bobbybouwmann/a8b33ebbeec33ccd64f5 to your computer and use it in GitHub Desktop.

Select an option

Save bobbybouwmann/a8b33ebbeec33ccd64f5 to your computer and use it in GitHub Desktop.
HRManager
<?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';
}
}
<?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
<?php
class LocalProvider implements DocumentProvider, UserProvider
{
public function documents()
{
echo 'Local documents<br>';
}
public function user()
{
echo 'Local user<br>';
}
}
<?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