Created
September 9, 2015 04:49
-
-
Save GwendolenLynch/2a2266525cd61a5edfd0 to your computer and use it in GitHub Desktop.
Before middleware to load Guzzle 6.
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 | |
use Silex\Application; | |
use Silex\ControllerProviderInterface; | |
/** | |
* Controller. | |
* | |
* @author Gawain Lynch <gawain.lynch@gmail.com> | |
*/ | |
class Controller implements ControllerProviderInterface | |
{ | |
/** | |
* @param \Silex\Application $app | |
* | |
* @return \Silex\ControllerCollection | |
*/ | |
public function connect(Application $app) | |
{ | |
/** @var $ctr \Silex\ControllerCollection */ | |
$ctr = $app['controllers_factory'] | |
->before([$this, 'before']); | |
$ctr->match('/', [$this, 'myCallback']) | |
->method('GET|POST'); | |
return $ctr; | |
} | |
/** | |
* Before middleware to load Guzzle 6. | |
*/ | |
public function before() | |
{ | |
$baseDir = dirname(dirname(__DIR__)); | |
require $baseDir . '/lib/GuzzleHttp/Guzzle/functions_include.php'; | |
require $baseDir . '/lib/GuzzleHttp/Promise/functions_include.php'; | |
require $baseDir . '/lib/GuzzleHttp/Psr7/functions_include.php'; | |
$loader = new \Composer\Autoload\ClassLoader(); | |
$loader->setPsr4('GuzzleHttp\\', [ | |
$baseDir . '/lib/GuzzleHttp/Guzzle', | |
$baseDir . '/lib/GuzzleHttp/Promise', | |
$baseDir . '/lib/GuzzleHttp/Psr7', | |
]); | |
$loader->register(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment