contiva / sap-cpi-php
Comprehensive PHP library for SAP Cloud Platform Integration (CPI) APIs with full CRUD operations, cross-system transport, and Auto-Motor examples
Requires
- php: ^7.2 || ^8.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.13
README
Comprehensive PHP library for SAP Cloud Platform Integration (CPI) APIs with full CRUD operations, cross-system transport capabilities, and specialized Auto-Motor integration examples.
๐ Features
- Complete CRUD Operations for all SAP CPI artifact types
- Cross-System Transport capabilities
- All 7 Native SAP CPI Value Mapping APIs implemented
- Auto-Motor Integration Examples for automotive industry
- Factory Pattern for simplified usage
- Environment-based Configuration support
- Comprehensive PhpDoc Documentation
- PSR-12 Coding Standards compliant
- Full Test Coverage with PHPUnit
๐ฆ Installation
Install via Composer:
composer require contiva/sap-cpi-php
Requirements
- PHP 7.2 or higher (PHP 8.0+ recommended)
- Guzzle HTTP 7.0+
- SAP CPI OAuth2 credentials
๐ง Quick Start
Basic Connection Setup
<?php
require_once 'vendor/autoload.php';
use contiva\sapcpiphp\SapCpiFactory;
// Method 1: Direct configuration
$cpi = SapCpiFactory::connect([
'host' => 'your-tenant.it-cpi024.cfapps.eu10-002.hana.ondemand.com',
'oauth' => [
'url' => 'https://your-tenant.authentication.eu10.hana.ondemand.com/oauth/token',
'client_id' => 'your-client-id',
'client_secret' => 'your-client-secret'
]
]);
// Method 2: Environment variables
putenv('SAP_CPI_HOST=your-tenant.it-cpi024.cfapps.eu10-002.hana.ondemand.com');
putenv('SAP_CPI_OAUTH_URL=https://your-tenant.authentication.eu10.hana.ondemand.com/oauth/token');
putenv('SAP_CPI_CLIENT_ID=your-client-id');
putenv('SAP_CPI_CLIENT_SECRET=your-client-secret');
$cpi = SapCpiFactory::fromEnvironment();
Basic Operations
// List all packages
$packages = $cpi->package()->list();
foreach ($packages as $package) {
echo "Package: {$package->Name} ({$package->Id})\n";
}
// Create a new package
$package = $cpi->package();
$package->Id = 'MY_PACKAGE';
$package->Name = 'My Integration Package';
$package->Description = 'Package for custom integrations';
$package->create();
// Create an Integration Flow
$flow = $cpi->artifact();
$flow->Id = 'MY_INTEGRATION_FLOW';
$flow->Name = 'My Integration Flow';
$flow->PackageId = 'MY_PACKAGE';
$flow->create();
๐ Auto-Motor Examples
The library includes specialized support for automotive industry integrations:
Auto-Motor Value Mapping
use contiva\sapcpiphp\SapCpiFactory;
// Create automotive engine mapping
$engineMapping = SapCpiFactory::createAutoMotorValueMapping(
$cpi,
'AUTO_ENGINE_MAPPING',
'AUTO_PACKAGE',
[
'BMW_320i' => 'B48_2.0L_Turbo',
'Mercedes_C200' => 'M264_1.5L_Turbo',
'Audi_A4_2.0T' => 'EA888_2.0L_Turbo',
'VW_Golf_GTI' => 'EA888_2.0L_Turbo'
]
);
$engineMapping->create();
Complete Auto-Motor Suite
// Create complete automotive integration suite
$artifacts = SapCpiFactory::createAutoMotorSuite(
$cpi,
'BMW_INTEGRATION',
[
'BMW_320i' => 'B48_2.0L_Turbo',
'BMW_X3' => 'B58_3.0L_Turbo',
'BMW_M3' => 'S58_3.0L_TwinTurbo'
]
);
echo "Created automotive integration suite:\n";
foreach ($artifacts as $type => $artifact) {
if ($artifact) {
echo "- {$type}: {$artifact->Id}\n";
}
}
Auto-Motor Integration Flow
// Create automotive-specific Integration Flow
$autoFlow = SapCpiFactory::createAutoMotorIntegrationFlow(
$cpi,
'AUTO_ORDER_PROCESSING',
'AUTO_PACKAGE'
);
// Configure automotive endpoints
$autoFlow->changeConfiguration('BMWEndpoint', 'https://bmw-api.com/orders', 'xsd:string');
$autoFlow->changeConfiguration('SAPEndpoint', 'https://sap-erp.com/api', 'xsd:string');
$autoFlow->changeConfiguration('Timeout', '30000', 'xsd:int');
$autoFlow->pushConfiguration();
$autoFlow->create();
$autoFlow->deploy();
๐ Comprehensive API Usage
Value Mappings with Native SAP CPI APIs
use contiva\sapcpiphp\SapCpiValueMapping;
// Create Value Mapping with custom data
$vm = SapCpiValueMapping::fromMappingData(
$cpi,
'COUNTRY_MAPPING',
'Country Code Mapping',
'MY_PACKAGE',
'ISO', // Source Agency
'CountryCode', // Source Schema
'SAP', // Target Agency
'LandCode', // Target Schema
[
['source' => 'US', 'target' => 'USA'],
['source' => 'DE', 'target' => 'DEU'],
['source' => 'FR', 'target' => 'FRA']
]
);
$vm->create();
// Use native SAP CPI APIs
$schema = $vm->getValMapSchema();
$mappings = $vm->getValMaps('ISO', 'CountryCode', 'SAP', 'LandCode');
// Upsert new mappings
$newMappings = [
['source' => 'IT', 'target' => 'ITA'],
['source' => 'ES', 'target' => 'ESP']
];
$vm->upsertValMaps('ISO', 'CountryCode', 'SAP', 'LandCode', $newMappings);
Message Mappings
// Create Message Mapping with XSL transformation
$xslContent = file_get_contents('transformation.xsl');
$messageMapping = SapCpiMessageMapping::fromXsl(
$cpi,
$xslContent,
'ORDER_TRANSFORMATION',
'Order to Invoice Transformation',
'MY_PACKAGE'
);
$messageMapping->create();
$messageMapping->deploy();
Script Collections
// Create Script Collection from ZIP
$zipContent = file_get_contents('scripts.zip');
$scriptCollection = SapCpiScriptCollection::fromZip(
$cpi,
$zipContent,
'UTILITY_SCRIPTS',
'Utility Script Collection',
'MY_PACKAGE'
);
$scriptCollection->create();
// Extract and analyze scripts
$scripts = $scriptCollection->extractScripts();
foreach ($scripts as $filename => $content) {
echo "Script: {$filename}\n";
echo "Size: " . strlen($content) . " bytes\n\n";
}
๐ Cross-System Transport
// Source system
$sourceVM = $sourceCpi->valueMapping('VM_ID');
$sourceVM->pull()->pullContent();
// Transport to target system
$targetVM = $sourceVM->changeConnection($targetCpi);
$targetVM->Id = 'VM_ID_COPY';
$targetVM->create();
๐งช Testing
Run the test suite:
# Run all tests
composer test
# Run with coverage
composer test-coverage
# Run specific test
./vendor/bin/phpunit tests/Unit/SapCpiConnectionTest.php
๐ Code Quality
# Lint code
composer lint
# Fix code style
composer lint-fix
# Static analysis
composer analyze
# Run all checks
composer check
๐ Documentation
All classes are fully documented with PhpDoc comments including:
- Method descriptions with parameters and return types
- Usage examples for all major features
- Auto-Motor specific examples for automotive industry
- Exception handling documentation
- Cross-system transport patterns
Available Classes
SapCpiConnection
- Main connection and authenticationSapCpiPackage
- Package managementSapCpiArtifact
- Integration Flow managementSapCpiValueMapping
- Value Mapping with all 7 native APIsSapCpiMessageMapping
- Message transformation mappingsSapCpiScriptCollection
- Script collection managementSapCpiFactory
- Convenient factory methods
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting:
composer check
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ข About Contiva
This library is developed and maintained by Contiva GmbH, specialists in SAP integration and automotive industry solutions.
๐ Support
- Documentation: Full PhpDoc documentation in source code
- Examples: Comprehensive examples in this README
- Issues: GitHub Issues
- Auto-Motor Examples: Specialized automotive integration patterns included
Made with โค๏ธ for the SAP Integration Community