Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GwendolenLynch
Created September 9, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GwendolenLynch/2a2266525cd61a5edfd0 to your computer and use it in GitHub Desktop.
Save GwendolenLynch/2a2266525cd61a5edfd0 to your computer and use it in GitHub Desktop.
Before middleware to load Guzzle 6.
<?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