cloudframework-io / backend-core-php8
CLOUDRAMEWORK PHP8 CORE FRAMEWORK TO DEVELOP BACKEND APIs and SCRIPTs optimized for APPENGINE, FUNCTIONS, KUBERNETS and other server technologies
Installs: 1 401
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 0
Open Issues: 0
pkg:composer/cloudframework-io/backend-core-php8
Requires
- google/apiclient: ^2.18
- google/cloud-bigquery: ^1.34
- google/cloud-core: ^1.68
- google/cloud-datastore: ^1.34
- google/cloud-iam: ^1.2
- google/cloud-kms: ^2.5
- google/cloud-logging: ^1.34
- google/cloud-pubsub: ^2.16
- google/cloud-secret-manager: ^2.2
- google/cloud-storage: ^1.48
- google/cloud-tasks: ^2.1
- google/cloud-translate: ^2.1
- zbateson/mail-mime-parser: ^3.0
- dev-main
- 8.4.11
- 8.4.10
- 8.4.9
- 8.4.8
- 8.4.7
- 8.4.6
- 8.4.5
- 8.4.4
- 8.4.3
- 8.4.2
- 8.4.1
- 8.3.64
- 8.3.63
- 8.3.62
- 8.3.61
- 8.3.60
- 8.3.59
- 8.3.58
- 8.3.57
- 8.3.56
- 8.3.55
- 8.3.54
- 8.3.53
- 8.3.52
- 8.3.51
- 8.3.50
- 8.3.49
- 8.3.48
- 8.3.47
- 8.3.45
- 8.3.44
- 8.3.43
- 8.3.42
- 8.3.41
- 8.3.40
- 8.3.39
- 8.3.38
- 8.3.37
- 8.3.36
- 8.3.35
- 8.3.34
- 8.3.33
- 8.3.32
- 8.3.31
- 8.3.30
- 8.3.29
- 8.3.28
- 8.3.27
- 8.3.26
- 8.3.25
- 8.3.24
- 8.3.23
- 8.3.22
- 8.3.21
- 8.3.20
- 8.3.19
- 8.3.18
- 8.3.17
- 8.3.16
- 8.3.15
- 8.3.14
- 8.3.13
- 8.3.12
- 8.3.11
- 8.3.10
- 8.3.9
- 8.3.8
- 8.3.7
- 8.3.6
- 8.3.5
- 8.3.4
- 8.3.3
- 8.3.2
- 8.3.1
- 8.1.23
- 8.1.22
- 8.1.21
- 8.1.20
- 8.1.19
- 8.1.18
- 8.1.17
- 8.1.16
- 8.1.15
- 8.1.14
- 8.1.13
- 8.1.12
- 8.1.11
- 8.1.10
- 8.1.9
- 8.1.8
- 8.1.7
- 8.1.6
- 8.1.5
- 8.1.4
- 8.1.3
- 8.1.2
- 8.1.1
- dev-development
- dev-documentation
- dev-fix/strlen_null_deprecated
- dev-feature/workflow-email-bcc
This package is auto-updated.
Last update: 2025-11-22 12:06:19 UTC
README
A powerful and flexible PHP8+ framework for building scalable backend APIs and scripts, optimized for Google Cloud Platform (GCP) services including App Engine, Cloud Functions, Compute Engine, and Kubernetes.
Overview
CloudFramework Backend Core is a comprehensive framework designed to accelerate backend development with built-in support for:
- RESTful API Development: Robust API creation with built-in routing, validation, and response handling
- Google Cloud Integration: Native support for Datastore, Cloud Storage, BigQuery, Cloud SQL, and more
- Script Execution: CLI script framework for backend tasks and automation
- Security: Built-in authentication, authorization, and security features
- Data Validation: Comprehensive validation system for API requests
- Caching: Flexible caching strategies for performance optimization
- Logging: Advanced logging with GCP Cloud Logging integration
Requirements
- PHP ^8.3
- Composer
- Python 3.x (for development tools)
- Google Cloud SDK (optional, for GCP deployment)
Quick Links
- GitHub Repository: https://github.com/CloudFramework-io/backend-core-php8
- Packagist: https://packagist.org/packages/cloudframework-io/backend-core-php8
- Documentation: See
/docsdirectory for comprehensive guides
Table of Contents
- Installation
- Quick Start
- Your First API
- Running Scripts
- Configuration
- GCP Setup
- Deployment
- Documentation
- Contributing
- License
Installation
Basic Installation
Install the framework via Composer:
composer require cloudframework-io/backend-core-php8 # if you have problem with GRPC extensions you can use: # composer require cloudframework-io/backend-core-php8 --ignore-platform-req=ext-grpc
Initialize Project Structure
Run the installation script to create the basic project structure:
php vendor/cloudframework-io/backend-core-php8/install.php
This command will create:
./local_data/cache- Local cache directory./api/- API endpoints examples./scripts/- Script examplescomposer.json- Project composer configuration.gitignore- Git ignore rulesapp.yaml- Google App Engine configuration.gcloudignore- GCP deployment ignore rulesREADME.md- Project READMEphp.ini- PHP configurationconfig.json- Framework configuration
Quick Start
Launch Local Development Server
Start the built-in development server:
composer server
The server will start at http://localhost:8080/
Test Your First API
Open your browser and navigate to:
http://localhost:8080/- Main endpoint with API informationhttp://localhost:8080/training/hello- Simple Hello World APIhttp://localhost:8080/training/hello-advanced- Advanced Hello World with endpoints
Example API Response
The response from http://localhost:8080/ will be a JSON:
{
"success": true,
"status": 200,
"code": "ok",
"time_zone": "UTC",
"data": {
"end-point /index [current]": "This end-point defined in <document-root>/api/index.php",
"end-point /training/hello": "Advanced API Structure of Hello World in <document-root>/api/training/hello-advanced.php",
"Current Url Parameters: $this->params": [],
"Current formParameters: $this->formParams": []
},
"logs": [
"[syslog:info] CoreCache: init(). type: directory",
"[syslog:info] RESTful: Url: [GET] http://localhost:8080/"
]
}
Your First API
Simple API Structure
Create a simple API in api/your-endpoint.php:
<?php class API extends RESTful { function main() { // Add data to the response $this->addReturnData('Hello World'); } }
Advanced API with Endpoints
Create an advanced API with multiple endpoints in api/your-service/index.php:
<?php class API extends RESTful { function main() { // Restrict HTTP methods if(!$this->checkMethod('GET,POST,PUT,DELETE')) return; // Route to specific endpoint $endpoint = $this->params[0] ?? 'default'; if(!$this->useFunction('ENDPOINT_'.$endpoint)) { return $this->setErrorFromCodelib('params-error', "Endpoint not found"); } } public function ENDPOINT_default() { $this->addReturnData([ "message" => "Welcome to the API", "endpoints" => ["/hello", "/users", "/data"] ]); } public function ENDPOINT_hello() { if(!$this->checkMethod('GET')) return; $this->addReturnData('Hello from endpoint'); } }
See the training examples in:
api/training/hello.php- Basic API structureapi/training/hello-advanced.php- Advanced API with endpoints
Running Scripts
Execute Scripts
Run background scripts using the CLI:
# Execute a script composer script training/hello # Pass parameters to the script composer script training/hello/world
Script Structure
Create a script in scripts/your-script.php:
<?php class Script extends Scripts2020 { function main() { $method = $this->params[0] ?? 'default'; if (!$this->useFunction('METHOD_' . $method)) { return $this->setErrorFromCodelib('params-error', "Method not found"); } } function METHOD_default() { $this->sendTerminal("Hello from script!"); } }
Configuration
Environment Setup
Configure your development environment (requires GCP SDK for GCP integration):
composer setup
This interactive setup will configure:
- Shell environment (for macOS with zsh)
- CloudFramework Platform connection (optional)
- GCP project settings
- Datastore, Cloud Storage, BigQuery access
- Local cache configuration
Configuration File
Edit config.json to configure your project:
{
"core.gcp.project_id": "your-project-id",
"core.datastore.on": true,
"core.gcp.datastore.project_id": "",
"core.datastorage.on": true,
"core.gcp.datastorage.project_id": "",
"core.bigquery.on": true,
"core.gcp.bigquery.project_id": "",
"development": {
"core.cache.cache_path": "{{rootPath}}/local_data/cache"
}
}
Service Account Credentials
For local development with GCP services, set up credentials:
export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/local_data/service-account.json # Or use composer command composer credentials
macOS Development Environment
For macOS users with zsh, the setup script can configure helpful aliases:
cfserve # Start local development server cfdeploy # Deploy to GCP cfcredentials # Install development credentials cfscript # Run scripts cfgen_password # Generate secure passwords
GCP Setup
Prerequisites
- Install Google Cloud SDK
- Create a GCP project or use an existing one
- Enable required APIs:
- Cloud Datastore API (optional)
- Cloud Storage API (optional)
- BigQuery API (optional)
- Cloud SQL Admin API (optional)
Configure GCP Project
Run the interactive setup to configure GCP services:
composer setup
The setup will prompt you for:
- GCP Project ID
- Enable/disable Datastore, Cloud Storage, BigQuery
- Cache configuration
- Service account credentials
Deployment
Deploy to Google App Engine
- Ensure you have the correct GCP project selected:
gcloud config set project YOUR-PROJECT-ID
- Deploy your application:
gcloud app deploy app.yaml --project=YOUR-PROJECT-ID
- Your application will be available at:
https://YOUR-PROJECT-ID.ew.r.appspot.com
Deploy to Cloud Functions
Create a Cloud Function entry point and deploy:
gcloud functions deploy myFunction \ --runtime php83 \ --trigger-http \ --allow-unauthenticated
Deploy to Cloud Run
Build and deploy as a container:
gcloud run deploy my-api \
--source . \
--platform managed \
--region europe-west1 \
--allow-unauthenticated
Core Features
RESTful API Framework
- Automatic request/response handling
- Built-in routing with URL parameters
- HTTP method validation
- CORS support
- Request validation and sanitization
- Automatic JSON responses
- Error handling with customizable codes
Data Integration
- Google Cloud Datastore: NoSQL database access
- Google Cloud Storage: File storage and management
- Google BigQuery: Data warehouse queries
- Cloud SQL: MySQL/PostgreSQL integration
- MongoDB: NoSQL database support
- PostgreSQL: Direct PostgreSQL access
Security
- Authentication mechanisms
- Authorization and access control
- CORS configuration
- Input validation and sanitization
- XSS and SQL injection protection
- Secure session management
Developer Tools
- Script execution framework
- Logging and debugging
- Performance monitoring
- Caching strategies
- Email sending capabilities
- PDF generation (via tcpdi_cf)
- Template rendering (Twig support)
Documentation
Comprehensive documentation is available in the /docs directory:
- Getting Started Guide - Complete setup and first steps
- API Development - Building RESTful APIs
- Script Development - Creating background scripts
- GCP Integration - Working with Google Cloud services
- API Reference - Detailed class and method documentation
- Configuration Guide - Configuration options
- Deployment Guide - Deploy to various platforms
- Security Best Practices - Security guidelines
- Examples - Code examples and use cases
Framework Architecture
The framework follows a modular architecture:
your-project/
├── api/ # API endpoints
│ ├── index.php # Main API
│ └── training/ # Training examples
├── scripts/ # Background scripts
├── local_data/ # Local development data
│ └── cache/ # Cache directory
├── config.json # Configuration
├── composer.json # Dependencies
└── vendor/
└── cloudframework-io/
└── backend-core-php8/
├── src/
│ ├── Core7.php # Core framework
│ ├── class/ # Framework classes
│ └── dispatcher.php # Request dispatcher
├── runapi.php # API entry point
├── runscript.php # Script entry point
└── install.php # Installation script
Available Classes
Core classes accessible via $this->core:
Core7- Main framework classCoreConfig- Configuration managementCoreCache- Caching systemCoreSecurity- Security featuresCoreRequest- HTTP request handlingCoreSession- Session managementCoreLog- Logging systemCorePerformance- Performance monitoring
Extended functionality classes:
RESTful- API base classScripts2020- Script base classDataStore- Google Cloud DatastoreBuckets- Google Cloud StorageDataBQ- BigQuery integrationCloudSQL- Cloud SQL accessEmail- Email sendingDataValidation- Input validationWorkFlows- Workflow management
See the API Reference for detailed documentation.
Contributing
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Coding Standards
- Follow PSR-12 coding standards
- Write clear, documented code
- Include unit tests for new features
- Update documentation as needed
Support
- Issues: GitHub Issues
- Documentation: Documentation Directory
- Website: https://cloudframework.io
Authors
- Héctor López - hl@cloudframework.io
- Fran Herrera - fran@cloudframework.io
- Adrian Martínez - am@cloudframework.io
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with support for Google Cloud Platform
- Integrated with various Google Cloud services
- Optimized for App Engine, Cloud Functions, Cloud Run, and Kubernetes
CloudFramework - Accelerating backend development since 2013