DocumentsCommandLast uses trait:short
Provides the implementation for a 'last' command action.
This trait should be used in a Symfony Console command that needs to retrieve and display a last document modified in the model.
Example 1 : use the 'modified' property by default.
bin/console command:places last -v
Command:places
==============
Fetching the last `modified` document.
--------------------------------
Document Found: 1
---------- ----------- ---------------------- ----------------------
_key Name Created Modified
---------- ----------- ---------------------- ----------------------
65910397 Marseille 2025-08-25T10:06:26Z 2025-08-25T10:06:26Z
---------- ----------- ---------------------- ----------------------
✅ Done in 5 ms
----------------
Thank you and see you soon!
Example 2 : use the 'created' property.
bin/console command:places last created -v
Command:places
==============
Fetching the last `created` document.
--------------------------------
Document Found: 1
---------- ----------- ---------------------- ----------------------
_key Name Created Modified
---------- ----------- ---------------------- ----------------------
65910397 Marseille 2025-08-25T10:06:26Z 2025-08-25T10:06:26Z
---------- ----------- ---------------------- ----------------------
✅ Done in 5 ms
----------------
Thank you and see you soon!
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.
- last() : int
- Executes the action to fetch and display the last document in the model.
- outputDocuments() : void
- Renders a list of documents to the console output.
Properties
$documents
The DocumentsModel instance for data operations.
public
Documents|null
$documents
$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
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
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
Return values
static —The instance of the class using this trait, for method chaining.
last()
Executes the action to fetch and display the last document in the model.
protected
last(InputInterface $input, OutputInterface $output[, array<string|int, mixed> $option = [] ]) : int
Parameters
- $input : InputInterface
-
The console input instance.
- $output : OutputInterface
-
The console output instance.
- $option : array<string|int, mixed> = []
-
An array of optional parameters to send in the command.
Tags
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->fieldsproperty. - 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).