Esempio n. 1
0
 function testWrite()
 {
     $uri = '/text.txt';
     $content = 'Text content';
     $doc = new MLPHP\Document(parent::$client);
     $doc->setContent($content)->setContentType('text/text');
     $doc->write($uri);
     $response = $doc->getResponse();
     $this->assertEquals(201, $response->getHttpCode());
     return $doc;
 }
Esempio n. 2
0
 function testWrite()
 {
     // Set up response for mock client
     $this->response->setInfo(array('http_code' => 201));
     $this->mockClient->expects($this->any())->method('send')->will($this->returnValue($this->response));
     $uri = '/text.txt';
     $content = 'Text content';
     $doc = new MLPHP\Document($this->mockClient);
     $doc->setContent($content)->setContentType('text/text');
     $doc->write($uri);
     $response = $doc->getResponse();
     $this->assertEquals(201, $response->getHttpCode());
 }
Esempio n. 3
0
 function setUp()
 {
     global $mlphp;
     if (substr($mlphp->config['mlversion'], 0, 3) < 8) {
         $this->markTestSkipped('Test requires MarkLogic 8 or greater');
     }
     $uri = '/text.xml';
     $content = '<doc>
                 <foo bar="baz">hello</foo>
                 <one two="3">world</one>
                 <a b="c">!</one>
               </doc>';
     $doc = new MLPHP\Document(parent::$client);
     $doc->setContent($content)->setContentType('application/xml');
     $doc->write($uri);
     $this->db = new MLPHP\Database(parent::$manageClient, 'mlphp-test-db');
 }
Esempio n. 4
0
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.
*/
// A Simple MLPHP Application
// 1. Complete the installation steps, see: mlphp/README.md
// 2. Tell the app how to talk to MarkLogic.
// Adjust the path below as needed to find the MLPHP project's vendor directory.
require_once __DIR__ . '/../vendor/autoload.php';
use MarkLogic\MLPHP;
// 3. Create a REST client that talks to MarkLogic.
$mlphp = new MLPHP\MLPHP(array('username' => 'rest-writer-user', 'password' => 'writer-pw', 'host' => 'localhost', 'port' => 8077, 'version' => 'v1', 'auth' => 'digest'));
$client = $mlphp->newClient();
// 4. Add a document to the MarkLogic database.
$document = new MLPHP\Document($client);
$document->setContent('<app><description>My first MLPHP app.</description></app>');
$document->write('/myfirstapp.xml');
// 5. Search the MarkLogic database.
$search = new MLPHP\Search($client);
$results = $search->retrieve('MLPHP');
// 6. Display a result.
echo '<html>';
echo '<style>.highlight { background-color: yellow; }</style>';
if ($results->getTotal() > 0) {
    $matches = $results->getResultByIndex(1)->getMatches();
    echo $matches[0]->getContent();
} else {
    echo 'No results found.';
}
echo '</html>';
Esempio n. 5
0
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;
?>
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Example: Chaining Document Methods</title>
</head>

<?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 text as a document to the database
$doc = new MLPHP\Document($client);
echo $doc->setContent('Hello, PHP!')->write('/chained1.txt')->getContent();
echo '<br />';
echo $doc->setContentFile('example.xml')->write('/chained2.xml')->getContent();
echo '<br />';
$doc2 = new MLPHP\Document($client);
echo $doc2->write();
?>

</body>
</html>
Esempio n. 6
0
 public static function loadDocsText($client)
 {
     $doc = new MLPHP\Document(parent::$client, '/text.txt');
     $doc->setContent('Hello MLPHP!!!')->setContentType('text/text')->write();
 }
Esempio n. 7
0
limitations under the License.
*/
// Setup
use MarkLogic\MLPHP;
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Text as a document
$doc1 = new MLPHP\Document($client);
// Create a Document object (passing the REST client)
$text1 = 'Hello, PHP';
// Define document text
$doc1->setContentType('text/text');
// Set the content type for the document
$doc1->setContent($text1);
// Set the text as the document content
$uri1 = '/example.txt';
// Define the URI for the document
$doc1->write($uri1);
// Write the document to the database
// Read the document from the database and display
echo "Read the text document:\n";
echo $doc1->read($uri1) . "\n\n";
// XML file
$doc2 = new MLPHP\Document($client);
// Create a Document object (passing the REST client)
$file2 = 'example.xml';
// Define the path to the file to write
$doc2->setContentType('application/xml');
// Set the content type for the document
Esempio n. 8
0
echo "Quality updated:\n";
echo $meta1->getQuality() . PHP_EOL;
// Read and display the quality of the metadata object
$doc1->writeMetadata($meta1);
// Write the metadata object for the document to the database
echo "Final written quality:\n";
$meta1 = $doc1->readMetadata();
// Read the metadata for the document
print_r($meta1->getQuality());
// Read and display the quality for the metadata object
echo "\n\n\n";
// Update multiple metadata at once via method chaining
$meta1->addCollections(array('sugary', 'fresh'))->addProperties(array('rating' => '9/10'));
$perm4 = new MLPHP\Permission('doc-editor', array('read', 'update', 'insert'));
$meta1->addPermissions($perm4)->setQuality($meta1->getQuality() + 1);
echo "Metadata (collections, properties, permissions, and quality) updated via method chaining:\n";
// Write, read, and display
$doc1->writeMetadata($meta1);
print_r($doc1->readMetadata());
echo "\n\n\n";
// Update metadata simultaneously with document write
$doc2 = new MLPHP\Document($client);
$doc2->setContent('More content');
$uri2 = '/example_updated.xml';
// Add metadata as params
$params2 = array('collection' => 'round', 'prop:status' => 'current', 'perm:doc-editor' => 'insert', 'quality' => 99);
echo "Metadata updated via params:\n";
// Write, read, and display
$doc2->write($uri2, $params2);
print_r($doc2->readMetadata());
echo "\n\n\n";