use WindowsAzure\MediaServices\Templates\TokenType;
// Settings
$account = "<your media services account name>";
$secret = "<your media services account key>";
$mezzanineFileName = "Azure-Video.wmv";
$tokenRestriction = true;
$tokenType = TokenType::JWT;
print "Azure SDK for PHP - AES Dynamic Encryption Sample\r\n";
// 0 - set up the MediaServicesService object to call into the Media Services REST API.
$restProxy = ServicesBuilder::getInstance()->createMediaServicesService(new MediaServicesSettings($account, $secret));
// 1 - Upload the mezzanine
$sourceAsset = uploadFileAndCreateAsset($restProxy, $mezzanineFileName);
// 2 - encode the output asset
$encodedAsset = encodeToAdaptiveBitrateMP4Set($restProxy, $sourceAsset);
// 3 - Create Content Key
$contentKey = createEnvelopeTypeContentKey($restProxy, $encodedAsset);
// 4 - Create the ContentKey Authorization Policy
$tokenTemplateString = null;
if ($tokenRestriction) {
    $tokenTemplateString = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType);
} else {
    addOpenAuthorizationPolicy($restProxy, $contentKey);
}
// 5 - Create the AssetDeliveryPolicy
createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey);
// 6 - Publish
publishEncodedAsset($restProxy, $encodedAsset);
// 7 - Generate Test Token
if ($tokenRestriction) {
    generateTestToken($tokenTemplateString, $contentKey);
}
function applyAesDynamicEncryption($restProxy, $asset, $options)
{
    $testToken = null;
    // 1 - Create Content Key
    $contentKey = createEnvelopeTypeContentKey($restProxy, $asset);
    // 2 - Create the ContentKey Authorization Policy and Options
    if ($options->tokenRestriction) {
        // 2.1 - Apply Token restriction
        $template = addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $options->tokenType);
        // 2.2 - Generate Test Token
        $testToken = generateTestToken($template, $contentKey);
    } else {
        // 2.1 - Apply Open restriction
        addOpenAuthorizationPolicy($restProxy, $contentKey);
    }
    // 3 - Create the AssetDeliveryPolicy
    createAssetDeliveryPolicy($restProxy, $asset, $contentKey);
    return $testToken;
}