136 lines
3.8 KiB
Bash
136 lines
3.8 KiB
Bash
#!/bin/bash
|
|
|
|
# Script to install Twilio PHP SDK without Composer
|
|
# This is REQUIRED for the plugin to work properly
|
|
|
|
echo "Installing Twilio PHP SDK v8.7.0..."
|
|
echo "IMPORTANT: This SDK is required for the plugin to function."
|
|
|
|
# Check if we can download files
|
|
if ! command -v curl &> /dev/null; then
|
|
echo "ERROR: curl is required to download the SDK"
|
|
echo "Please install curl and try again"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v tar &> /dev/null; then
|
|
echo "ERROR: tar is required to extract the SDK"
|
|
echo "Please install tar and try again"
|
|
exit 1
|
|
fi
|
|
|
|
# Create vendor directory if it doesn't exist
|
|
mkdir -p vendor/twilio/sdk
|
|
|
|
# Download the latest release (8.7.0)
|
|
echo "Downloading Twilio SDK from GitHub..."
|
|
if ! curl -L https://github.com/twilio/twilio-php/archive/refs/tags/8.7.0.tar.gz -o twilio-sdk.tar.gz; then
|
|
echo "ERROR: Failed to download Twilio SDK"
|
|
echo "Please check your internet connection and try again"
|
|
exit 1
|
|
fi
|
|
|
|
# Extract the archive
|
|
echo "Extracting SDK files..."
|
|
if ! tar -xzf twilio-sdk.tar.gz; then
|
|
echo "ERROR: Failed to extract SDK files"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if the extracted directory exists
|
|
if [ ! -d "twilio-php-8.7.0/src" ]; then
|
|
echo "ERROR: Extracted SDK directory structure is unexpected"
|
|
exit 1
|
|
fi
|
|
|
|
# Create the Twilio directory structure
|
|
echo "Setting up SDK directory structure..."
|
|
mkdir -p vendor/twilio
|
|
|
|
# Remove existing SDK if it exists
|
|
if [ -d "vendor/twilio/sdk" ]; then
|
|
rm -rf vendor/twilio/sdk
|
|
fi
|
|
|
|
# Move the entire src directory to be the sdk
|
|
echo "Installing SDK files..."
|
|
if ! mv twilio-php-8.7.0/src vendor/twilio/sdk; then
|
|
echo "ERROR: Failed to move SDK files"
|
|
exit 1
|
|
fi
|
|
|
|
# Create a comprehensive autoloader
|
|
cat > vendor/autoload.php << 'EOF'
|
|
<?php
|
|
/**
|
|
* Twilio SDK v8.7.0 Autoloader
|
|
* This file loads the Twilio PHP SDK classes
|
|
*/
|
|
|
|
// Prevent multiple registrations
|
|
if (!defined('TWILIO_AUTOLOADER_REGISTERED')) {
|
|
define('TWILIO_AUTOLOADER_REGISTERED', true);
|
|
|
|
// Register the autoloader
|
|
spl_autoload_register(function ($class) {
|
|
// Only handle Twilio classes
|
|
if (strpos($class, 'Twilio\\') !== 0) {
|
|
return false;
|
|
}
|
|
|
|
// Convert class name to file path
|
|
$relative_class = substr($class, 7); // Remove 'Twilio\'
|
|
$file = __DIR__ . '/twilio/sdk/' . str_replace('\\', '/', $relative_class) . '.php';
|
|
|
|
if (file_exists($file)) {
|
|
require_once $file;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
// Try to load the SDK's own autoloader if it exists
|
|
$sdk_autoloader = __DIR__ . '/twilio/sdk/autoload.php';
|
|
if (file_exists($sdk_autoloader)) {
|
|
require_once $sdk_autoloader;
|
|
}
|
|
|
|
// Load essential Twilio classes manually to ensure they're available
|
|
$essential_classes = [
|
|
__DIR__ . '/twilio/sdk/Rest/Client.php',
|
|
__DIR__ . '/twilio/sdk/TwiML/VoiceResponse.php',
|
|
__DIR__ . '/twilio/sdk/Exceptions/TwilioException.php',
|
|
__DIR__ . '/twilio/sdk/Security/RequestValidator.php'
|
|
];
|
|
|
|
foreach ($essential_classes as $class_file) {
|
|
if (file_exists($class_file)) {
|
|
require_once $class_file;
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Clean up
|
|
rm -rf twilio-php-8.7.0
|
|
rm twilio-sdk.tar.gz
|
|
|
|
# Verify installation
|
|
echo ""
|
|
echo "Verifying installation..."
|
|
if [ -f "vendor/autoload.php" ] && [ -d "vendor/twilio/sdk" ]; then
|
|
echo "✓ Twilio SDK v8.7.0 installed successfully!"
|
|
echo "✓ Autoloader created"
|
|
echo "✓ Installation complete"
|
|
echo ""
|
|
echo "The Twilio WordPress Plugin is now ready to use."
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Configure your Twilio credentials in WordPress admin"
|
|
echo "2. Set up your phone numbers and webhooks"
|
|
echo "3. Test the installation with a sample call"
|
|
else
|
|
echo "✗ Installation failed - files not found"
|
|
exit 1
|
|
fi |