35 lines
874 B
PHP
35 lines
874 B
PHP
<?php
|
|
/**
|
|
* FETCH FILE CONTENTS ACTION
|
|
* -------------------------
|
|
* Demonstrates how to register and implement a simple action that fetches file contents.
|
|
*
|
|
* Call format:
|
|
* @fetchFileContents filename
|
|
*
|
|
* Expected output:
|
|
* The contents of the file with the specified filename
|
|
*/
|
|
|
|
// 1. Register the action with expected argument types
|
|
registerAction(
|
|
(new Action())
|
|
->setFunctionName("fetchFileContents")
|
|
->setArgumentsTypes(["filename"]) // filename
|
|
);
|
|
|
|
/**
|
|
* 2. Implement the function
|
|
*
|
|
* @param string $filename
|
|
* @return string
|
|
* @throws Exception If the file does not exist or cannot be read
|
|
*/
|
|
function fetchFileContents(string $filename): string {
|
|
try {
|
|
return file_get_contents($filename);
|
|
} catch (Exception $e) {
|
|
throw new Exception("Failed to fetch file contents: " . $e->getMessage());
|
|
}
|
|
}
|