function parseInputObject(SimpleXMLElement $input)
{
    $type = 'string';
    if (isset($input['objectType'])) {
        $type = strval($input['objectType']);
    }
    switch ($type) {
        case 'string':
            return strval($input);
        case 'int':
            return intval(strval($input));
        case 'bool':
            return (bool) strval($input);
        case 'array':
            return parseInputArray($input->item);
    }
    if (!class_exists($type)) {
        echo "Type [{$type}] could not be found\n";
        exit;
    }
    $object = new $type();
    $properties = $input->children();
    foreach ($properties as $property) {
        /* @var $property SimpleXMLElement */
        $propertyName = $property->getName();
        $object->{$propertyName} = parseInputObject($property);
    }
    return $object;
}
Esempio n. 2
0
function parseInputObject(SimpleXMLElement $input = null)
{
    global $inFile;
    if (is_null($input)) {
        return null;
    }
    if (isset($input['null']) && $input['null']) {
        return KalturaClient::getKalturaNullValue();
    }
    $type = 'string';
    if (isset($input['objectType'])) {
        $type = strval($input['objectType']);
    }
    $value = strval($input);
    $matches = null;
    if (preg_match('/\\{prompt:([^}]+)\\}/', $value, $matches)) {
        $userInput = askForUserParameter($matches[1]);
        $value = preg_replace('/\\{prompt:[^}]+\\}/', $userInput, $value);
    }
    if (preg_match('/\\{php:([^}]+)\\}/', $value, $matches)) {
        $value = eval($matches[1]);
    }
    if (preg_match('/\\{variable:([^}]+)\\}/', $value, $matches)) {
        global $variables;
        $value = isset($variables[$matches[1]]) ? $variables[$matches[1]] : null;
    }
    if (isset($input['path'])) {
        $path = $input['path'];
        if (!file_exists($path)) {
            $path = dirname($inFile) . '/' . $path;
            if (!file_exists($path)) {
                echo "File [{$path}] could not be found\n";
                exit(-1);
            }
        }
        $value = file_get_contents($path);
    }
    switch ($type) {
        case 'string':
            return $value;
        case 'int':
            return intval($value);
        case 'bool':
            return (bool) $value;
        case 'file':
            if (file_exists($value)) {
                return realpath($value);
            }
            $value = dirname($inFile) . '/' . $value;
            if (file_exists($value)) {
                return realpath($value);
            }
            echo "File [{$value}] could not be found\n";
            exit(-1);
        case 'array':
            return parseInputArray($input->item);
    }
    if (!class_exists($type)) {
        echo "Type [{$type}] could not be found\n";
        exit(-1);
    }
    $object = new $type();
    $properties = $input->children();
    foreach ($properties as $property) {
        /* @var $property SimpleXMLElement */
        $propertyName = $property->getName();
        $object->{$propertyName} = parseInputObject($property);
    }
    return $object;
}