PHP code example of aferalabs / arachne

1. Go to this page and download the library: Download aferalabs/arachne 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/ */

    

aferalabs / arachne example snippets


use Arachne\Auth\BaseProvider;

class LoginProvider extends BaseProvider
{
    private $sessionToken;

    public function authenticate()
    {
        $client = $this->getClient();
        $client->setPath('/login');
        $client->setRequestBody(json_encode(array('u' => 'user', 'p' => 'pa$$')));
        $response = $client->send();

        if ($response->getStatusCode() !== 200) {
            return false;
        }

        $body = json_decode($response->getBody());
        $this->sessionToken = $body->sessionToken;

        return true;
    }

    public function prepare(ClientInterface $client)
    {
        $client->addHeader('X-Session-Token', $this->sessionToken);
    }
}

use Arachne\Context\ArachneContext

class MyContext extends ArachneContext
{
    public function __construct(array $params)
    {
        // ... process some custom params
        parent::__construct($params);
    }
}