Skip to content

Instantly share code, notes, and snippets.

@AlexGx
Created December 14, 2015 02:50
Show Gist options
  • Save AlexGx/6a6cb4fabec442451bdc to your computer and use it in GitHub Desktop.
Save AlexGx/6a6cb4fabec442451bdc to your computer and use it in GitHub Desktop.
<?php
namespace common\components\chrome;
use DOMDocument;
/**
* Class ChromeAutoUpdate.
*/
class ChromeAutoUpdate
{
/**
* @const
*/
const PROTOCOL_VERSION = '2.0';
/**
* Generates manifest XML string.
* @param array $apps array of apps elements
* @return string
*/
public function generateManifest($apps)
{
$dom = new DOMDocument('1.0', 'utf-8');
$gupdate = $dom->createElementNS('http://www.google.com/update2/response', 'gupdate');
$gupdate->setAttribute('protocol', static::PROTOCOL_VERSION);
$dom->appendChild($gupdate);
foreach ($apps as $app) {
$gupdate->appendChild(
$this->buildAppSection($dom, $app['appid'], $app['codebase'], $app['version'])
);
}
return $dom->saveXML();
}
/**
* Builds App section
* @param DOMDocument $dom
* @param $appid
* @param $codebase
* @param $version
* @return mixed
*/
protected function buildAppSection(&$dom, $appid, $codebase, $version)
{
$app = $dom->createElement('app');
$app->setAttribute('appid', $appid);
$updatecheck = $dom->createElement('updatecheck');
$updatecheck->setAttribute('codebase', $codebase);
$updatecheck->setAttribute('version', $version);
$app->appendChild($updatecheck);
return $app;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment