Ejemplo n.º 1
0
<?php

/*
Copyright 2002-2012 MarkLogic Corporation.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
use MarkLogic\MLPHP;
require_once 'setup.php';
$client = $mlphp->newClient();
$doc = new MLPHP\Document($client);
$uri = $_REQUEST['uri'];
$doc->delete($uri);
header('content-type: text/html');
echo 'deleted';
Ejemplo n.º 2
0
<?php 
// Set up global vars and class autoloading
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Write a doc via PUT
$doc = new MLPHP\Document($client);
$file = 'example.xml';
$doc->setContentFile($file);
$uri = "/" . $file;
echo '<br />Write: ' . $doc->write($uri)->getUri() . '<br />' . PHP_EOL;
// Read a doc via GET
echo '<br />Read: ' . $doc->read($uri) . '<br />' . PHP_EOL;
// Delete a doc via DELETE
echo '<br />Delete: ' . $doc->delete($uri)->getUri() . '<br />' . PHP_EOL;
// Test 301 redirect
$govTrackClient = new MLPHP\RESTClient('www.govtrack.us', 0, 'api', 'v1');
// Get Senate bills from bill endpoint
$params = array('bill_type' => 'senate_bill');
// 'bill' resource results in redirect ('bill/' does not)
$request = new MLPHP\RESTRequest('GET', 'bill', $params);
$response = $govTrackClient->send($request);
//print_r($response->getBody());
echo '<br />Title of second bill object: <br />';
$obj = json_decode($response->getBody());
echo $obj->objects[1]->title . '<br /><br />' . PHP_EOL;
?>

</body>
</html>
Ejemplo n.º 3
0
    }
    closedir($handle);
}
// Read the documents from the database
echo "Read the documents:\n";
foreach ($files as $i => $file) {
    // Loop through the file URIs
    echo 'File #' . ($i + 1) . ': ';
    $uri6 = '/' . $file;
    // Define the URI for the document
    // Display each document
    echo htmlspecialchars($doc6->read($uri6)) . "\n";
}
// Delete a document
echo "Delete document '/example.txt'\n";
$doc1->delete('/example.txt');
// Attempt to read and display deleted document (error occurs)
echo "Attempt to read:\n";
try {
    echo $doc1->read('/example.txt') . "\n";
} catch (Exception $e) {
    if ($e->getCode() === 404) {
        echo 'Error code 404, resource not available';
    } else {
        echo 'Error code ' . $e->getCode();
    }
}
function displayImage($uri, $contentType)
{
    echo '<img src="binary.php?uri=' . $uri . '&type=' . $contentType . '"/>';
}