1. Go to this page and download the library: Download wpkg/wpkg-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wpkg / wpkg-php example snippets
$_config = new \WPKG\Config();
// Overwrite some attributes
$_config
->with('wpkg_base', 'http://example.com')
->with('quitonerror', true)
->with('debug', true);
// Now we can set the variables
$_config
->withVariable('PROG_FILES32', "%ProgramFiles%", null, "x86")
->withVariable('PROG_FILES32', "%ProgramFiles(x86)%", null, "x64")
->withVariable('DESKTOP', "%ALLUSERSPROFILE%\Desktop", "Windows xp")
->withVariable('DESKTOP', "%PUBLIC%\Desktop", "Windows 7");
// Show current variant of generated XML
echo $_config->show();
// Root container
$_host = new \WPKG\Host();
// Need to add some parameters
$_host
->with('name', 'host1')
->with('profile-id', 'profile1');
echo $_host->show();
// Root container
$_host = new \WPKG\Host();
// Need to add some parameters
$_host
->with('name', 'host1')
->with('profile-id', ['profile1', 'profile2', 'profile3']);
echo $_host->show();
// Root container
$_hosts = new Hosts();
/**
* Test host #1
*/
$host1 = new Host();
$host1
->with('name', 'host1')
->with('profile-id', 'profile1');
$_hosts->setHost($host1);
/**
* Test host #2
*/
$host2 = new Host();
$host2
->with('name', 'host2')
->with('profile-id', ['profile1', 'profile2', 'profile3']);
$_hosts->setHost($host2);
/**
* Test host #3
*/
$host3 = new Host();
$host3
->with('name', 'host3')
->with('profile-id', 'profile3');
$_hosts->setHost($host3);
echo $_hosts->show();
use \WPKG\Drivers\ADImport;
// Read AD configuration
$_config = port = new ADImport($_config);
// You also can set config via specific method
//$_import->setConfig($_config);
// Choose work mode (only hosts available) and output the XML
$_hosts = $_import->import('hosts');
$out = $_hosts->show();
print_r($out);
use WPKG\Profile;
$_profile = new \WPKG\Profile();
$_profile
->with('id', 'profile1')
->with('packages', 'DotNet')
->with('depends', 'profile2');
// Show current variant of generated config
echo $_profile->show();
$_profiles = new \WPKG\Profiles();
/**
* Test profile #1
*/
$pr1 = new Profile();
$pr1->with('id', 'profile1');
$_profiles->setProfile($pr1);
/**
* Test profile #2
*/
$pr2 = new Profile();
$pr2->with('id', 'profile2')
->with('packages', 'DotNet');
$_profiles->setProfile($pr2);
/**
* Test profile #3
*/
$pr3 = new Profile();
$pr3->with('id', 'profile3')
->with('packages', ['Firefox', 'Chromium', 'Opera'])
->with('depends', 'profile1');
$_profiles->setProfile($pr3);
/**
* Test profile #4
*/
$pr4 = new Profile();
$pr4->with('id', 'profile4')
->with('packages', ['SuperBank', 'AnotherBank'])
->with('depends', ['profile1', 'profile2']);
$_profiles->setProfile($pr4);
/**
* Test profile #5
*/
$pr5 = new Profile();
$pr5->with('id', 'profile5')
->with('depends', 'profile3');
$_profiles->setProfile($pr5);
// Show current variant of generated config
echo $_profiles->show();
use \WPKG\Package;
use \WPKG\PackageCheckExits;
$_package = new Package();
$_exits = new PackageCheckExits();
// Overwrite the attributes of tha class
$_package
->with('id', 'wpkg1')
->with('name', 'Windows Packager sample 1')
->with('revision', 1)
->with('priority', 0)
->with('reboot', 'false');
// Small check for Windows 7
$_package
->withCheck('registry', 'exists', 'HKLM\Software\wpkg\full\key\not\part\of\it')
->withCheck('file', 'exists', 'C:\wpkg\wpkg.bat')
->withCheck('uninstall', 'exists', 'WPKG 0.6-test1');
// Add few variables to package config
$_package
->withVariable('PROG_FILES32', "%ProgramFiles(x86)%", null, "x64")
->withVariable('DESKTOP', "%ALLUSERSPROFILE%\Desktop", "Windows xp");
// We need set exit codes for some installation stages
$_exits
->add(0)
->add(3010, true)
->add('any')
->add(2);
// Run command
$_package
->withCommand('install', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"', 'test', $_exits)
->withCommand('remove', 'msiexec /x /qn "%SOFTWARE%\path\to\msi"')
->withCommand('upgrade', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"')
->withCommand('downgrade', null, 'remove')
->withCommand('downgrade', null, 'install');
echo $_package->show();
use \WPKG\Package;
use \WPKG\PackageCheckExits;
use \WPKG\Packages;
// Root container
$_packages = new Packages();
/**
* Test package #1
*/
$pk1 = new Package();
$pk1->with('id', 'time')
->with('name', 'Time Synchronization')
->with('priority', 100)
->with('execute', 'always')
->withCheck('host', 'os', 'windows 7')
->withCommand('install', 'net time \\timeserver /set /yes');
$_packages->setPackage($pk1);
/**
* Test package #2
*/
$pk2 = new Package();
$pk2_exits = new PackageCheckExits();
// We need set exit codes for some installation stages
$pk2_exits
->add(0)
->add(3010, true)
->add('any')
->add(2);
$pk2->with('id', 'wpkg')
->with('name', 'Windows Packager sample 1')
->with('revision', 1)
->with('priority', 0)
->with('reboot', 'false')
->withCheck('registry', 'exists', 'HKLM\Software\wpkg\full\key\not\part\of\it')
->withCheck('file', 'exists', 'C:\wpkg\wpkg.bat')
->withCheck('uninstall', 'exists', 'WPKG 0.6-test1')
->withCommand('install', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"', 'test', $pk2_exits)
->withCommand('remove', 'msiexec /x /qn "%SOFTWARE%\path\to\msi"')
->withCommand('upgrade', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"')
->withCommand('downgrade', null, 'remove')
->withCommand('downgrade', null, 'install');
$_packages->setPackage($pk2);
/**
* Test package #3
*/
$pk3 = new Package();
$pk3->with('id', 'time3')
->with('name', 'Time Synchronization')
->with('priority', 100)
->with('execute', 'always')
->withCheck('host', 'os', 'windows 7')
->withCommand('install', 'net time \\timeserver /set /yes');
$_packages->setPackage($pk3);
echo $_packages->show();
use \WPKG\Drivers\XMLImport;
// Create new object
$_import = new XMLImport();
// Content of hosts file
$_hosts_file = file_get_contents('config.xml');
// Read and parse file to normal format
$_hosts = $_import->import($_hosts_file);
// Print array to stdOut
print_r($_hosts);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.