Skip to content

Commit 451308a

Browse files
committed
feat: Use psr 17 & psr 18
1 parent a694993 commit 451308a

10 files changed

Lines changed: 130 additions & 176 deletions

.php-cs-fixer.dist.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@
327327
'ternary_to_null_coalescing' => true,
328328
'trailing_comma_in_multiline' => [
329329
'elements' => [
330-
'arguments',
331330
'arrays',
332331
'match',
333332
]

Readme.md

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
[![Latest Stable Version](https://poser.pugx.org/elninotech/linkedin-api-client/v)](https://packagist.org/packages/elninotech/linkedin-api-client)
66
[![Total Downloads](https://poser.pugx.org/elninotech/linkedin-api-client/downloads)](https://packagist.org/packages/elninotech/linkedin-api-client/stats)
77

8-
98
A PHP library to handle authentication and communication with LinkedIn API. The library/SDK helps you to get an access
109
token and when authenticated it helps you to send API requests. You will not get *everything* for free though... You
11-
have to read the [LinkedIn documentation][api-doc-core] to understand how you should query the API.
10+
have to read the [LinkedIn documentation][api-doc-core] to understand how you should query the API.
1211

1312
To get an overview what this library actually is doing for you. Take a look at the authentication page from
1413
the [API docs][api-doc-authentication].
@@ -19,55 +18,27 @@ Here is a list of features that might convince you to choose this LinkedIn clien
1918

2019
* Flexible and easy to extend
2120
* Developed with modern PHP standards
22-
* Not developed for a specific framework.
21+
* Not developed for a specific framework.
2322
* Handles the authentication process
2423
* Respects the CSRF protection
2524

2625
## Installation
2726

28-
**TL;DR**
29-
```bash
30-
composer require php-http/curl-client guzzlehttp/psr7 php-http/message elninotech/linkedin-api-client
31-
```
32-
33-
This library does not have a dependency on Guzzle or any other library that sends HTTP requests. We use the awesome
34-
HTTPlug to achieve the decoupling. We want you to choose what library to use for sending HTTP requests. Consult this list
35-
of packages that support [php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation)
36-
find clients to use. For more information about virtual packages please refer to
37-
[HTTPlug](http://docs.php-http.org/en/latest/httplug/users.html). Example:
38-
39-
```bash
40-
composer require php-http/guzzle7-adapter
41-
```
42-
43-
You do also need to install a PSR-7 implementation and a factory to create PSR-7 messages (PSR-17 whenever that is
44-
released). You could use Guzzles PSR-7 implementation and factories from php-http:
27+
First, install Linkedin-API-client via the [Composer][composer] package manager:
4528

4629
```bash
47-
composer require guzzlehttp/psr7 php-http/message
30+
composer require elninotech/linkedin-api-client
4831
```
4932

50-
Now you may install the library by running the following:
33+
Ensure that the `php-http/discovery` composer plugin is allowed to run or install a client manually if your project does
34+
not already have a PSR-18 client integrated.
5135

5236
```bash
53-
composer require elninotech/linkedin-api-client
37+
composer require guzzlehttp/guzzle
5438
```
5539

5640
If you are updating from a previous version, make sure to read [the upgrade documentation](Upgrade.md).
5741

58-
### Finding the HTTP client (optional)
59-
60-
The LinkedIn client needs to know what library you are using to send HTTP messages. You could provide an instance of
61-
HttpClient and MessageFactory or you could fall back to auto discovery. Below is an example of where you provide a Guzzle7
62-
instance.
63-
64-
```php
65-
$linkedIn=new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
66-
$linkedIn->setHttpClient(new \Http\Adapter\Guzzle7\Client());
67-
$linkedIn->setHttpMessageFactory(new Http\Message\MessageFactory\GuzzleMessageFactory());
68-
69-
```
70-
7142
## Usage
7243

7344
In order to use this API client (or any other LinkedIn clients), you have to [register your application][register-app]
@@ -91,7 +62,7 @@ This example below is showing how to login with LinkedIn.
9162
*/
9263
//require_once "vendor/autoload.php";
9364

94-
$linkedIn=new Elnino\LinkedIn\LinkedIn('client_id', 'client_secret');
65+
$linkedIn = new Elnino\LinkedIn\LinkedIn('client_id', 'client_secret');
9566

9667
if ($linkedIn->isAuthenticated()) {
9768
//we know that the user is authenticated now. Start query the API
@@ -112,10 +83,10 @@ echo "<a href='$url'>Login with LinkedIn</a>";
11283

11384
### How to post on LinkedIn wall
11485

115-
The example below shows how you can post on a users wall. The access token is fetched from the database.
86+
The example below shows how you can post on a users wall. The access token is fetched from the database.
11687

11788
```php
118-
$linkedIn=new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
89+
$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
11990
$linkedIn->setAccessToken('access_token_from_db');
12091

12192
$options = array('json'=>
@@ -142,15 +113,15 @@ var_dump($result);
142113

143114
### The api options
144115

145-
The third parameter of `LinkedIn::api` is an array with options. Below is a table of array keys that you may use.
116+
The third parameter of `LinkedIn::api` is an array with options. Below is a table of array keys that you may use.
146117

147-
| Option name | Description
148-
| ----------- | -----------
149-
| body | The body of a HTTP request. Put your json string here.
150-
| headers | This is HTTP headers to the request
151-
| json | This is an array with json data that will be encoded to a json string.
152-
| response_data_type | To override the response format for one request
153-
| query | This is an array with query parameters
118+
| Option name | Description
119+
|--------------------|------------------------------------------------------------------------
120+
| body | The body of a HTTP request. Put your json string here.
121+
| headers | This is HTTP headers to the request
122+
| json | This is an array with json data that will be encoded to a json string.
123+
| response_data_type | To override the response format for one request
124+
| query | This is an array with query parameters
154125

155126
### Understanding response data type
156127

@@ -159,7 +130,7 @@ The data type returned from `LinkedIn::api` can be configured. You may use the t
159130

160131
```php
161132
// By constructor argument
162-
$linkedIn=new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array');
133+
$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array');
163134

164135
// By setter
165136
$linkedIn->setResponseDataType('string');
@@ -171,29 +142,29 @@ $linkedIn->get('/v2/me/?projection=(id,firstName,lastName)', array('response_dat
171142

172143
Below is a table that specifies what the possible return data types are when you call `LinkedIn::api`.
173144

174-
| Type | Description
175-
| ------ | ------------
176-
| array | An assosiative array. This can only be used with the `json` format.
177-
| psr7 | A PSR7 response.
178-
| stream | A file stream.
179-
| string | A plain old string.
180-
145+
| Type | Description
146+
|--------|---------------------------------------------------------------------
147+
| array | An assosiative array. This can only be used with the `json` format.
148+
| psr7 | A PSR7 response.
149+
| stream | A file stream.
150+
| string | A plain old string.
181151

182152
### Use different Session classes
183153

184154
You might want to use another storage than the default `SessionStorage`. If you are using Laravel
185-
you are more likely to inject the `IlluminateSessionStorage`.
155+
you are more likely to inject the `IlluminateSessionStorage`.
156+
186157
```php
187-
$linkedIn=new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
158+
$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret');
188159
$linkedIn->setStorage(new IlluminateSessionStorage());
189160
```
190161

191162
You can inject any class implementing `DataStorageInterface`. You can also inject different `UrlGenerator` classes.
192163

193164
### Using different scopes
194165

195-
If you want to define special scopes when you authenticate the user you should specify them when you are generating the
196-
login url. If you don't specify scopes LinkedIn will use the default scopes that you have configured for the app.
166+
If you want to define special scopes when you authenticate the user you should specify them when you are generating the
167+
login url. If you don't specify scopes LinkedIn will use the default scopes that you have configured for the app.
197168

198169
```php
199170
$scope = 'r_fullprofile,r_emailaddress,w_share';
@@ -204,11 +175,26 @@ $url = $linkedIn->getLoginUrl(array('scope'=>$scope));
204175
echo "<a href='$url'>Login with LinkedIn</a>";
205176
```
206177

178+
### Using a different http client
179+
180+
If you want to customize how the requests are being sent, you can inject a different `RequestManager` when instantiating
181+
the API.
182+
183+
```php
184+
$myRequestManager = new MySpecialRequestManager();
185+
$linkedIn = new Elnino\LinkedIn\LinkedIn('app_id', 'app_secret', 'array', $myRequestManager);
186+
```
187+
207188
### Special thanks
208189

209190
This repo was originally created by [Thomas Nyholm from Happyr][forked-from].
210191

192+
[composer]: https://getcomposer.org/
193+
211194
[register-app]: https://www.linkedin.com/developers/apps
195+
212196
[api-doc-authentication]: https://learn.microsoft.com/en-us/linkedin/shared/authentication/authentication
197+
213198
[api-doc-core]: https://learn.microsoft.com/en-us/linkedin/shared/api-guide/concepts
199+
214200
[forked-from]: https://github.com/Happyr/LinkedIn-API-client

Upgrade.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
This document explains how you upgrade from one version to another.
44

5-
## Upgrade from 1.0 to 2.0
5+
## Upcoming
6+
7+
### Changes
8+
9+
* Using PSR 17 Http Client and PSR 18 Factory
10+
* Ability to inject RequestManager when creating a new client.
11+
* Deprecate specifying protocolVersion
12+
13+
## Upgrade from 1.0 to 2.0.0
614

715
### Changes
816

@@ -18,7 +26,7 @@ This document explains how you upgrade from one version to another.
1826

1927
### Changes
2028

21-
* We do not longer require `php-http/message`. You have to make sure to put that in your own composer.json.
29+
* We do no longer require `php-http/message`. You have to make sure to put that in your own composer.json.
2230

2331
## Upgrade from 0.7.1 to 0.7.2
2432

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
],
2323
"require": {
2424
"php": "^7.2 || ^8.0",
25+
"ext-json": "*",
2526
"php-http/discovery": "^1.0",
26-
"php-http/httplug": "^1.0 || ^2.0",
27-
"php-http/message-factory": "^1.0",
28-
"psr/http-client-implementation": "^1.0"
27+
"psr/http-client-implementation": "^1.0",
28+
"psr/http-factory-implementation": "^1.0"
2929
},
3030
"require-dev": {
31-
"ext-json": "*",
31+
"guzzlehttp/guzzle": "^7.0",
3232
"illuminate/support": "^12.0",
33-
"mockery/mockery": "^1.0",
34-
"php-http/guzzle7-adapter": "^1.0"
33+
"mockery/mockery": "^1.0"
3534
},
3635
"autoload": {
3736
"psr-4": {
@@ -45,13 +44,14 @@
4544
},
4645
"config": {
4746
"allow-plugins": {
48-
"php-http/discovery": true
47+
"php-http/discovery": false
4948
}
5049
},
5150
"scripts": {
5251
"lint": "./tools/php-cs-fixer check",
5352
"lint-fix": "./tools/php-cs-fixer fix",
5453
"phpstan": "./tools/phpstan analyse --memory-limit=-1",
55-
"test": "./tools/phpunit"
54+
"test": "./tools/phpunit",
55+
"test-coverage": "XDEBUG_MODE=coverage ./tools/phpunit --coverage-text"
5656
}
5757
}

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
parameters:
22
level: 6
3+
treatPhpDocTypesAsCertain: false
34
paths:
45
- src

src/AuthenticatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function fetchNewAccessToken(LinkedInUrlGeneratorInterface $urlGenerator)
2424
/**
2525
* Generate a login url.
2626
*
27-
* @param array<mixed> $options
27+
* @param mixed[] $options
2828
*
2929
* @return string
3030
*/

0 commit comments

Comments
 (0)