Exemple #1
0
 /**
  * @param $tempDir
  * @param array $guzzleConfig
  * @return \GuzzleHttp\Client
  * @throws \Matyx\Guzzlette\GuzzletteException
  */
 public static function createGuzzleClient($tempDir, $guzzleConfig = [])
 {
     if (isset(static::$client)) {
         return static::$client;
     }
     if (Tracy\Debugger::isEnabled()) {
         $handler = NULL;
         if (isset($guzzleConfig['handler'])) {
             $handler = $guzzleConfig['handler'];
             if (!$handler instanceof GuzzleHttp\HandlerStack) {
                 throw new GuzzletteException("Handler must be instance of " . GuzzleHttp\HandlerStack::class);
             }
         } else {
             $handler = GuzzleHttp\HandlerStack::create();
         }
         $requestStack = new RequestStack();
         Tracy\Debugger::getBar()->addPanel(new TracyPanel($tempDir, $requestStack));
         $handler->push(function (callable $handler) use($requestStack) {
             return function ($request, array $options) use($handler, $requestStack) {
                 Tracy\Debugger::timer();
                 $guzzletteRequest = new Request();
                 $guzzletteRequest->request = $request;
                 return $handler($request, $options)->then(function ($response) use($requestStack, $guzzletteRequest) {
                     $guzzletteRequest->time = Tracy\Debugger::timer();
                     $guzzletteRequest->response = $response;
                     $requestStack->addRequest($guzzletteRequest);
                     return $response;
                 });
             };
         });
         $guzzleConfig['handler'] = $handler;
     }
     static::$client = new GuzzleHttp\Client($guzzleConfig);
     return static::$client;
 }
Exemple #2
0
 /**
  * Get the Algolia client associated with this instance.
  *
  * @return \AlgoliaSearch\Client
  */
 protected function getClient()
 {
     if (!static::$client) {
         static::$client = new \AlgoliaSearch\Client(Config::get('search.connections.algolia.config.application_id'), Config::get('search.connections.algolia.config.admin_api_key'));
     }
     return static::$client;
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $fs = new Filesystem();
     $fs->remove(__DIR__ . static::$TEMP_PATH);
     static::$client = static::createClient(['config' => static::$CONFIG_FILE]);
     static::$router = static::$kernel->getContainer()->get('router');
 }
 /**
  * Get the static HTTP client
  *
  * @param array|Traversable $options
  * @return Client
  */
 protected static function getStaticClient($options = null)
 {
     if (!isset(static::$client) || $options !== null) {
         static::$client = new Client(null, $options);
     }
     return static::$client;
 }
Exemple #5
0
 public static function setUpBeforeClass()
 {
     static::$client = static::createClient();
     static::$router = self::$client->getContainer()->get('router');
     static::$em = self::$client->getContainer()->get('doctrine.orm.entity_manager');
     static::$container = self::getContainer();
 }
Exemple #6
0
 /**
  * Singleton object getter.
  *
  * @param string $wsdl
  * @return SoapClient instance.
  */
 public static function getClient($wsdl)
 {
     if (!static::$client) {
         static::$client = new static($wsdl);
     }
     return static::$client;
 }
 /**
  * Get the Elasticsearch client associated with this instance.
  *
  * @return \Elasticsearch\Client
  */
 protected function getClient()
 {
     if (!static::$client) {
         static::$client = new \Elasticsearch\Client(Config::get('search.connections.elasticsearch.config', array()));
     }
     return static::$client;
 }
Exemple #8
0
 /**
  * Get api client for consuming api
  *
  * @return Client
  * @throws Exception
  */
 public function client()
 {
     if (!static::$client) {
         static::$client = new Client(array('base_uri' => $this->apiUrl, 'cookies' => $this->jar));
     }
     return static::$client;
 }
 /**
  * Initialize
  */
 public static function _init()
 {
     $config = \Config::load('sentry', true);
     static::$config = $config[\Fuel::$env];
     // create instance for PHP
     static::$client = new \Raven_Client(static::$config['php']['dsn']);
 }
