Oihana PHP Arango

DocumentsCommandList uses trait:short

Provides the implementation for a 'list' command action.

This trait should be used in a Symfony Console command that needs to retrieve and display all documents from its associated model.

Example

Basic usage

bin/console command:places list

Command:places
==============

Listing documents in the collection
-----------------------------------

Documents Found: 4

✅  Done in 5 ms
----------------

Thank you and see you soon!

Use the verbose mode (-v)

$ bin/console.php command:places list -v

Command:places
==============

List the document(s) of the collection
--------------------------------------

Document Found: 4
---------- ----------------- ---------------------- ----------------------
_key       Name              Created                Modified
---------- ----------------- ---------------------- ----------------------
59918826   Béhuard           2025-01-20T15:28:41Z   2025-01-20T15:28:41Z
59943726   Aix-en-Provence   2025-01-21T10:05:41Z   2025-01-21T10:05:41Z
60280105   Savennières       2025-02-05T14:58:20Z   2025-02-05T14:58:20Z
65910397   Marseille         2025-08-25T10:06:26Z   2025-08-25T10:06:26Z
---------- ----------------- ---------------------- ----------------------

✅  Done in 6 ms
----------------

Thank you and see you soon!

Use the very verbose mode (-vv)

bin/console.php command:places list -vv

Command:places
==============

Listing documents in the collection
-----------------------------------

Documents Found: 4

[
    {
        "@type": "Place",
        "@context": "https://schema.org",
        "_key": 59943726,
        "name": "Aix-en-Provence",
        "created": "2025-01-21T10:05:41Z",
        "modified": "2025-01-21T10:05:41Z",
        "address": {
            "postalCode": 49170
        }
    },
    {
        "@type": "Place",
        "@context": "https://schema.org",
        "_key": 60280105,
        "name": "Savennières",
        "created": "2025-02-05T14:58:20Z",
        "modified": "2025-02-05T14:58:20Z",
        "address": {
            "postalCode": 49170
        }
    }
    ...
]

Table of Contents

Properties

$documents  : Documents|null
The DocumentsModel instance for data operations.
$excludes  : array<string|int, mixed>|mixed|null
A list of properties to exclude during data manipulation operations like insert, update, replace, or upsert.
$fields  : array<string|int, mixed>
The document's fields to display in tabular output.
$removeKeys  : array<string|int, mixed>|mixed|null
A list of properties to remove during data manipulation operations like insert, update, replace, or upsert.

Methods

assertDocuments()  : void
Asserts that the 'documents' property has been initialized.
fetchDocuments()  : array<string|int, mixed>
Fetch all documents from the OpenEdge database.
initializeDocuments()  : static
Initializes the 'documents' property.
list()  : int
Executes the action to list all documents from the model.
outputDocuments()  : void
Renders a list of documents to the console output.

Properties

$excludes

A list of properties to exclude during data manipulation operations like insert, update, replace, or upsert.

public array<string|int, mixed>|mixed|null $excludes = null

$fields

The document's fields to display in tabular output.

public array<string|int, mixed> $fields = [\org\schema\constants\Schema::_KEY, \org\schema\constants\Schema::NAME, \org\schema\constants\Schema::CREATED, \org\schema\constants\Schema::MODIFIED]

$removeKeys

A list of properties to remove during data manipulation operations like insert, update, replace, or upsert.

public array<string|int, mixed>|mixed|null $removeKeys = null

Methods

assertDocuments()

Asserts that the 'documents' property has been initialized.

protected assertDocuments() : void
Tags
throws
UnexpectedValueException

If the 'documents' property is not set.

fetchDocuments()

Fetch all documents from the OpenEdge database.

protected fetchDocuments(OutputInterface $output[, Documents|null $ref = null ][, string $name = 'documents' ][, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>
Parameters
$output : OutputInterface

The console output instance.

$ref : Documents|null = null

The optional Documents reference to use (default, use $this->documents)

$name : string = 'documents'

The optional name of the documents (default "documents").

$init : array<string|int, mixed> = []

An associative array of optional settings to define the query - Documents::list().

Tags
throws
BindException
ContainerExceptionInterface
ArangoException
NotFoundExceptionInterface
ReflectionException
Return values
array<string|int, mixed>

initializeDocuments()

Initializes the 'documents' property.

protected initializeDocuments([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

This method attempts to find a service name in the '$init' array and uses the provided PSR container to retrieve the DocumentsModel instance.

Parameters
$init : array<string|int, mixed> = []

An array of initialization parameters, expected to contain the documents service name.

$container : ContainerInterface|null = null

An optional PSR-11 container for service resolution.

Tags
throws
ContainerExceptionInterface

If an error occurs while retrieving the entry from the container.

NotFoundExceptionInterface

If no entry was found in the container for the given service name.

Return values
static

The instance of the class using this trait, for method chaining.

list()

Executes the action to list all documents from the model.

protected list(InputInterface $input, OutputInterface $output[, mixed|null $option = null ]) : int
Parameters
$input : InputInterface

The console input instance.

$output : OutputInterface

The console output instance.

$option : mixed|null = null

This parameter is currently unused.

Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
ReflectionException
ArangoException
BindException
Return values
int

The exit code for the command, typically ExitCode::SUCCESS.

outputDocuments()

Renders a list of documents to the console output.

protected outputDocuments(array<string|int, mixed> $documents, InputInterface $input, OutputInterface $output[, array<string|int, mixed>|null $fields = null ]) : void

The output format is determined by the verbosity level:

  • Default: Displays the total count of documents found.
  • Verbose (-v): Renders a table with the fields defined in the $this->fields property.
  • Very Verbose (-vv): Outputs the full documents as a prettyprint JSON array.
Parameters
$documents : array<string|int, mixed>

The array of document objects to display.

$input : InputInterface

The console input instance.

$output : OutputInterface

The console output instance.

$fields : array<string|int, mixed>|null = null

The optional fields to display (by default, use the $this->fields property).

On this page

Search results