Example #1
0
 /**
  * Generate an xml representation of the library data.
  *
  * @param array $exclude Fields to leave out of the library output
  * @return string
  */
 function to_xml($exclude = array())
 {
     $exclude = array_flip($exclude);
     $writer = new BoostLibraries_XMLWriter();
     $writer->openMemory();
     //$writer->setIndent(true);
     //$writer->setIndentString('  ');
     $writer->startDocument('1.0', 'US-ASCII');
     $writer->startElement('boost');
     $writer->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     if ($this->categories) {
         $writer->startElement('categories');
         foreach ($this->categories as $name => $category) {
             $writer->startElement('category');
             $writer->writeAttribute('name', $name);
             $writer->writeElement('title', $category['title']);
             $writer->endElement();
         }
         $writer->endElement();
         // categories
     }
     foreach ($this->db as $key => $libs) {
         foreach ($libs as $lib) {
             $details = $lib->details;
             if ($lib->update_version) {
                 $details['update-version'] = $lib->update_version;
             }
             $details = BoostLibrary::clean_for_output($details);
             $writer->startElement('library');
             $this->write_element($writer, $exclude, $details, 'key');
             $this->write_element($writer, $exclude, $details, 'module');
             $this->write_optional_element($writer, $exclude, $details, 'boost-version');
             $this->write_optional_element($writer, $exclude, $details, 'update-version');
             $this->write_optional_element($writer, $exclude, $details, 'status');
             $this->write_optional_element($writer, $exclude, $details, 'name');
             $this->write_many_elements($writer, $exclude, $details, 'authors');
             $this->write_many_elements($writer, $exclude, $details, 'maintainers');
             $this->write_optional_element($writer, $exclude, $details, 'description');
             $this->write_optional_element($writer, $exclude, $details, 'documentation');
             $this->write_many_elements($writer, $exclude, $details, 'std');
             $this->write_many_elements($writer, $exclude, $details, 'category');
             $writer->endElement();
         }
     }
     $writer->endElement();
     // boost
     $writer->endDocument();
     return $writer->outputMemory();
 }
function load_from_text($text, $filename, $library_path = null)
{
    $libraries = BoostLibrary::read_libraries_json($text);
    foreach ($libraries as $lib) {
        $lib->set_library_path($library_path);
    }
    return $libraries;
}
Example #3
0
assert(count($r) == 1);
$libraries->update(BoostLibrary::read_libraries_json($accumulators_details), 'develop');
$r = $libraries->get_history('accumulators');
assert(count($r) == 1);
$new_accumulators_details = '{
    "key": "accumulators",
    "module": "accumulators",
    "boost-version": "1.36.0",
    "name": "Accumulators",
    "authors": "Eric Niebler",
    "description": "Framework for incremental calculation, and collection of statistical accumulators.",
    "documentation": "libs/accumulators/",
    "category": [ "Math", "Generic" ]
}';
$libraries->update(BoostLibrary::read_libraries_json($new_accumulators_details), 'develop');
$r = $libraries->get_history('accumulators');
assert(count($r) == 2);
assert(isset($r['1.36.0']));
assert(isset($r['develop']));
assert($r['1.36.0']->details['category'] == array('Math'));
assert($r['develop']->details['category'] == array('Generic', 'Math'));
assert(!isset($r['master']));
$libraries->update(BoostLibrary::read_libraries_json($new_accumulators_details), 'master');
$r = $libraries->get_history('accumulators');
assert(count($r) == 2);
assert(isset($r['1.36.0']));
assert(isset($r['master']));
assert(!isset($r['develop']));
assert($r['1.36.0']->details['category'] == array('Math'));
assert($r['master']->details['category'] == array('Generic', 'Math'));
assert(!isset($r['develop']));
<?php

require_once __DIR__ . '/../common/code/bootstrap.php';
if (isset($_GET['version'])) {
    try {
        $version = BoostVersion::from($_GET['version']);
    } catch (BoostVersion_Exception $e) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
        echo json_encode(array('error' => $e->getMessage()));
        exit(0);
    }
} else {
    $version = BoostVersion::current();
}
// TODO: This is a bit awkard, should probably have an alternative
//       to 'get_for_version' which returns a BoostLibraries instance
//       rather than an array.
// TODO: Include hidden libraries.
$version_libs = array_map(function ($lib) {
    return new BoostLibrary($lib);
}, BoostLibraries::load()->get_for_version($version));
header('Content-type: application/json');
echo BoostLibrary::get_libraries_json($version_libs);
echo $version_libs->to_json();