Skip to content

Commit

Permalink
Kick off
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Oct 1, 2024
1 parent 9e006d4 commit f0f3119
Show file tree
Hide file tree
Showing 125 changed files with 2,514 additions and 288 deletions.
43 changes: 42 additions & 1 deletion .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ composer require contributte/mate --dev

1. Create `.mate.neon` in your project root.

You can initialize it by running `vendor/bin/mate init`. Or you can create it manually.

```neon
data:
user:
Expand All @@ -26,9 +28,48 @@ data:
2. Run `vendor/bin/mate` or `php mate.phar` in your project root.

```
php mate.phar craft
vendor/bin/mate craft
```

## Configuration

Under construction.

## Usage

### `mate init`

Create `.mate.neon` in your project.

### `mate craft`

Generate files based on `.mate.neon`.

```bash
vendor/bin/mate craft --struct user
```

```bash
vendor/bin/mate craft --struct user --crafter=entity
vendor/bin/mate craft --struct user --crafter=repository

vendor/bin/mate craft --struct user --crafter=bus --mode=create
vendor/bin/mate craft --struct user --crafter=bus --mode=update
vendor/bin/mate craft --struct user --crafter=bus --mode=delete
vendor/bin/mate craft --struct user --crafter=bus --mode=list
vendor/bin/mate craft --struct user --crafter=bus --mode=get

