Telegram Group & Telegram Channel
Ну что, за два дня готов пакет для построения AST для protobuf 👩‍💻 butschster/proto-parser . Уверен всплывут баги и т.д., но тесты есть, кучу edge кейсов покрыл.

Чем он крут? Можно взять proto-файлы, превратить их в дерево PHP-объектов (AST) и далее сгенерировать свои DTO-классы. Например:

syntax = "proto3";

package examplepb;

message Person {
// Unique identifier for the person.
uint64 id = 1 [(validate.rules).uint64.gt = 999];

// Email address will be used for communication.
string email = 2 [(validate.rules).string.email = true];

// Full name of the person.
string name = 3 [(validate.rules).string = {
pattern: "^[A-Za-z]+( [A-Za-z]+)*$",
max_bytes: 256
}];

// Home location of the person.
Location home = 4 [(validate.rules).message.required = true];

message Location {
double lat = 1 [(validate.rules).double = {gte: -90, lte: 90}];
double lng = 2 [(validate.rules).double = {gte: -180, lte: 180}];
}
}

service ExampleService {
// Create a new person.
rpc CreatePerson(Person) returns (Person) {
option (google.api.http) = {
post: "/v1/persons"
body: "*"
};
}
}


Превратим в:

use Symfony\Component\Validator\Constraints as Assert;

final readonly class Person
{
public function __construct(
/** Unique identifier for the person. */
#[Assert\GreaterThan(value: 999)]
public int $id,
/** Email address will be used for communication. */
#[Assert\Email]
public string $email,
/** Full name of the person. */
#[Assert\Regex(pattern: '^[A-Za-z]+( [A-Za-z]+)*$'), Assert\Length(max: 256, charset: '8bit')]
public string $name,
/** Home location of the person. */
#[Assert\NotNull]
public Location $home,
) {
}
}


use Symfony\Component\Validator\Constraints as Assert;

final readonly class Location
{
public function __construct(
#[Assert\GreaterThanOrEqual(value: -90), Assert\LessThanOrEqual(value: 90)]
public float $lat,
#[Assert\GreaterThanOrEqual(value: -180), Assert\LessThanOrEqual(value: 180)]
public float $lng,
) {
}
}


<?php

declare(strict_types=1);

namespace Internal;

use App\Grpc\Service;
use OpenApi\Annotations as OA;
use Spiral\RoadRunner\GRPC\ContextInterface;

#[Service(name: 'ExampleService', package: 'examplepb')]
interface ExampleServiceInterface
{
/**
* Create a new person.
*/
#[OA\Post(path: '/v1/persons', tags: ['CreatePerson'])]
#[OA\RequestBody(path: '*', tags: ['CreatePerson'])]
public function CreatePerson(ContextInterface $ctx, Person $in): Person;
}




Что умеет:
1. Строить дерево. Понимает весь синтаксис, что я смог найти.
2. Привязывать комментарии к нодам. Например комментарий над полем будет в ноде поля. Комментарий к option будет в его ноде. И т.д.
3. Дока есть.

Что не умеет:
ХЗ что. призываю потестить и улучшить желающих.

Прогнал свой проект с > 100 proto файлов, все спарсил.

P.s. Ах да, забыл сказать, что эти DTO сгененировал мой другой пакет, который уже умеет работать с AST. Сделан на коленке, поэтому еще не выкладывал.
Please open Telegram to view this post
VIEW IN TELEGRAM
3🔥30



tg-me.com/php_fart/100
Create:
Last Update:

Ну что, за два дня готов пакет для построения AST для protobuf 👩‍💻 butschster/proto-parser . Уверен всплывут баги и т.д., но тесты есть, кучу edge кейсов покрыл.

Чем он крут? Можно взять proto-файлы, превратить их в дерево PHP-объектов (AST) и далее сгенерировать свои DTO-классы. Например:

syntax = "proto3";

package examplepb;

message Person {
// Unique identifier for the person.
uint64 id = 1 [(validate.rules).uint64.gt = 999];

// Email address will be used for communication.
string email = 2 [(validate.rules).string.email = true];

// Full name of the person.
string name = 3 [(validate.rules).string = {
pattern: "^[A-Za-z]+( [A-Za-z]+)*$",
max_bytes: 256
}];

// Home location of the person.
Location home = 4 [(validate.rules).message.required = true];

message Location {
double lat = 1 [(validate.rules).double = {gte: -90, lte: 90}];
double lng = 2 [(validate.rules).double = {gte: -180, lte: 180}];
}
}

service ExampleService {
// Create a new person.
rpc CreatePerson(Person) returns (Person) {
option (google.api.http) = {
post: "/v1/persons"
body: "*"
};
}
}


Превратим в:

use Symfony\Component\Validator\Constraints as Assert;

final readonly class Person
{
public function __construct(
/** Unique identifier for the person. */
#[Assert\GreaterThan(value: 999)]
public int $id,
/** Email address will be used for communication. */
#[Assert\Email]
public string $email,
/** Full name of the person. */
#[Assert\Regex(pattern: '^[A-Za-z]+( [A-Za-z]+)*$'), Assert\Length(max: 256, charset: '8bit')]
public string $name,
/** Home location of the person. */
#[Assert\NotNull]
public Location $home,
) {
}
}


use Symfony\Component\Validator\Constraints as Assert;

final readonly class Location
{
public function __construct(
#[Assert\GreaterThanOrEqual(value: -90), Assert\LessThanOrEqual(value: 90)]
public float $lat,
#[Assert\GreaterThanOrEqual(value: -180), Assert\LessThanOrEqual(value: 180)]
public float $lng,
) {
}
}


<?php

declare(strict_types=1);

namespace Internal;

use App\Grpc\Service;
use OpenApi\Annotations as OA;
use Spiral\RoadRunner\GRPC\ContextInterface;

#[Service(name: 'ExampleService', package: 'examplepb')]
interface ExampleServiceInterface
{
/**
* Create a new person.
*/
#[OA\Post(path: '/v1/persons', tags: ['CreatePerson'])]
#[OA\RequestBody(path: '*', tags: ['CreatePerson'])]
public function CreatePerson(ContextInterface $ctx, Person $in): Person;
}




Что умеет:
1. Строить дерево. Понимает весь синтаксис, что я смог найти.
2. Привязывать комментарии к нодам. Например комментарий над полем будет в ноде поля. Комментарий к option будет в его ноде. И т.д.
3. Дока есть.

Что не умеет:
ХЗ что. призываю потестить и улучшить желающих.

Прогнал свой проект с > 100 proto файлов, все спарсил.

P.s. Ах да, забыл сказать, что эти DTO сгененировал мой другой пакет, который уже умеет работать с AST. Сделан на коленке, поэтому еще не выкладывал.

BY PHP Fart Time




Share with your friend now:
tg-me.com/php_fart/100

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

telegram from us


Telegram PHP Fart Time
FROM USA