AmyRemoteProject::create_resource PHP Method

create_resource() public static method

public static create_resource ( $project_url, $ticket, $path, $label, $content )
    public static function create_resource($project_url, $ticket, $path, $label, $content)
    {
        $url = fix_parse_url($project_url);
        $label = trim(str_replace('/', '', $label));
        $response = SimpleHTTP::send('POST', $url['host'], $url['port'], $url['path'], array('a' => 'create_resource', 'ticket' => $ticket, 'path' => $path, 'label' => $label, 'content' => $content));
        if ('200' != $response['status_code']) {
            throw new Exception("Invalid status code `{$response['status_code']}' returned from server `{$url['host']}'.");
        }
        $content = trim($response['body']);
        if ('' === $content) {
            throw new Exception("Unable to create project resource, no content returned from `{$url['host']}{$url['path']}'.");
        }
        if (false !== strpos($response['headers']['content-type'], 'text/xml')) {
            return array('flush' => true, 'content' => $content);
        }
        if ('#S#' != substr($content, 0, 3)) {
            throw new Exception("Error while creating project resource: Message from {$url['host']}{$url['path']}: " . substr($content, 3));
        }
        return array('flush' => false, 'content' => substr($content, 3));
    }

Usage Example

 public function on_project_create_resource($pars = array())
 {
     try {
         $result = AmyRemoteProject::create_resource($pars['url'], $pars['ticket'], $pars['path'], $pars['label'], $pars['content']);
         if ($result['flush']) {
             echo $result['content'];
             header('Content-Type: text/xml; charset=UTF-8');
             exit;
         }
         self::setResult($result['content']);
     } catch (Exception $e) {
         $err_msg = $e->getMessage();
         self::raiseError("Project resource `{$pars['label']}' at `{$pars['path']}' could not been created due an error: `{$err_msg}'.");
     }
 }