Exemple #10
0
 /**
  * Get the Guzzle client for requests
  *
  * @return Client
  */
 protected static function getClient()
 {
     if (!static::$client) {
         static::$client = new Client('https://graph.facebook.com');
     }
     return static::$client;
 }
 protected static function getClient()
 {
     if (null === static::$client) {
         static::$client = new \SoapClient(static::$baseUrl . "?wsdl", array('location' => static::$baseUrl, 'cache_wsdl' => WSDL_CACHE_NONE));
     }
     return static::$client;
 }
Exemple #12
0
 /**
  * @param array $options
  *
  * @return BitBucketClient
  */
 protected static function getBitBucketClient(array $options = [])
 {
     if (null === static::$client || static::$client->getOptions() !== $options) {
         static::$client = new BitBucketClient($options);
     }
     return static::$client;
 }
 /**
  * Get the static HTTP client
  *
  * @return Client
  */
 protected static function getStaticClient()
 {
     if (!isset(static::$client)) {
         static::$client = new Client();
     }
     return static::$client;
 }
Exemple #14
0
 public static function auth()
 {
     $news = new Zend_Gdata_Photos();
     $svc = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
     static::$client = Zend_Gdata_ClientLogin::getHttpClient(static::$gUser, static::$gPass, $svc);
     static::$service = new Zend_Gdata_Photos(static::$client, "ANO");
 }
Exemple #15
0
 /**
  * @param string $url
  *
  * @return Client
  */
 protected static function getGitlabClient($url)
 {
     if (null === static::$client || static::$client->getBaseUrl() !== $url) {
         static::$client = new Client(trim($url, '/') . '/');
     }
     return static::$client;
 }
Exemple #16
0
 /**
  * Initialise the facade. Must be called first.
  *
  * @param string                                     $token API token.
  * @param string|int                                 $room  Room to send message to.
  * @param string                                     $from  Who the message is from.
  * @param \rcrowe\Hippy\Transport\TransportInterface $transport
  */
 public static function init($token, $room, $from, $transport = null)
 {
     if ($transport === null) {
         $transport = new Guzzle($token, $room, $from);
     }
     static::$client = new Client($transport);
     static::$queue = new Queue();
 }
Exemple #17
0
 protected function setUp()
 {
     parent::setUp();
     $this->loadFixtures($this->getFixtureFullClassNames());
     if (!static::$client) {
         static::$client = static::makeClient($authentication = true);
     }
 }
Exemple #18
0
 public static function setUpBeforeClass()
 {
     static::$client = static::createClient();
     if (static::$client->getDatabases()->exists(static::getDbName(), static::$dbStorage)) {
         static::$client->getDatabases()->drop(static::getDbName(), static::$dbStorage);
     }
     static::$db = static::$client->getDatabases()->create(static::getDbName(), static::$dbStorage);
 }
