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.
#[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
1) Install PHP 8.0 (or greater)
2) 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
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
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 {
}