vendor/bin/mate craft --struct user --crafter=api --mode=create
vendor/bin/mate craft --struct user --crafter=api --mode=update
vendor/bin/mate craft --struct user --crafter=api --mode=delete
vendor/bin/mate craft --struct user --crafter=api --mode=list
vendor/bin/mate craft --struct user --crafter=api --mode=get
```

### `mate generate`

Generate whole project based on `.mate.neon`.

```bash
vendor/bin/mate generate --template api
```
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
],
"require": {
"php": ">=8.2",
"nette/di": "^3.2.2",
"nette/php-generator": "^4.1.6",
"nette/utils": "^4.0.5",
"nette/neon": "^3.4.3",
"nette/schema": "^1.3.0",
"latte/latte": "^3.0.18",
"symfony/console": "^7.1.5"
"symfony/console": "^7.1.5",
"nette/safe": "^1.0.0"
},
"require-dev": {
"contributte/qa": "^0.4.0",
Expand Down
9 changes: 8 additions & 1 deletion examples/d01/.mate.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
data:
mate:
presets: [moderntv]

app:
scopes: [database, bus, api]

structs:
user:
fields:
username: {type: string}
email: {type: string}
password: {type: string}
createdAt: {type: Nette\Utils\DateTime}
updatedAt: {type: Nette\Utils\DateTime}
roles: {type: array}
28 changes: 28 additions & 0 deletions examples/d01/app/Api/User/Create/CreateUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Create;

use App\Api\AbstractController;
use App\Model\Api\Request\RequestFactory;
use Contributte\FrameX\Http\IResponse;
use Moderntv\Messenger\Bus\CommandBus;
use Psr\Http\Message\ServerRequestInterface;

final class CreateUserController extends AbstractController
{

public function __construct(
private readonly CommandBus $bus,
private readonly RequestFactory $requestFactory,
)
{
}

public function __invoke(ServerRequestInterface $serverRequest): IResponse
{
// TODO
}

}
16 changes: 16 additions & 0 deletions examples/d01/app/Api/User/Create/CreateUserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Create;

final readonly class CreateUserRequest
{

public function __construct(
public CreateUserRequestBody $body,
)
{
}

}
38 changes: 38 additions & 0 deletions examples/d01/app/Api/User/Create/CreateUserRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Create;

use App\Domain\User\Database\User;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

final class CreateUserRequestBody
{

public string $username;

public string $email;

public string $password;

public Nette\Utils\DateTime $createdAt;

public Nette\Utils\DateTime $updatedAt;

public array $roles;

public static function schema(): Schema
{
return Expect::structure([
'username' => Expect::string()->required(),
'email' => Expect::string()->required(),
'password' => Expect::string()->required(),
'createdAt' => Expect::string()->required(),
'updatedAt' => Expect::string()->required(),
'roles' => Expect::string()->required(),
])->castTo(self::class);
}

}
20 changes: 20 additions & 0 deletions examples/d01/app/Api/User/Create/CreateUserResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Create;

use Contributte\FrameX\Http\EntityResponse;

final class CreateUserResponse extends EntityResponse
{

public static function of(UserDto $dto): self
{
$self = self::create();
$self->payload = $dto;

return $self;
}

}
28 changes: 28 additions & 0 deletions examples/d01/app/Api/User/Delete/DeleteUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Delete;

use App\Api\AbstractController;
use App\Model\Api\Request\RequestFactory;
use Contributte\FrameX\Http\IResponse;
use Moderntv\Messenger\Bus\CommandBus;
use Psr\Http\Message\ServerRequestInterface;

final class DeleteUserController extends AbstractController
{

public function __construct(
private readonly CommandBus $bus,
private readonly RequestFactory $requestFactory,
)
{
}

public function __invoke(ServerRequestInterface $serverRequest): IResponse
{
// TODO
}

}
19 changes: 19 additions & 0 deletions examples/d01/app/Api/User/Delete/DeleteUserResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Delete;

use Contributte\FrameX\Http\DataResponse;

final class DeleteUserResponse extends DataResponse
{

public static function of(): self
{
$self = self::create();

return $self;
}

}
28 changes: 28 additions & 0 deletions examples/d01/app/Api/User/Get/GetUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Get;

use App\Api\AbstractController;
use App\Model\Api\Request\RequestFactory;
use Contributte\FrameX\Http\IResponse;
use Moderntv\Messenger\Bus\CommandBus;
use Psr\Http\Message\ServerRequestInterface;

final class GetUserController extends AbstractController
{

public function __construct(
private readonly CommandBus $bus,
private readonly RequestFactory $requestFactory,
)
{
}

public function __invoke(ServerRequestInterface $serverRequest): IResponse
{
// TODO
}

}
15 changes: 15 additions & 0 deletions examples/d01/app/Api/User/Get/GetUserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Get;

final readonly class GetUserRequest
{

public function __construct(
)
{
}

}
20 changes: 20 additions & 0 deletions examples/d01/app/Api/User/Get/GetUserResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\Get;

use Contributte\FrameX\Http\EntityResponse;

final class GetUserResponse extends EntityResponse
{

public static function of(UserDto $dto): self
{
$self = self::create();
$self->payload = $dto;

return $self;
}

}
28 changes: 28 additions & 0 deletions examples/d01/app/Api/User/List/ListUserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\List;

use App\Api\AbstractController;
use App\Model\Api\Request\RequestFactory;
use Contributte\FrameX\Http\IResponse;
use Moderntv\Messenger\Bus\CommandBus;
use Psr\Http\Message\ServerRequestInterface;

final class ListUserController extends AbstractController
{

public function __construct(
private readonly CommandBus $bus,
private readonly RequestFactory $requestFactory,
)
{
}

public function __invoke(ServerRequestInterface $serverRequest): IResponse
{
// TODO
}

}
15 changes: 15 additions & 0 deletions examples/d01/app/Api/User/List/ListUserRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\List;

final readonly class ListUserRequest
{

public function __construct(
)
{
}

}
26 changes: 26 additions & 0 deletions examples/d01/app/Api/User/List/ListUserRequestFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types = 1);

namespace App\Api\User\List;

use App\Model\Api\Request\RequestFilter;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

class ListUserRequestFilter extends RequestFilter
{

public static function schema(): Schema
{
return RequestFilter::extend([
'o' => Expect::structure([
'username' => Expect::anyOf('asc', 'desc'),
])->required(false)->castTo('array'),
'q' => Expect::structure([
'username' => Expect::string(),
])->required(false)->castTo('array'),
])->castTo(self::class);
}

}
Loading

0 comments on commit f0f3119

Please sign in to comment.