Exemple #19
0
 public static function __callStatic($method_name, $arguments)
 {
     $params = array('scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379);
     if (!static::$client) {
         static::$client = new \Predis\Client($params);
     }
     return call_user_func_array(array(static::$client, $method_name), $arguments);
 }
 /**
  * Initialization function.
  * Here a config array must be passed with the client configuration
  * Sensible values are set by default, but further configuration could also
  * be set.
  *
  * A list of required fields is also set (with no default value set)
  */
 public static function init($config = array())
 {
     $default = array('base_url' => '{scheme}://{hostname}:{port}/api/{version}/{client_endpoint}', 'scheme' => 'http', 'hostname' => 'localhost', 'port' => 9292, 'version' => 'v1', 'includes_json_root' => true, 'json_root' => 'subject');
     $required = array('client_endpoint', 'subclient_endpoint');
     $config = Collection::fromConfig($config, $default, $required);
     static::$client = new Client($config->get('base_url'), $config);
     static::$initialized = true;
 }
 protected function setUp()
 {
     static::$client = static::createClient();
     $container = static::$client->getContainer();
     $sapiToken = $container->getParameter('storage_api.test.token');
     $sapiUrl = $container->getParameter('storage_api.test.url');
     static::$client->setServerParameters(array('HTTP_X-StorageApi-Token' => $sapiToken));
 }
 /**
  * Register the 's3://' stream wrapper
  *
  * @param Aws\S3\S3Client $client
  * @param string          $protocol
  */
 public static function register(Aws\S3\S3Client $client, $protocol = 's3')
 {
     if (in_array($protocol, stream_get_wrappers())) {
         stream_wrapper_unregister($protocol);
     }
     stream_wrapper_register($protocol, __CLASS__, STREAM_IS_URL);
     static::$client = $client;
 }
Exemple #23
0
 /**
  * Attempts to open a connection to the StatsD socket
  */
 public function connect()
 {
     try {
         static::$connection = new \Domnikl\Statsd\Connection\UdpSocket('graphite', 8125);
         static::$client = new \Domnikl\Statsd\Client(static::$connection, "tune.app");
     } catch (\Exception $e) {
         // normally this would be logged and passed up through escalation and a mock statsd would swallow requests
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     $this->rollbackTransaction();
     BaseWebTestCase::tearDown();
     static::$client = null;
     static::$container = null;
     static::$kernel = null;
     $this->cleanFixtures();
 }
 /**
  * Creates if needed and returns client instance
  *
  * @param bool  $reinitialize
  * @param array $options
  *
  * @return Client
  */
 protected static function getClient($reinitialize = false, array $options = [])
 {
     if (!static::$client || $reinitialize) {
         static::$client = static::createClient($options);
     }
     // core is loaded (for tests without calling of getClient(true))
     static::$client->getKernel()->boot();
     return static::$client;
 }
 public static function tearDownAfterClass()
 {
     static::$client = null;
     static::$crawler = null;
     static::$post = null;
     // .htaccessを開発環境用に戻す
     $htaccess = DOCROOT . 'public/.htaccess';
     copy($htaccess . '_develop', $htaccess);
     touch($htaccess, filemtime($htaccess . '_develop'));
 }
 protected static function getApplication()
 {
     if (!static::$application) {
         $options = static::$options;
         static::$client = static::createClient($options);
         static::$application = new Application(static::$client->getKernel());
         static::$application->setAutoExit(false);
     }
     return static::$application;
 }
Exemple #28
0
 /**
  * Creates all database fields required to run test.
  */
 public static function setUpBeforeClass()
 {
     //Set up database and get the ids of test data
     static::$mockIds = SetUpDb::setUp();
     //Create a new guzzleHttp client
     static::$client = new Client(['base_uri' => getenv('base_uri'), 'timeout' => 10000.0]);
     //Login user to get token for other operations during test
     $response = static::$client->post('auth/login', ['exceptions' => false, 'form_params' => ['username' => 'test-root', 'password' => 'test-root']]);
     $login = json_decode($response->getBody(), true);
     static::$token = $login['token'];
 }
 /**
  * Create a new instance.
  *
  * @param  string  $client
  * @param  string  $secret
  * @param  array  $scopes
  * @param  string  $redirect
  */
 public function __construct($client, $secret, array $scopes, $redirect)
 {
     static::$client = $client;
     static::$secret = $secret;
     static::$scopes = $scopes;
     static::$redirect = $redirect;
     $this->bind('TwitchApi\\Contracts\\Request', 'TwitchApi\\Request');
     $this->bind('TwitchApi\\Contracts\\Response', 'TwitchApi\\Response');
     $this->bind('TwitchApi\\Contracts\\User', 'TwitchApi\\User');
     $this->bind('TwitchApi\\Contracts\\Channel', 'TwitchApi\\Channel');
 }
Exemple #30
0
 protected function getCollection()
 {
     if (null === static::$collection) {
         // connect
         static::$client = new \MongoClient();
         // select a database
         static::$db = static::$client->ik2;
         // select a collection (analogous to a relational database's table)
         static::$collection = static::$db->cronario_jobsss2;
     }
     return static::$collection;
 }