Web services/cyclos.php

This script is used by the PHP examples in this wiki.

<?php
class Cyclos {
    public static $server_root = "http://localhost:8080/cyclos";
    private static $cache = array();

    public static function service($service) {
        $cache = Cyclos::$cache;
        if (!array_key_exists($service, $cache)) {
            $wsdl = Cyclos::$server_root."/services/$service?wsdl";
            try {
                $cache[$service] = new SoapClient($wsdl);
            } catch (Exception $e) {
                die("Error retrieving WSDL file $wsdl: $e");
            }
        }
        return $cache[$service];
    }

    public static function picture_url($url) {
        if (empty($url)) {
            return Cyclos::$server_root."/systemImage?image=noPicture&thumbnail=true";
        } else {
            return $url;
        }
    }
}

# Ensures an element is returned as array. 
# When empty, returns an empty array. 
# When an array, returns itself. 
# Otherwise, an array containg the just the element
function ensure_array($element) {
    if (empty($element)) {
        return array();
    }
    if (array_key_exists(0, $element)) {
        return $element;
    }
    return array($element);
}
?>