PHP code example of dunglas / solid-client-php
1. Go to this page and download the library: Download dunglas/solid-client-php library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dunglas / solid-client-php example snippets
use Dunglas\PhpSolidClient\SolidClientFactory;
use Dunglas\PhpSolidClient\OidcClient;
use Symfony\Component\HttpClient\HttpClient;
$solidClientFactory = new SolidClientFactory(HttpClient::create());
// Create an anonymous Solid client
$anonymousSolidClient = $solidClientFactory->create();
// Fetch the WebID profile of a user
$profile = $anonymousSolidClient->getProfile('https://example.com/your/webid');
// Fetch the OIDC issuer for a user
$oidcIssuer = $anonymousSolidClient->getOidcIssuer('https://example.com/your/webid');
// Create a Solid OIDC client for this user
$oidcClient = new OidcClient($oidcIssuer);
// Register the OIDC client dynamically
$oidcClient->register();
// Authenticate the user
$oidcClient->authenticate();
// At this point you may want to save $oidcClient in the session
// The user will be redirected to the OIDC server to log in
// Create a Solid client generating DPoP access tokens for the logged-in user
$loggedSolidClient = $solidClientFactory->create($oidcClient);
// Create a new container
$containerResponse = $loggedSolidClient->createContainer('https://mypod.example.com', 'blog');
$container = $containerResponse->getContent();
// Post a new note
$apiPlatformResponse = $loggedSolidClient->post('https://mypod.example.com/blog', 'api-platform-conference', <<<TTL
@prefix as: <http://www.w3.org/ns/activitystreams#>.
<> a as:Note; as:content "Going to API Platform Conference".
TTL
);
$apiPlatformCon = $apiPlatformResponse->getContent();
// Fetch an existing note
$symfonyLiveResponse = $loggedSolidClient->get('https://mypod.example.com/blog/symfony-live');
$symfonyLive = $symfonyLiveResponse->getContent();
// Logout
$oidcClient->signOut($oidcClient->getIdToken());
composer