### Manage Databases in ArangoDB with PHP Source: https://context7.com/lucassouzavieira/arangodb-php-odm/llms.txt Shows how to perform database operations including listing, creating, dropping, and retrieving database information. Includes examples for getting current database info, listing all databases, and handling errors during creation. ```php use ArangoDB\Database\Database; use ArangoDB\Connection\Connection; $connection = new Connection([ 'endpoint' => 'http://localhost:8529', 'username' => 'root', 'password' => 'password', 'database' => '_system', ]); // Get current database instance $database = $connection->getDatabase(); $info = $database->getInfo(); echo "Database: " . $info['name'] . "\n"; echo "Path: " . $info['path'] . "\n"; // List all databases on the server $databases = Database::list($connection); foreach ($databases as $dbName) { echo "Found database: $dbName\n"; } // Create a new database try { $result = Database::create($connection, 'my_new_database'); echo "Database created successfully\n"; } catch (\Exception $e) { echo "Error: " . $e->getMessage() . "\n"; } // Drop a database $result = Database::drop($connection, 'my_old_database'); if ($result) { echo "Database dropped successfully\n"; } // Check if collection exists if ($database->hasCollection('users')) { echo "Collection 'users' exists\n"; } ``` -------------------------------- ### Install/Uninstall Foxx Services with Arango PHP ODM Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/namespaces/arangodb-foxx.html This PHP code snippet demonstrates how to interact with the Arango PHP ODM to install or uninstall Foxx services. It utilizes the Foxx class from the ArangoDB namespace. The exact implementation details for installation and uninstallation are not provided in this snippet but would typically involve methods on the Foxx object. ```php install('/path/to/service', '/mount/point'); // $foxx->uninstall('/mount/point'); ``` -------------------------------- ### Install/Uninstall Foxx Services (PHP) Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Foxx-Foxx.html This PHP code snippet demonstrates how to install and uninstall Foxx services in ArangoDB. It is part of the Foxx class within the ArangoDB namespace. Ensure the ArangoDB PHP client library is installed. ```php $mount, 'source' => $source ]; if ($development) { $params['development'] = 'true'; } return $this->request('POST', '/_admin/foxx/install', $params); } /** * Uninstall a Foxx service * * @param string $mount The mount point of the service * * @return Response */ public function uninstall($mount) { return $this->request('POST', '/_admin/foxx/uninstall', ['mount' => $mount]); } // ... other methods private function request($method, $path, $params = []) { // Placeholder for the actual HTTP request logic // This would typically involve using an HTTP client to interact with ArangoDB return new Response(200, [], '{}'); } } ``` -------------------------------- ### GET /{url} Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Http-RestClient.html Performs a GET request to the specified URL with optional data and headers. ```APIDOC ## GET /{url} ### Description Performs a GET request. ### Method GET ### Endpoint /{url} ### Parameters #### Path Parameters - **url** (string) - Required - The URL to execute the request against. #### Query Parameters None #### Request Body - **data** (mixed) - Optional - Data to send with the request. Defaults to an empty array. - **headers** (array) - Optional - Additional headers. Defaults to an empty array. ### Request Example ```json { "url": "/your/collection", "data": {"limit": 10}, "headers": {} } ``` ### Response #### Success Response (200) - **ResponseInterface** - An object representing the HTTP response. #### Response Example (Response structure depends on the specific request and ArangoDB response) ``` -------------------------------- ### Build System URI and Get Data from ArangoDB Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Database/DatabaseHandler.php.txt This snippet shows how to construct a system URI for ArangoDB using the Api class and retrieve data via a GET request. It decodes the JSON response and returns the 'result' field. It also includes exception handling for client errors, re-throwing them as a DatabaseException with specific error details. ```php $uri = Api::buildSystemUri($connection->getBaseUri(), Api::CURRENT_DATABASE); $response = $connection->get($uri); $data = json_decode((string)$response->getBody(), true); return $data['result']; } catch (ClientException $exception) { $response = json_decode((string)$exception->getResponse()->getBody(), true); throw new DatabaseException($response['errorMessage'], $exception, $response['errorNum']); } } } ``` -------------------------------- ### GET /api/aql/functions Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-AQL-AQL.html Retrieves all registered AQL user functions from the ArangoDB server. Optionally filters functions by namespace. ```APIDOC ## GET /api/aql/functions ### Description Returns all registered AQL user functions from the ArangoDB server. Can optionally filter by namespace. ### Method GET ### Endpoint /api/aql/functions ### Parameters #### Query Parameters - **namespace** (string) - Optional - Filters functions by the specified namespace. ### Response #### Success Response (200) - **ArrayList** (object) - Contains all AQL functions from the server. #### Response Example { "functions": [ { "name": "function1", "code": "function() { return 'example'; }" } ] } ``` -------------------------------- ### Get Authorization Header in ArangoDB PHP Authenticable Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Connection-Connection.html The getAuthorizationHeader method retrieves the authorization header as an array for use in requests. It takes no parameters and returns an array of string/int mixed values. Protected method for internal header generation; assumes prior authentication setup. ```php protected getAuthorizationHeader() : array ``` -------------------------------- ### ArangoDB AQLFunction Constructor (PHP) Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-AQL-Functions-AQLFunction.html Initializes a new AQLFunction object. It requires the function name and code, and optionally accepts a connection object, a boolean indicating determinism, and a boolean indicating if it's a new function. ```php public function __construct(string $name, string $code, ?Connection $connection = null, bool $isDeterministic = true, bool $isNew = true): mixed ``` -------------------------------- ### Initialize ArangoDB Cursor with Connection and Statement Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Cursor/Cursor.php.txt Constructor method for creating a new cursor instance. Takes a connection object, statement interface, and optional configuration options. Merges default options with provided ones and initializes the cursor by calling the create method. Requires a valid ArangoDB connection and statement implementation. ```php public function __construct(Connection $connection, StatementInterface $statement, array $options = []) { $this->uri = Api::buildDatabaseUri($connection->getBaseUri(), $connection->getDatabaseName(), Api::CURSOR); $this->statement = $statement; $this->connection = $connection; $this->result = new ArrayList(); $this->options = array_merge($this->defaultOptions, $options); $this->create(); } ``` -------------------------------- ### Get ArangoDB Collection Update Parameters (PHP) Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Collection/Collection.php.txt Generates an array containing the parameters for updating an ArangoDB collection's properties. Specifically, it includes `cacheEnabled` and `waitForSync` attributes. This method is used internally by the `update` method. It references the `rename` method as an example of an update operation. ```php protected function getUpdateParameters(): array { return [ 'cacheEnabled' => $this->attributes['cacheEnabled'], 'waitForSync' => $this->attributes['waitForSync'], ]; } ``` -------------------------------- ### Initialize Modal and Code Loading (JavaScript) Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-View-View.html This script initializes modal windows and triggers the loading of external code snippets when modal buttons are clicked. It includes logic to prevent code loading when the page is opened via the 'file://' scheme due to browser security restrictions. ```javascript const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); ``` -------------------------------- ### Get ArangoDB System Time Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Admin/Admin.php.txt Retrieves the server's system time from ArangoDB. It accepts a connection object and returns a float representing the Unix timestamp. Uses HTTP GET and exception handling. ```PHP public static function time(Connection $connection): float { try { $response = $connection->get(Api::ADMIN_TIME); $data = json_decode((string)$response->getBody(), true); return $data['time']; } catch (ClientException $exception) { // Unknown error. $response = json_decode((string)$exception->getResponse()->getBody(), true); throw new ServerException($response['errorMessage'], $exception, $response['errorNum']); } } ``` -------------------------------- ### Get ArangoDB Statistics Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Admin/Admin.php.txt Retrieves server statistics from ArangoDB. It takes a connection object as input and returns an array containing the statistics data. It utilizes HTTP GET requests and handles potential ServerExceptions. ```PHP public static function statistics(Connection $connection) { try { $response = $connection->get(Api::ADMIN_STATISTICS); $data = json_decode((string)$response->getBody(), true); return $data; } catch (ClientException $exception) { // Unknown error. $response = json_decode((string)$exception->getResponse()->getBody(), true); throw new ServerException($response['errorMessage'], $exception, $response['errorNum']); } } ``` -------------------------------- ### Modal Initialization and Event Handling (JavaScript) Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Batch-Import.html This JavaScript code initializes modal elements and sets up event listeners for opening and closing them. It checks if the page is opened locally (file:// scheme) and hides modal triggers if so, as XHR requests are blocked. When a modal trigger is clicked, it prevents the default action, finds the corresponding modal, opens it, and loads external code snippets if specified. Exit buttons within the modal are also configured to close it. ```javascript const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); ``` -------------------------------- ### Untitled Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src-database-databasehandler.html No description -------------------------------- ### ArrayList: Get Element by Key in PHP Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/DataStructures/ArrayList.php.txt The `get()` method enables retrieving a specific element from the ArrayList using its key. It checks for the existence of the key before returning the value, returning null if the key is not found. ```php content)) { return $this->content[$key]; } return null; } // ... other methods ... } ``` -------------------------------- ### Get ArangoDB Tasks Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Admin/Admin.php.txt Retrieves a list of tasks running on the ArangoDB server. It takes a connection object as input and returns an ArrayList of Task objects. Uses HTTP GET and exception handling, building an ArrayList. ```PHP public static function tasks(Connection $connection): ArrayList { try { $tasks = new ArrayList(); $response = $connection->get(Api::ADMIN_TASKS); $data = json_decode((string)$response->getBody(), true); foreach ($data as $taskData) { $name = $taskData['name']; $command = $taskData['command']; $tasks->push(new Task($name, $command, $connection, $taskData)); } return $tasks; } catch (ClientException $exception) { // Unknown error. $response = json_decode((string)$exception->getResponse()->getBody(), true); throw new ServerException($response['errorMessage'], $exception, $response['errorNum']); } } ``` -------------------------------- ### Establish ArangoDB Connection in PHP Source: https://context7.com/lucassouzavieira/arangodb-php-odm/llms.txt Demonstrates how to create and configure a connection to ArangoDB server with authentication and custom options. Includes basic connection setup, authentication check, and custom headers configuration. ```php use ArangoDB\Connection\Connection; // Basic connection with endpoint $connection = new Connection([ 'endpoint' => 'http://localhost:8529', 'username' => 'root', 'password' => 'mypassword', 'database' => 'mydb', ]); // Connection with host and port separation $connection = new Connection([ 'host' => 'http://localhost', 'port' => 8529, 'username' => 'root', 'password' => 'mypassword', 'database' => 'mydb', 'connection' => 'Keep-Alive', 'timeout' => 30 ]); // Check authentication status if ($connection->isAuthenticated()) { echo "Connected to: " . $connection->getBaseUri(); echo "\nDatabase: " . $connection->getDatabaseName(); } // Set custom headers for all requests $connection->setDefaultHeaders([ 'X-Custom-Header' => 'CustomValue' ]); ``` -------------------------------- ### Load external code snippets via JavaScript Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Auth-Authenticable.html This script dynamically loads external source code into
 elements marked with a data-src attribute, handling XHR requests, error states, and syntax highlighting with Prism. It also manages modal dialogs for displaying code snippets and adjusts scrolling for line numbers. Dependencies include the Prism library and a proper server environment for XHR.

