Skip to content

Composer, namespacing, PSR-0 autoloading #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
26 changes: 14 additions & 12 deletions README
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
_________________________

PHP FastCGI Client README
_________________________


AUTHOR & CONTACT
================

Charron Pierrick
- pierrick@webstart.fr


DOCUMENTATION & DOWNLOAD
========================

Latest version is available on github at :
- http://github.com/adoy/PHP-FastCGI-Client/

Documentation can be found on :
Documentation can be found on :
- http://github.com/adoy/PHP-FastCGI-Client/


Expand All @@ -28,13 +28,13 @@ This Code is released under the GNU LGPL

Please do not change the header of the file(s).

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License, or
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU Lesser General Public License for more details.
Expand All @@ -43,12 +43,14 @@ See the GNU Lesser General Public License for more details.
How can I use it ?
==================

require('fastcgi.php');
require 'vendor/autoload.php';

use Adoy\FastCGI\Client;

$client = new FCGIClient('localhost', '9000');
$client = new Client('localhost', '9000');
$content = 'key=value';
echo $client->request(
array(
array(
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
'REQUEST_METHOD' => 'POST',
'SCRIPT_FILENAME' => 'test.php',
Expand Down
15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "adoy/fastcgi-client",
"description": "Client for communication with a FastCGI (FCGI) application using the FastCGI protocol.",
"keywords": ["fastcgi"],
"license": "LGPL-2.1",
"authors": [
{
"name": "Pierrick Charron",
"email": "pierrick@php.net"
}
],
"autoload": {
"psr-0": { "Adoy\\FastCGI\\": "src" }
}
}
12 changes: 7 additions & 5 deletions fcgiget.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
* See the GNU Lesser General Public License for more details.
*/

require 'src/Adoy/FastCGI/Client.php';

use Adoy\FastCGI\Client;

/**
* Simple command line script to test communication with a FastCGI server
*
* @author Pierrick Charron <pierrick@webstart.fr>
* @author Remi Collet <remi@famillecollet.com>
* @version 1.0
*/
require('fastcgi.php');

if (!isset($_SERVER['argc'])) {
die("Command line only\n");
}
Expand All @@ -43,11 +45,11 @@
$url['query'] = '';
$uri = $req;
}
$client = new FCGIClient(
(isset($url['host']) ? $url['host'] : 'localhost'),
$client = new Client(
(isset($url['host']) ? $url['host'] : 'localhost'),
(isset($url['port']) ? $url['port'] : 9000));

$params = array(
$params = array(
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
'REQUEST_METHOD' => 'GET',
'SCRIPT_FILENAME' => $url['path'],
Expand Down
18 changes: 10 additions & 8 deletions fastcgi.php → src/Adoy/FastCGI/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
* See the GNU Lesser General Public License for more details.
*/

namespace Adoy\FastCGI;

/**
* Handles communication with a FastCGI application
*
* @author Pierrick Charron <pierrick@webstart.fr>
* @author Pierrick Charron <pierrick@webstart.fr>
* @version 1.0
*/
class FCGIClient
class Client
{
const VERSION_1 = 1;

Expand Down Expand Up @@ -120,7 +122,7 @@ private function connect()
if (!$this->_sock) {
$this->_sock = fsockopen($this->_host, $this->_port, $errno, $errstr, 5);
if (!$this->_sock) {
throw new Exception('Unable to connect to FastCGI application');
throw new \Exception('Unable to connect to FastCGI application');
}
}
}
Expand Down Expand Up @@ -278,7 +280,7 @@ public function getValues(array $requestedInfo)
if ($resp['type'] == self::GET_VALUES_RESULT) {
return $this->readNvpair($resp['content'], $resp['length']);
} else {
throw new Exception('Unexpected response type, expecting GET_VALUES_RESULT');
throw new \Exception('Unexpected response type, expecting GET_VALUES_RESULT');
}
}

Expand Down Expand Up @@ -320,18 +322,18 @@ public function request(array $params, $stdin)
} while ($resp && $resp['type'] != self::END_REQUEST);

if (!is_array($resp)) {
throw new Exception('Bad request');
throw new \Exception('Bad request');
}

switch (ord($resp['content']{4})) {
case self::CANT_MPX_CONN:
throw new Exception('This app can\'t multiplex [CANT_MPX_CONN]');
throw new \Exception('This app can\'t multiplex [CANT_MPX_CONN]');
break;
case self::OVERLOADED:
throw new Exception('New request rejected; too busy [OVERLOADED]');
throw new \Exception('New request rejected; too busy [OVERLOADED]');
break;
case self::UNKNOWN_ROLE:
throw new Exception('Role value not known [UNKNOWN_ROLE]');
throw new \Exception('Role value not known [UNKNOWN_ROLE]');
break;
case self::REQUEST_COMPLETE:
return $response;
Expand Down