Inspired by Spring Boot, you can build micro-services in PHP 8 in that style.
Application:
#[WinterBootApplication]
class MyApplication {
public static function main() {
(new WinterWebSwooleApplication())->run(MyApplication::class);
}
}
MyApplication::main();
This framework gives advantage to people already know Spring Boot, and want to jump into PHP8.
- Dependency Injection is managed by the framework with PHP8 Attributes (Annotations)
#[Service]
class UserServiceImpl implements UserService {
#[Autowired]
private PdbcTemplate $pdbc;
public function createUser(string $name, string $email) {
$this->pdbc->update(/* ... */);
}
}
--------------------------------------------------------------------
#[RestController]
class MyController {
#[Autowired]
private UserService $userService;
#[RequestMapping(path: "/api/v2/users", method: [RequestMethod::POST]]
public function createUser(
#[RequestParam] string $name,
#[RequestParam] string $email
): ResponseEntity {
$this->userService->createUser($name, $email);
return ResponseEntity::ok()->withJson($someJsonArray);
}
}
# curl command
curl "http://localhost/api/v2/users" -d "name=Abc&email=mail"
Check out the example application here example-service
-
Install PHP 8.0 (or greater)
-
Asynchronous functions #[Async] and #[Scheduled] to work,
swoole
extension needed.
pecl install swoole
Install framework with composer
composer require suvera/winter-boot
composer require suvera/winter-modules
You're Done!
Framework Support Phing build system
Go through this document Building Service
- Build phar files
- Build Docker Images - See example-service
- StereoTypes & Dependency Injection
- Configuration
- Logging
- Application Start/Booting
- REST API Development
- Caching
- Custom StereoTypes & Aspect Oriented Magic
- Databases & Transactions
- Actuator
- Locking
- Json and XML
- Async and Scheduling support
- Shared In-Memory Stores
- Daemon Threads
- Building & Deployment
This framework can be extended even further by using https://github.com/suvera/winter-modules
Create a new module by extending WinterModule. Check out below modules for reference
- Doctrine ORM/DBAL Module
- Redis Module
- Apache Kafka Module
- DTCE Module
- S3 Module
- Memdb Module - In-memory databases integrated, such as Apache Ignite, Redis, Memcached, Hazelcast, etc ...
- Service Discovery - Consul, Netflix Eureka, etc...
Yes, any component from any php framework can be used just by composer. Symfony, YII2, Laravel, Code Igniter etc ...
Examples:
# Symfony Security component
composer require symfony/security
# Laravel illuminate events component
composer require illuminate/events
# Yii Arrays Component
composer require yiisoft/arrays --prefer-dist
Make sure that components are PHP8 compatible.
Yes, You can extend framework and create core Application runner classes.
class WinterWebSwooleApplication extends WinterApplicationRunner implements WinterApplication {
}
in the same way that you can also extend framework.
class WinterWebWorkermanApplication extends WinterApplicationRunner implements WinterApplication {
}
class WinterRoadRunnerApplication extends WinterApplicationRunner implements WinterApplication {
}