```javascript
(function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d[0].scrollTop = d[0].children[1].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })();
```

--------------------------------

### Get ArangoDB User

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Admin/Admin.php.txt

Retrieves user information from the ArangoDB server.  It requires a connection object and a username as input and returns a User object if found, or false if not.  It uses HTTP GET request and handles potential exceptions.

```PHP
public static function user(Connection $connection, string $username)
{
    try {
        $uri = Api::buildDatabaseUri($connection->getBaseUri(), $connection->getDatabaseName(), Api::USER);
        $uri = Api::addUriParam($uri, $username);

        $response = $connection->get($uri);
        $data = json_decode((string)$response->getBody(), true);
        $user = new User($data, $connection, false);
        return $user;
    } catch (ClientException $exception) {
        $response = json_decode((string)$exception->getResponse()->getBody(), true);
        $serverException = new ServerException($response['errorMessage'], $exception, $response['errorNum']);

        // User not found.
        if ($exception->getResponse()->getStatusCode() == 404) {
            return false;
        }

        throw $serverException;
    }
}
```

--------------------------------

### Load external code snippets into documentation using JavaScript

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src-collection-collection.html

This JavaScript utility fetches source files referenced in 
 elements and injects them into the page with syntax highlighting. It handles loading states, error messages, and scrolls to the specified line. Dependencies include the Prism library for highlighting and assumes a browser environment.

```JavaScript
(function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line); code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName("line-numbers"); d[0].scrollTop = d[0].children[1].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn('Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way'); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line); const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })();
```

--------------------------------

### TTLIndex Class Documentation

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Collection-Index-TTLIndex.html

Provides details on the TTLIndex class, including its properties and methods for creating and managing Time-To-Live (TTL) indexes in ArangoDB.

```APIDOC
## TTLIndex Class

### Description

This class represents a Time-To-Live (TTL) index in ArangoDB. It extends the base Index class and provides specific methods for TTL index management, such as setting the expiration time.

### Properties

*   **$collection** (ArangoDB\Collection) - The collection this index belongs to.
*   **$expiresAfter** (int|float) - The time in seconds after which documents expire.
*   **$fields** (array) - An array of fields that constitute the index.
*   **$id** (string) - The unique identifier of the index.
*   **$indexTypes** (array) - Supported index types for this class.
*   **$isNew** (bool) - Flag indicating if the index is newly created.
*   **$name** (string) - The name of the index.
*   **$sparse** (bool) - Whether the index is sparse.
*   **$type** (string) - The type of the index (e.g., 'TTL').
*   **$unique** (bool) - Whether the index is unique.

### Methods

*   **__construct(array $data = [], ?ArangoDB\Collection $collection = null)**: Constructor for the TTLIndex class.
*   **__toString()**: Returns a string representation of the index.
*   **expireAfter(int|float $seconds)**: Sets the expiration time for the TTL index.
*   **getCollection()**: Returns the collection associated with the index.
*   **getCreateData()**: Returns the data required to create the index.
*   **getFields()**: Returns the fields of the index.
*   **getId()**: Returns the ID of the index.
*   **getName()**: Returns the name of the index.
*   **getType()**: Returns the type of the index.
*   **isNew()**: Checks if the index is new.
*   **isSparse()**: Checks if the index is sparse.
*   **isUnique()**: Checks if the index is unique.
*   **jsonSerialize()**: Prepares the index for JSON serialization.
*   **setCollection(ArangoDB\Collection $collection)**: Sets the collection for the index.
*   **toArray()**: Converts the TTLIndex object to an array.

### Request Example (Conceptual - for creating a TTL index)

```php
use ArangoDB\Collection\Index\TTLIndex;

// Assuming $collection is an instance of ArangoDB\Collection
$ttlIndex = new TTLIndex();
$ttlIndex->setCollection($collection);
$ttlIndex->setFields(['createdAt']); // Field to index on
$ttlIndex->expireAfter(3600); // Documents expire after 1 hour

// To persist this, you would typically use a method on the collection object
// $collection->addIndex($ttlIndex); // This is a conceptual representation
```

### Response (Conceptual - for retrieving index information)

```json
{
  "id": "_id_of_the_index",
  "name": "index_name",
  "type": "TTL",
  "fields": ["createdAt"],
  "isNew": false,
  "unique": false,
  "sparse": false,
  "expiresAfter": 3600
}
```
```

--------------------------------

### Perform GET Request with ArangoDB RestClient (PHP)

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/files/src/Http/RestClient.php.txt

Executes an HTTP GET request to a specified URL. It sends JSON-encoded data and custom headers. The method returns a PSR-7 ResponseInterface object. It handles potential Guzzle exceptions during the request.

```php
httpClient->send($request->withoutHeader('content-length'));
}

```

--------------------------------

### Modal Button Event Handler Setup

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Database-Database.html

JavaScript code that sets up event listeners for modal buttons to display code snippets. Checks if page is opened locally and disables functionality if so due to browser XHR restrictions. Handles modal open/close events.

```javascript
const modalButtons = document.querySelectorAll("\[data-modal\]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(\`Modal with id "${trigger.dataset.modal}" could not be found\`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("\[data-exit-button\]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })();
```

--------------------------------

### ArangoDB AQLFunction Methods (PHP)

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-AQL-Functions-AQLFunction.html

Provides methods to interact with ArangoDB AQL functions. These include creating, deleting, retrieving code and metadata, checking connection status, and serializing the function object.

```php
public function delete(): bool
public function getCode(): string
public function getDeletionData(): array
public function getName(): string
public function hasConnection(): bool
public function isDeterministic(): bool
public function isNew(): bool
public function jsonSerialize(): array|mixed
public function save(): bool
public function setConnection(Connection|null $connection): void
public function toArray(): array
```

--------------------------------

### Get Index Type

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Collection-Index-PersistentIndex.html

Returns the type of the index (e.g., 'persistent', 'hash', 'fulltext').

```php
public function getType(): string
{
}

```

--------------------------------

### Get Index ID

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Collection-Index-PersistentIndex.html

Returns the unique identifier for the index. This ID is assigned by ArangoDB.

```php
public function getId(): string
{
}

```

--------------------------------

### Load external PHP code snippets dynamically with JavaScript

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/packages/ArangoDB-Database.html

This JavaScript function scans the documentation page for 
 elements with a data-src attribute, fetches the referenced PHP file via XHR, and injects the code into the page with syntax highlighting. It also handles modal dialogs for displaying code and includes error handling for missing files and network issues.

```JavaScript
(function () {\n    function loadExternalCodeSnippet(el, url, line) {\n        Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => {\n            const src = url || pre.getAttribute('data-src').replace(/\\\\/g, '/');\n            const language = 'php';\n            const code = document.createElement('code');\n            code.className = 'language-' + language;\n            pre.textContent = '';\n            pre.setAttribute('data-line', line)\n            code.textContent = 'Loading…';\n            pre.appendChild(code);\n            var xhr = new XMLHttpRequest();\n            xhr.open('GET', src, true);\n            xhr.onreadystatechange = function () {\n                if (xhr.readyState !== 4) {\n                    return;\nn                }\n                if (xhr.status < 400 && xhr.responseText) {\n                    code.textContent = xhr.responseText;\n                    Prism.highlightElement(code);\n                    d=document.getElementsByClassName(\"line-numbers\");\n                    d[0].scrollTop = d[0].children[1].offsetTop;\n                    return;\n                }\n                if (xhr.status === 404) {\n                    code.textContent = '✖ Error: File could not be found';\n                    return;\n                }\n                if (xhr.status >= 400) {\n                    code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;\n                    return;\n                }\n                code.textContent = '✖ Error: An unknown error occurred';\n            };\n            xhr.send(null);\n        });\n    }\n    const modalButtons = document.querySelectorAll(\"[data-modal]\");\n    const openedAsLocalFile = window.location.protocol === 'file:';\n    if (modalButtons.length > 0 && openedAsLocalFile) {\n        console.warn(\n            'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' +\n            'browsers block XHR requests when a page is opened this way'\n        );\n    }\n    modalButtons.forEach(function (trigger) {\n        if (openedAsLocalFile) {\n            trigger.setAttribute(\"hidden\", \"hidden\");\n        }\n        trigger.addEventListener(\"click\", function (event) {\n            event.preventDefault();\n            const modal = document.getElementById(trigger.dataset.modal);\n            if (!modal) {\n                console.error(\`Modal with id \"${trigger.dataset.modal}\" could not be found\`);\n                return;\n            }\n            modal.classList.add(\"phpdocumentor-modal__open\");\n            loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line)\n            const exits = modal.querySelectorAll(\"[data-exit-button]\");\n            exits.forEach(function (exit) {\n                exit.addEventListener(\"click\", function (event) {\n                    event.preventDefault();\n                    modal.classList.remove(\"phpdocumentor-modal__open\");\n                });\n            });\n        });\n    });\n})();
```

--------------------------------

### Get Edge Collection Name

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Graph-EdgeDefinition.html

Retrieves the name of the edge collection associated with this edge definition.

```APIDOC
## GET /api/edge-definition/collection

### Description
Retrieves the name of the edge collection associated with this edge definition.

### Method
GET

### Endpoint
/api/edge-definition/collection

### Response
#### Success Response (200)
- **collection** (string) - Name of the edge collection.

#### Response Example
{
  "collection": "edges"
}
```

--------------------------------

### Load external code snippets via XHR in JavaScript

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Collection-Index-InvertedIndex.html

This JavaScript utility fetches external source files and injects them into the page, using Prism for syntax highlighting. It requires a DOM environment with modal elements and handles XHR errors, but cannot run when the page is opened via the file:// protocol due to browser security restrictions.

```javascript
(function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); d=document.getElementsByClassName(\"line-numbers\"); d[0].scrollTop = d[0].children[1].offsetTop; return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll(\"[data-modal]\"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute(\"hidden\", \"hidden\"); } trigger.addEventListener(\"click\", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id \"${trigger.dataset.modal}\" could not be found`); return; } modal.classList.add(\"phpdocumentor-modal__open\"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll(\"[data-exit-button]\"); exits.forEach(function (exit) { exit.addEventListener(\"click\", function (event) { event.preventDefault(); modal.classList.remove(\"phpdocumentor-modal__open\"); }); }); }); }); })();
```

--------------------------------

### Get Index Name

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Collection-Index-PersistentIndex.html

Retrieves the name of the index. This is a user-defined or automatically generated name for the index.

```php
public function getName(): string
{
}

```

--------------------------------

### Dynamic External Code Snippet Loader in JavaScript

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Exceptions-Storage-DataSourceNotFoundException.html

This JavaScript code implements a dynamic loader for external code snippets in documentation modals. It uses XMLHttpRequest to fetch code from URLs and highlights it with Prism. Dependencies include Prism.js for syntax highlighting; inputs are modal triggers with data attributes for src and line; outputs updated code elements in modals; limitations include failure on file:// protocol due to browser restrictions on XHR.

```javascript
(function () { function loadExternalCodeSnippet(el, url, line) { Array.prototype.slice.call(el.querySelectorAll('pre[data-src]')).forEach((pre) => { const src = url || pre.getAttribute('data-src').replace(/\\/g, '/'); const language = 'php'; const code = document.createElement('code'); code.className = 'language-' + language; pre.textContent = ''; pre.setAttribute('data-line', line) code.textContent = 'Loading…'; pre.appendChild(code); var xhr = new XMLHttpRequest(); xhr.open('GET', src, true); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) { return; } if (xhr.status < 400 && xhr.responseText) { code.textContent = xhr.responseText; Prism.highlightElement(code); return; } if (xhr.status === 404) { code.textContent = '✖ Error: File could not be found'; return; } if (xhr.status >= 400) { code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText; return; } code.textContent = '✖ Error: An unknown error occurred'; }; xhr.send(null); }); } const modalButtons = document.querySelectorAll("[data-modal]"); const openedAsLocalFile = window.location.protocol === 'file:'; if (modalButtons.length > 0 && openedAsLocalFile) { console.warn( 'Viewing the source code is unavailable because you are opening this page from the file:// scheme; ' + 'browsers block XHR requests when a page is opened this way' ); } modalButtons.forEach(function (trigger) { if (openedAsLocalFile) { trigger.setAttribute("hidden", "hidden"); } trigger.addEventListener("click", function (event) { event.preventDefault(); const modal = document.getElementById(trigger.dataset.modal); if (!modal) { console.error(`Modal with id "${trigger.dataset.modal}" could not be found`); return; } modal.classList.add("phpdocumentor-modal__open"); loadExternalCodeSnippet(modal, trigger.dataset.src || null, trigger.dataset.line) const exits = modal.querySelectorAll("[data-exit-button]"); exits.forEach(function (exit) { exit.addEventListener("click", function (event) { event.preventDefault(); modal.classList.remove("phpdocumentor-modal__open"); }); }); }); }); })();
```

--------------------------------

### Get Vertex Collections for '_to'

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Graph-EdgeDefinition.html

Retrieves the list of vertex collection names for the '_to' attribute of edges.

```APIDOC
## GET /api/edge-definition/to

### Description
Retrieves the list of vertex collection names for the '_to' attribute of edges.

### Method
GET

### Endpoint
/api/edge-definition/to

### Response
#### Success Response (200)
- **to** (array) - List of vertex collection names.

#### Response Example
{
  "to": ["vertices3", "vertices4"]
}
```

--------------------------------

### Load external code snippets via JavaScript XHR

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Cursor-CollectionCursor.html

Implements modal-based code viewer with dynamic loading of external

--------------------------------

### AQL Query Execution with ArangoDB PHP ODM

Source: https://context7.com/lucassouzavieira/arangodb-php-odm/llms.txt

Shows how to execute ArangoDB Query Language (AQL) statements using the PHP ODM. Supports simple queries, queries with bind parameters for security, complex aggregations, and query validation. Requires the ArangoDB PHP ODM and a running ArangoDB instance.

```php
use ArangoDB\AQL\Statement;
use ArangoDB\Cursor\Cursor;
use ArangoDB\Connection\Connection;
use ArangoDB\AQL\AQL; // Added for AQL::validateQuery

$connection = new Connection([
    'endpoint' => 'http://localhost:8529',
    'username' => 'root',
    'password' => 'password',
    'database' => 'mydb',
]);

// Simple query without parameters
$aql = "FOR user IN users FILTER user.age >= 18 SORT user.name RETURN user";
$statement = new Statement($connection, $aql);

$cursor = new Cursor($connection, $statement, [
    'batchSize' => 100,
    'cache' => true,
    'memoryLimit' => 0,
    'ttl' => 60
]);

// Iterate through results
foreach ($cursor as $user) {
    echo $user['name'] . " - " . $user['email'] . "\n";
}

// Query with bind parameters for security
$aql = "FOR user IN users FILTER user.country == @country AND user.age >= @minAge RETURN user";
$statement = new Statement($connection, $aql);
$statement->bind('country', 'USA');
$statement->bind('minAge', 21);

$cursor = new Cursor($connection, $statement);
$results = [];
foreach ($cursor as $result) {
    $results[] = $result;
}

echo "Found " . count($results) . " users\n";

// Complex query with aggregation
$aql = << 10
    SORT total DESC
    RETURN {
        country: country,
        users: total
    }
AQL;

$statement = new Statement($connection, $aql);
$cursor = new Cursor($connection, $statement);

foreach ($cursor as $stat) {
    echo $stat['country'] . ": " . $stat['users'] . " users\n";
}

// Validate query before execution
if (AQL::validateQuery($statement, $connection)) {
    echo "Query is valid\n";
} else {
    echo "Query has syntax errors\n";
}
```

--------------------------------

### Get Vertex Collections for '_from'

Source: https://github.com/lucassouzavieira/arangodb-php-odm/blob/main/docs/classes/ArangoDB-Graph-EdgeDefinition.html

Retrieves the list of vertex collection names for the '_from' attribute of edges.

```APIDOC
## GET /api/edge-definition/from

### Description
Retrieves the list of vertex collection names for the '_from' attribute of edges.

### Method
GET

### Endpoint
/api/edge-definition/from

### Response
#### Success Response (200)
- **from** (array) - List of vertex collection names.

#### Response Example
{
  "from": ["vertices1", "vertices2"]
}
```