codegyan / php-compiler-sdk
SDK for interacting with Codegyan PHP Compiler API
Requires
- php: ^8.1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-02-08 15:05:41 UTC
README
This SDK provides a convenient way to interact with the Codegyan PHP Compiler API, allowing you to compile PHP code programmatically.
Installation
You can install the SDK via Composer. Run the following command:
composer require codegyan/php-compiler-sdk
Usages
Before using the SDK, you need to obtain an API key and client ID from Codegyan. Follow these steps to get your API credentials:
-
Sign Up/Login: If you don't have an account, sign up for a Codegyan account. If you already have an account, log in to your dashboard.
-
Get Credentials: Once logged in, navigate to the Developer Console or API settings in your account dashboard. Here, you will find your API key and client ID. Copy these credentials and use them when initializing the SDK client in your code.
Here's an example of how to initialize the SDK client with your API key and client ID:
<?php require_once 'vendor/autoload.php'; use Codegyan\Compiler\Client; // Replace 'YOUR_API_KEY' and 'YOUR_CLIENT_ID' with your actual API key and client ID $apiKey = 'YOUR_API_KEY'; $clientId = 'YOUR_CLIENT_ID'; // Initialize the SDK client $compiler = new Client($apiKey, $clientId); // PHP code to be compiled $code = '<?php echo "Hello, world!"; ?>'; try { // Compile PHP code $compiledCode = $compiler->compilePHPCode($code); // Decode the JSON string to an associative array $compiledData = json_decode($compiledCode, true); // Check if the compiled code status is equal to 15 if ($compiledData['status'] == 15) { echo "Compiled code: " . $compiledData['output']; } else { echo $compiledCode; } } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } ?>
Features
- Compile PHP Code: The SDK allows you to compile PHP code using the Codegyan PHP Compiler API.
- Error Handling: Proper error handling is implemented to catch and handle exceptions thrown during API requests.
- Customization: You can customize the SDK by passing different parameters to the constructor or by modifying the code to fit your specific requirements.
Testing
The SDK includes PHPUnit tests to ensure its functionality is working as expected. You can run the tests using the following command:
vendor/bin/phpunit
Contributing
Contributions are welcome! Feel free to submit bug reports, feature requests, or pull requests to help improve this SDK.
License
This Codegyan SDK is open-sourced software licensed under the MIT license.