Last active
March 9, 2017 03:12
-
-
Save karptonite/cd4ae1bd59118e3f182d14472a4fe5db to your computer and use it in GitHub Desktop.
Use case for parameters for container
This file contains 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 GeekDB_Fetcher_Factory | |
{ | |
public function create( $type, $setupData = null ) | |
{ | |
switch ($type) | |
{ | |
case 'direct': | |
return new GeekDB_Fetcher_Direct( $setupData ); | |
break; | |
case 'queued': | |
return $GLOBALS['container']->make( 'GeekDB_Fetcher_Queued', $setupData ); | |
break ; | |
default: | |
throw new Exception("Invalid GeekDB_Fetcher Type"); | |
break; | |
} | |
} | |
} |
This file contains 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 GeekDB_Fetcher_Queued extends GeekDB_Fetcher | |
{ | |
protected $_queue; | |
protected $_queuehandle; | |
protected $_resultobj; | |
public function __construct( \Geek\Queue\GearmanQueue $queue, $setupData ) | |
{ | |
$this->_queue = $queue; | |
parent::__construct( $setupData ); | |
} |
This file contains 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 | |
// from my setup | |
$container->bind( 'GeekDB_Fetcher_Queued', function ( $container, $setupData ) | |
{ | |
$queue = $container->make( 'Geek\Queue\GearmanQueue' ); | |
return new GeekDB_Fetcher_Queued( $queue, $setupData ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment