2017 © Pedro Pelรกez
 

library http

Http wrapper

image

bolster/http

Http wrapper

  • Wednesday, October 25, 2017
  • by Leko
  • Repository
  • 1 Watchers
  • 0 Stars
  • 193 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Caution

[[DEPRECATED]] This repository is no longer maintained. We'll delete this repository & unpublish package at 2017/12/31., (*1)

Bolster PHP http module

What is Bolster

Bolsterใฏใ€้•ทๆž•ใƒปๆ”ฏๆŒๆใฎใ‚ˆใ†ใชๆ„ๅ‘ณใŒใ‚ใ‚Šใพใ™ใ€‚
้–‹็™บ่€…ใ‚’ๆ”ฏใˆใฆไผ‘ใพใ›ใ‚‹ใ€ใใ‚“ใชใƒฉใ‚คใƒ–ใƒฉใƒช้ƒกใ‚’็‹™ใฃใŸๅๅ‰ใงใ™, (*2)

http://ejje.weblio.jp/content/bolster, (*3)

class structure

Bolster\
โ”œโ”€โ”€ Http\
โ”‚ย ย  โ”œโ”€โ”€ Parser\
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ JsonParser.php
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ ParserInterface.php
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ PlainParser.php
โ”‚ย ย  โ”œโ”€โ”€ Request.php
โ”‚ย ย  โ””โ”€โ”€ Response.php
โ””โ”€โ”€ Http.php

install

add your composer.json to, (*4)

{
    "require": {
        "bolster/http": "0.8"
    }
}

usage

basic

<?php
$http = new Bolster\Http();
$response = $http->get('https://qiita.com/api/v1/users/L_e_k_o');

echo $response;

stdout:, (*5)

{"id":3338,"url_name":"L_e_k_o","profile_image_url":"https://pbs.twimg.com/profile_images/453306597716930561/fcy5Qh53_normal.jpeg",...

with http header and response parser

<?php
$http = new Bolster\Http();

$parser = new Bolster\Http\Parser\JsonParser();
$http->setParser($parser);

$http->setHeaders('Accept',     'application/vnd.github.v3+json');
$http->setHeaders('User-Agent', 'Bolster-Http-Module');

$json = $http->get('https://api.github.com/users/Leko');

var_dump($json);

stdout:, (*6)

array(30) {
  'login' =>
  string(4) "Leko"
  'id' =>
  int(1424963)
  'avatar_url' =>
  string(51) "https://avatars.githubusercontent.com/u/1424963?v=2"
  'gravatar_id' =>
  string(32) "13fbd31a4503c352369aab017e3edef7"
  'url' =>
  string(33) "https://api.github.com/users/Leko"
  ...

with context option

<?php

$http = new Bolster\Http();

$http->setHttpContextOptions('ignore_errors', false);
$http->get('http://hogehoge.com/404');

throw errors:, (*7)

PHP Warning:  file_get_contents(http://hogehoge.com/404?): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
 in /PATH/TO/source/Bolster/Http/Request.php on line 101
PHP Stack trace: ...

The Versions

25/10 2017

dev-master

9999999-dev

Http wrapper

  Sources   Download

MIT

The Development Requires

by Avatar Leko

07/10 2014

1.0

1.0.0.0

Http wrapper

  Sources   Download

MIT

The Development Requires

by Avatar Leko

29/08 2014

0.9

0.9.0.0

Http wrapper

  Sources   Download

MIT

The Development Requires

by Avatar Leko

27/08 2014

0.8

0.8.0.0

Http wrapper

  Sources   Download

MIT

The Development Requires

by Avatar Leko