Skip to content

Instantly share code, notes, and snippets.

@karptonite
Last active March 9, 2017 03:12
Show Gist options
  • Save karptonite/cd4ae1bd59118e3f182d14472a4fe5db to your computer and use it in GitHub Desktop.
Save karptonite/cd4ae1bd59118e3f182d14472a4fe5db to your computer and use it in GitHub Desktop.
Use case for parameters for container
<?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;
}
}
}
<?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 );
}
<?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