suvera / winter-boot

Spring Boot styled - PHP8 Framework. Easy Dependency Injection and Easy Aspect Oriented magic just with annotations (Attributes).
MIT License
27 stars 2 forks source link

Winter Boot - PHP 8.0+ Framework

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.

Sample Service

#[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"

1. Example Micro-service

Check out the example application here example-service

2. Installation

1) Install PHP 8.0 (or greater)

2) Asynchronous functions #[Async] and #[Scheduled] to work, swoole extension needed.

pecl install swoole

Composer

Install framework with composer


composer require suvera/winter-boot

composer require suvera/winter-modules

You're Done!

3. Build & Deployment

Framework Support Phing build system

Go through this document Building Service

4. Documentation

5. Module Extensions

This framework can be extended even further by using https://github.com/suvera/winter-modules

How to create new module

Create a new module by extending WinterModule. Check out below modules for reference

6. FAQ

1. How to use other framework components in my project?

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.

2. Can I use RoadRunner or Workerman in my project?

Yes, You can extend framework and create core Application runner classes.

Currently, Swoole is done like this.
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 {
}