Download the PHP package thunderbirddeveloper/snakecharmer without Composer
On this page you can find all versions of the php package thunderbirddeveloper/snakecharmer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thunderbirddeveloper/snakecharmer
More information about thunderbirddeveloper/snakecharmer
Files in thunderbirddeveloper/snakecharmer
Package snakecharmer
Short Description SnakeHandler is a PHP package designed to manipulate and execute Python scripts from within PHP. The package allows you to execute Python scripts, process and manage the results.
License MIT
Informations about the package snakecharmer
Snake Charmer
Snake Charmer is a simple PHP class designed to execute Python scripts conveniently from within a PHP environment. It provides methods to run Python scripts, pass parameters to them, and retrieve the results.
Features
- Execute Python scripts from PHP with ease.
- Pass parameters to Python scripts.
- Retrieve results as strings or arrays.
- Clear script files and results conveniently.
- New: Support for saving script execution results to files.
- New: Methods for switching between memory and file output modes.
Installation
You can install Snake Charmer via Composer. Run the following command in your terminal:
Usage
Here's a basic example of how to use Snake Charmer:
Methods available in the SnakeCharmer class
setPath($path)
Method setting the path to the directory containing Python scripts.
setScripts($files, $clearResult = true)
Method setting the list of scripts to execute.
run($params = '', $last = false)
Method executing scripts with optional parameters.
getResultAsString($separator = "\n")
Method returning the execution results of scripts as a single string.
getResultAsArray()
Method returning the execution results of scripts as an array.
switchOutputToFile()
Method switching the mode of saving script execution results to writing to a file.
switchOutputToMemory()
Method switching the mode of saving script execution results to writing to memory.
getLastExitCode()
Method returning the exit code of the last executed script. 0 means success, non-zero indicates an error.
New Features
- File Output Mode: Snake Charmer can now save the output of script executions to files. Use switchOutputToFile() to enable this mode.
- Memory Output Mode: Default mode where script results are stored in memory. Use switchOutputToMemory() to enable this mode.
- FileManager Integration: Manages the saving and retrieval of script execution results in file mode.
- LastExitCode: You can returning the exit code of the last executed script
Example use cases
You can also add a section describing more complex use cases, such as executing multiple scripts with different parameters, error handling, etc.
Testing
- Running unit tests
SnakeCharmerTest.php contains unit tests for the SnakeCharmer class.
- Running simple test
SimpleTest.php is a script that demonstrates how to use the SnakeCharmer class rather than a traditional unit test file.
When running these commands, make sure your unit tests are correctly defined and have all necessary dependencies loaded, including PHPUnit for unit testing.
Requirements
- PHP version 7.0 or higher
- System shell for executing Python scripts.
Changing Snake Charmer Version
If you need to change the version of Snake Charmer, follow these steps:
- Edit composer.json file: Open the
composer.jsonfile in your project and update the version of Snake Charmer in therequiresection:
Update the version number (^1.0.0) according to Semantic Versioning rules (e.g., ^1.0.1 for MINOR update, ^1.1.0 for MAJOR update).
- Update the library: Then run Composer to update the library to the new version:
Reinstallation
If you need to reinstall Snake Charmer via Composer. Run the following command in your terminal:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Damian Łukasik 08.02.2024