{"id":15583717,"url":"https://github.com/sokil/php-vast","last_synced_at":"2025-04-05T14:08:32.474Z","repository":{"id":57055174,"uuid":"14952169","full_name":"sokil/php-vast","owner":"sokil","description":":star: Generating and parsing VAST documents","archived":false,"fork":false,"pushed_at":"2024-04-09T06:42:04.000Z","size":268,"stargazers_count":82,"open_issues_count":2,"forks_count":37,"subscribers_count":8,"default_branch":"2.0","last_synced_at":"2025-03-29T13:09:28.708Z","etag":null,"topics":["ads","advert","advertising","banner","iab","media","php","vast","video","xml"],"latest_commit_sha":null,"homepage":"http://www.iab.net/vast","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sokil.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-05T11:52:56.000Z","updated_at":"2025-03-13T14:39:23.000Z","dependencies_parsed_at":"2024-06-18T15:39:14.193Z","dependency_job_id":null,"html_url":"https://github.com/sokil/php-vast","commit_stats":{"total_commits":229,"total_committers":14,"mean_commits":"16.357142857142858","dds":0.4934497816593887,"last_synced_commit":"cd70478c0a53a1862b2c08abd678e80b2becb59d"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-vast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-vast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-vast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sokil%2Fphp-vast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sokil","download_url":"https://codeload.github.com/sokil/php-vast/tar.gz/refs/heads/2.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345854,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ads","advert","advertising","banner","iab","media","php","vast","video","xml"],"created_at":"2024-10-02T20:20:47.605Z","updated_at":"2025-04-05T14:08:32.459Z","avatar_url":"https://github.com/sokil.png","language":"PHP","readme":"# Stand With Ukraine\n\n[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)\n\n----\n\nPHP-VAST\n========\n\n[![Build](https://github.com/sokil/php-vast/workflows/Test/badge.svg?branch=2.0)](https://github.com/sokil/php-vast/actions?query=workflow%3ATest)\n[![Total Downloads](http://img.shields.io/packagist/dt/sokil/php-vast.svg?1)](https://packagist.org/packages/sokil/php-vast)\n[![Coverage Status](https://coveralls.io/repos/github/sokil/php-vast/badge.svg?branch=master\u00261)](https://coveralls.io/github/sokil/php-vast?branch=master)\n\n:star: VAST Ad generator and parser library on PHP.\n\n## Specs\n* VAST 2.0 Spec: http://www.iab.net/media/file/VAST-2_0-FINAL.pdf\n* VAST 3.0 Spec: http://www.iab.com/wp-content/uploads/2015/06/VASTv3_0.pdf\n* VAST 4.0 Spec: \n  * http://www.iab.com/wp-content/uploads/2016/01/VAST_4-0_2016-01-21.pdf\n  * https://www.iab.com/wp-content/uploads/2016/04/VAST4.0_Updated_April_2016.pdf\n* VAST 4.1 Spec:\n  * https://iabtechlab.com/wp-content/uploads/2018/11/VAST4.1-final-Nov-8-2018.pdf\n* [VAST Samples](https://github.com/InteractiveAdvertisingBureau/VAST_Samples)\n\n## Install\n\nInstall library through composer:\n\n```\ncomposer require sokil/php-vast\n```\n\n## Quick start\n\n```php\n// create document\n$factory = new \\Sokil\\Vast\\Factory();\n$document = $factory-\u003ecreate('4.1');\n\n// insert Ad section\n$ad1 = $document\n    -\u003ecreateInLineAdSection()\n    -\u003esetId('ad1')\n    -\u003esetAdSystem('Ad Server Name')\n    -\u003esetAdTitle('Ad Title')\n    -\u003eaddImpression('http://ad.server.com/impression', 'imp1');\n\n// create creative for ad section\n$linearCreative = $ad1\n    -\u003ecreateLinearCreative()\n    -\u003esetDuration(128)\n    -\u003esetId('013d876d-14fc-49a2-aefd-744fce68365b')\n    -\u003esetAdId('pre')\n    -\u003esetVideoClicksClickThrough('http://entertainmentserver.com/landing')\n    -\u003eaddVideoClicksClickTracking('http://ad.server.com/videoclicks/clicktracking')\n    -\u003eaddVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick')\n    -\u003eaddTrackingEvent('start', 'http://ad.server.com/trackingevent/start')\n    -\u003eaddTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop');\n\n// add closed caption file (Closed Caption support starts on VAST 4.1)\n$linearCreative\n    -\u003ecreateClosedCaptionFile()\n    -\u003esetLanguage('en-US')\n    -\u003esetType('text/srt')\n    -\u003esetUrl('http://server.com/cc.srt');\n    \n// add 100x100 media file\n$linearCreative\n    -\u003ecreateMediaFile()\n    -\u003esetProgressiveDelivery()\n    -\u003esetType('video/mp4')\n    -\u003esetHeight(100)\n    -\u003esetWidth(100)\n    -\u003esetBitrate(2500)\n    -\u003esetUrl('http://server.com/media1.mp4');\n\n// add 200x200 media file\n$linearCreative\n    -\u003ecreateMediaFile()\n    -\u003esetProgressiveDelivery()\n    -\u003esetType('video/mp4')\n    -\u003esetHeight(200)\n    -\u003esetWidth(200)\n    -\u003esetBitrate(2500)\n    -\u003esetUrl('http://server.com/media2.mp4');\n    \n// get dom document\n$domDocument = $document-\u003etoDomDocument();\n\n// get XML string\necho $document;\n```\n\nThis will generate:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cVAST version=\"2.0\"\u003e\n    \u003cAd id=\"ad1\"\u003e\n        \u003cInLine\u003e\n            \u003cAdSystem\u003eAd Server Name\u003c/AdSystem\u003e\n            \u003cAdTitle\u003e\u003c![CDATA[Ad Title]]\u003e\u003c/AdTitle\u003e\n            \u003cImpression id=\"imp1\"\u003e\u003c![CDATA[http://ad.server.com/impression]]\u003e\u003c/Impression\u003e\n            \u003cCreatives\u003e\n                \u003cCreative\u003e\n                    \u003cLinear\u003e\n                        \u003cDuration\u003e00:02:08\u003c/Duration\u003e\n                        \u003cVideoClicks\u003e\n                            \u003cClickThrough\u003e\u003c![CDATA[http://entertainmentserver.com/landing]]\u003e\u003c/ClickThrough\u003e\n                            \u003cClickTracking\u003e\u003c![CDATA[http://ad.server.com/videoclicks/clicktracking]]\u003e\u003c/ClickTracking\u003e\n                            \u003cCustomClick\u003e\u003c![CDATA[http://ad.server.com/videoclicks/customclick]]\u003e\u003c/CustomClick\u003e\n                        \u003c/VideoClicks\u003e\n                        \u003cTrackingEvents\u003e\n                            \u003cTracking event=\"start\"\u003e\u003c![CDATA[http://ad.server.com/trackingevent/start]]\u003e\u003c/Tracking\u003e\n                            \u003cTracking event=\"pause\"\u003e\u003c![CDATA[http://ad.server.com/trackingevent/stop]]\u003e\u003c/Tracking\u003e\n                        \u003c/TrackingEvents\u003e\n                        \u003cMediaFiles\u003e\n                            \u003cClosedCaptionFiles\u003e\n                              \u003cClosedCaptionFile language=\"en-US\" type=\"text/srt\"\u003e\n                                  \u003c![CDATA[http://server.com/cc.srt]]\u003e\n                              \u003c/ClosedCaptionFile\u003e\n                            \u003c/ClosedCaptionFiles\u003e\n                            \u003cMediaFile delivery=\"progressive\" type=\"video/mp4\" height=\"100\" width=\"100\" bitrate=\"2500\"\u003e\n                                \u003c![CDATA[http://server.com/media1.mp4]]\u003e\n                            \u003c/MediaFile\u003e\n                            \u003cMediaFile delivery=\"progressive\" type=\"video/mp4\" height=\"200\" width=\"200\" bitrate=\"2500\"\u003e\n                                \u003c![CDATA[http://server.com/media2.mp4]]\u003e\n                            \u003c/MediaFile\u003e\n                        \u003c/MediaFiles\u003e\n                    \u003c/Linear\u003e\n                \u003c/Creative\u003e\n            \u003c/Creatives\u003e\n        \u003c/InLine\u003e\n    \u003c/Ad\u003e\n\u003c/VAST\u003e\n```\n\n## Custom Specification Support\n\nVAST 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.\n\nThe VAST dialect is described in `\\Sokil\\Vast\\ElementBuilder` class. By overriding it you may create instances of your own classes and add there any setters.\n\nFirst let's create a class for `MediaFile` and add some custom attributes:\n\n```php\n\u003c?php\n\nnamespace Acme\\Vast\\ElementBuilder\\Element;\n\nuse Sokil\\Vast\\Creative\\InLine\\Linear\\MediaFile;\n\nclass AcmeMediaFile extends MediaFile\n{\n    public function setMinDuration($seconds)\n    {\n        $seconds = (int)$seconds;\n        if ($seconds \u003c= 0) {\n            thow new \\InvalidArgumentException('Invalid min duration specified, must be positive int')\n        }\n        \n        $this-\u003edomElement-\u003esetAttribute('minDuration', $seconds);\n        \n        return $this;\n    }\n}\n```\n\nNow we need to override the default element builder and create our own `MediaFile` factory method:\n\n```php\n\u003c?php\n\nnamespace Acme\\Vast\\ElementBuilder;\n\nuse Sokil\\Vast\\ElementBuilder;\nuse Acme\\Vast\\ElementBuilder\\Element\\AcmeMediaFile;\n\nclass AcmeElementBuilder extends ElementBuilder\n{\n    /**\n     * \u003cAd\u003e\u003cInLine\u003e\u003cCreatives\u003e\u003cCreative\u003e\u003cLinear\u003e\u003cMediaFile\u003e\n     *\n     * @param \\DOMElement $mediaFileDomElement\n     *\n     * @return AcmeMediaFile\n     */\n    public function createInLineAdLinearCreativeMediaFile(\\DOMElement $mediaFileDomElement)\n    {\n        return new AcmeMediaFile($mediaFileDomElement);\n    }\n}\n```\n\nNow we need to confugure VAST factory to use overridden element builder:\n\n```php\n\u003c?php\n\nuse Acme\\Vast\\ElementBuilder\\AcmeElementBuilder;\nuse Sokil\\Vast\\Factory;\n\n$elementBuilder = new AcmeElementBuilder();\n$factory = new Factory($elementBuilder);\n\n$document = $factory-\u003ecreate('4.1');\n\n$ad = $document-\u003ecreateInLineAdSection();\n$creative = $ad-\u003ecreateLinearCreative();\n$mediaFile = $creative-\u003ecreateMediaFile();\n\n$mediaFile-\u003esetMinDiration(10);\n```\n\nIf you have an AD server and want to add support for your custom tag, create your own library with custom elements and element builder, or add a pull request to this library. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsokil%2Fphp-vast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsokil%2Fphp-vast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsokil%2Fphp-vast/lists"}