PHPackages                             airtory/php-vast - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. airtory/php-vast

ActiveLibrary

airtory/php-vast
================

Generator and parser for VAST documents

2.0.x-dev(8mo ago)0339↓74.4%MITPHPPHP &gt;=7.1.3

Since Apr 9Pushed 8mo agoCompare

[ Source](https://github.com/Airtory/php-vast)[ Packagist](https://packagist.org/packages/airtory/php-vast)[ RSS](/packages/airtory-php-vast/feed)WikiDiscussions 2.0 Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

---

PHP-VAST
========

[](#php-vast)

[![Build](https://github.com/airtory/php-vast/workflows/Test/badge.svg?branch=2.0)](https://github.com/airtory/php-vast/actions?query=workflow%3ATest)[![Total Downloads](https://camo.githubusercontent.com/3ac719311b896a069fa2cc171ef235b28aeb54c69f5d23c3ef414337df546038/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616972746f72792f7068702d766173742e7376673f31)](https://packagist.org/packages/airtory/php-vast)[![Coverage Status](https://camo.githubusercontent.com/18564961254dacc3111578d85632a1686f55650b8a49161c44455d3c1c79e9d3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616972746f72792f7068702d766173742f62616467652e7376673f6272616e63683d6d61737465722631)](https://coveralls.io/github/airtory/php-vast?branch=master)

⭐ VAST Ad generator and parser library on PHP.

Specs
-----

[](#specs)

- VAST 2.0 Spec: [http://www.iab.net/media/file/VAST-2\_0-FINAL.pdf](http://www.iab.net/media/file/VAST-2_0-FINAL.pdf)
- VAST 3.0 Spec: [http://www.iab.com/wp-content/uploads/2015/06/VASTv3\_0.pdf](http://www.iab.com/wp-content/uploads/2015/06/VASTv3_0.pdf)
- VAST 4.0 Spec:
    - [http://www.iab.com/wp-content/uploads/2016/01/VAST\_4-0\_2016-01-21.pdf](http://www.iab.com/wp-content/uploads/2016/01/VAST_4-0_2016-01-21.pdf)
    - [https://www.iab.com/wp-content/uploads/2016/04/VAST4.0\_Updated\_April\_2016.pdf](https://www.iab.com/wp-content/uploads/2016/04/VAST4.0_Updated_April_2016.pdf)
- VAST 4.1 Spec:
    -
- [VAST Samples](https://github.com/InteractiveAdvertisingBureau/VAST_Samples)

Install
-------

[](#install)

Install library through composer:

```
composer require Airtory/php-vast

```

Quick start
-----------

[](#quick-start)

```
// create document
$factory = new \airtory\Vast\Factory();
$document = $factory->create('4.1');

// insert Ad section
$ad1 = $document
    ->createInLineAdSection()
    ->setId('ad1')
    ->setAdSystem('Ad Server Name')
    ->setAdTitle('Ad Title')
    ->addImpression('http://ad.server.com/impression', 'imp1');

// create creative for ad section
$linearCreative = $ad1
    ->createLinearCreative()
    ->setDuration(128)
    ->setId('013d876d-14fc-49a2-aefd-744fce68365b')
    ->setAdId('pre')
    ->setVideoClicksClickThrough('http://entertainmentserver.com/landing')
    ->addVideoClicksClickTracking('http://ad.server.com/videoclicks/clicktracking')
    ->addVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick')
    ->addTrackingEvent('start', 'http://ad.server.com/trackingevent/start')
    ->addTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop');

// add closed caption file (Closed Caption support starts on VAST 4.1)
$linearCreative
    ->createClosedCaptionFile()
    ->setLanguage('en-US')
    ->setType('text/srt')
    ->setUrl('http://server.com/cc.srt');

// add 100x100 media file
$linearCreative
    ->createMediaFile()
    ->setProgressiveDelivery()
    ->setType('video/mp4')
    ->setHeight(100)
    ->setWidth(100)
    ->setBitrate(2500)
    ->setUrl('http://server.com/media1.mp4');

// add 200x200 media file
$linearCreative
    ->createMediaFile()
    ->setProgressiveDelivery()
    ->setType('video/mp4')
    ->setHeight(200)
    ->setWidth(200)
    ->setBitrate(2500)
    ->setUrl('http://server.com/media2.mp4');

// get dom document
$domDocument = $document->toDomDocument();

// get XML string
echo $document;
```

This will generate:

```

            Ad Server Name
            Ad Title]]>
            http://ad.server.com/impression]]>

                        00:02:08

                            http://entertainmentserver.com/landing]]>
                            http://ad.server.com/videoclicks/clicktracking]]>
                            http://ad.server.com/videoclicks/customclick]]>

                            http://ad.server.com/trackingevent/start]]>
                            http://ad.server.com/trackingevent/stop]]>

                                  http://server.com/cc.srt]]>

                                http://server.com/media1.mp4]]>

                                http://server.com/media2.mp4]]>

```

Custom Specification Support
----------------------------

[](#custom-specification-support)

VAST document elements are completely described in it's specification, but some Ad servers may add support for custom elements and attributes. This library strictly follows specification, generally because two dialects of VAST may conflict with each other. You may write our own dialect by overriding element builder and create any elements and attributes you want.

The VAST dialect is described in `\airtory\Vast\ElementBuilder` class. By overriding it you may create instances of your own classes and add there any setters.

First let's create a class for `MediaFile` and add some custom attributes:

```
