<commit_before># ByteArk SDK for PHP

[![Packagist Version](https://img.shields.io/packagist/v/byteark/byteark-sdk-php.svg?style=flat)](https://packagist.org/packages/byteark/byteark-sdk-php)
[![Build Status](https://travis-ci.org/byteark/byteark-sdk-php.svg?branch=master)](https://travis-ci.org/byteark/byteark-sdk-php)

## Installation

You may install this SDK via [Composer](https://getcomposre.org)

    composer install byteark/byteark-sdk-php

## Usage

Now the only feature availabled is creating signed URL with ByteArk Signature Version 2

```php
$signer = new ByteArkV2UrlSigner([
    'access_id' => '2Aj6Wkge4hi1ZYLp0DBG',
    'access_secret' => '<KEY>',
]);

$signedUrl = $signer->sign(
    'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
    1514764800,
    [
        'method' => 'GET',
        'client_ip' => '192.168.127.12',
        'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
    ]
);

/*
Got this url:
http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8
    ?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG
    &x_ark_auth_type=ark-v2
    &x_ark_client_ip=1
    &x_ark_expires=1514764800
    &x_art_path_prefix=/video-objects/QDuxJm02TYqJ/
    &x_ark_signature=2bkwVFSu6CzW7KmzXkwDbA
*/
```

For more usage details, please visit [ByteArk Documentation](https://docs.byteark.com)<commit_msg>Update the README<commit_after># ByteArk SDK for PHP

[![Packagist Version](https://img.shields.io/packagist/v/byteark/byteark-sdk-php.svg?style=flat)](https://packagist.org/packages/byteark/byteark-sdk-php)
[![Build Status](https://travis-ci.org/byteark/byteark-sdk-php.svg?branch=master)](https://travis-ci.org/byteark/byteark-sdk-php)


## Installation

You may install this SDK via [Composer](https://getcomposre.org)

    composer install byteark/byteark-sdk-php


## Using ByteArkV2UrlSigner class

Create a signer instance with `access_id` and `access_secret`,
then, call `sign` method with URL, expire timestamp, and custom policies.

For example:

```php
$signer = new \ByteArk\Signer\ByteArkV2UrlSigner([
    'access_id' => '2Aj6Wkge4hi1ZYLp0DBG',
    'access_secret' => '<KEY>',
]);

$signedUrl = $signer->sign(
    'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
    1514764800,
    [
        'method' => 'GET',
        'client_subnet16' => '192.168.3.11',
        'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
    ]
);

/*
Got this url:
http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8
    ?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG
    &x_ark_auth_type=ark-v2
    &x_ark_client_subnet16=1
    &x_ark_expires=1514764800
    &x_ark_path_prefix=/video-objects/QDuxJm02TYqJ/
    &x_ark_signature=2bkwVFSu6CzW7KmzXkwDbA
*/
```

## Using RequestInfo class

You may use `getCurrentUrl` method to help you get current URL,
and `get` method to get some of these policy names:

* client_ip
* client_subnet16
* client_subnet24
* user_agent

For example:

```php
$requestInfo = new \ByteArk\Request\RequestInfo();
$signer = new \ByteArk\Signer\ByteArkV2UrlSigner([
    'access_id' => '2Aj6Wkge4hi1ZYLp0DBG',
    'access_secret' => '<KEY>',
]);

$signedUrl = $signer->sign(
    'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
    1514764800,
    [
        'method' => 'GET',
        'client_subnet16' => $requestInfo->get('client_subnet16'),
        'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
        'referer' => $request->getCurrentUrl()
    ]
);
```

For more usage details, please visit
[ByteArk Documentation](https://docs.byteark.com).
{'fraction_non_alphanumeric': 0.15270383861025497, 'fraction_numerical': 0.04258896049313533, 'mean_word_length': 4.2269399707174236, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 27, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3644034', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1442, 'n_words': 205}