Download the PHP package butschster/proto-parser without Composer

On this page you can find all versions of the php package butschster/proto-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package proto-parser

PHP Protocol Buffer Parser

A powerful and flexible Protocol Buffers parser for PHP, capable of generating an Abstract Syntax Tree (AST) from .proto files. This package provides a robust foundation for working with Protocol Buffers in PHP projects.

Key Features

Use Cases

Installation

Install the package via Composer:

Usage

Here's a quick example of how to use the Proto Parser:

Understanding AST (Abstract Syntax Tree)

An Abstract Syntax Tree (AST) is a tree representation of the abstract syntactic structure of source code. In the context of this package, the AST represents the structure of a Protocol Buffer definition file.

Here's an example of what an AST looks like for a simple .proto file:

The corresponding AST would look something like this:

Each node in the AST corresponds to a specific element in the Protocol Buffer definition. This structure allows for easy traversal and manipulation of the Protocol Buffer structure programmatically.

AST Class Diagram

The following class diagram provides an overview of the AST node classes available in the Protobuf parser. This diagram shows the relationships between different node classes and their properties.

Detailed Usage Examples

Parsing Messages

Parsing Services

Handling Imports and Options

Example: Generating DTO Classes

One powerful use case for the AST is generating Data Transfer Object (DTO) classes from Protocol Buffer definitions. You can use a code generator (like nette/php-generator) to create PHP classes based on the AST.

Here's an example of how you might use the AST to generate a PHP class:

This would generate a PHP class like this:

There are many possibilities for code generation using the AST. More use cases:

  1. Generate DTOs with Validation Attributes: You can use the AST to generate DTOs with built-in validation using Symfony Validator attributes.

  2. Generate OpenAPI Schema: By parsing the service RPC options, you can automatically generate OpenAPI (Swagger) schema documentation for your API endpoints, keeping your API documentation in sync with your protobuf definitions.

  3. Generate Clean JSON-Serializable DTOs: Create DTOs that are optimized for JSON serialization, ensuring efficient data transfer between your PHP application and other systems or frontends.

  4. Static Analysis Tool Integration: Use the AST to create custom PHPStan or Psalm rules that can analyze your protobuf usage within your PHP codebase, enhancing type safety and catching potential issues early.

  5. Code Migration Assistance: Leverage the AST to help automate code migrations when your protobuf definitions change, ensuring that your PHP code stays in sync with evolving protobuf schemas.

AST Node Classes

This document provides an overview of the available node classes in the Protobuf parser. These classes represent different elements of a Protobuf definition file.

ProtoNode

Represents the root node of a Protobuf file.

SyntaxDeclNode

Represents the syntax declaration of a Protobuf file.

ImportDeclNode

Represents an import statement in a Protobuf file.

PackageDeclNode

Represents a package declaration in a Protobuf file.

OptionDeclNode

Represents an option declaration in a Protobuf file.

MessageDefNode

Represents a message definition in a Protobuf file.

FieldDeclNode

Represents a field declaration within a message.

EnumDefNode

Represents an enum definition in a Protobuf file.

EnumFieldNode

Represents a field within an enum definition.

ServiceDefNode

Represents a service definition in a Protobuf file.

RpcDeclNode

Represents an RPC (Remote Procedure Call) declaration within a service.

MapFieldDeclNode

Represents a map field declaration within a message.

OneofFieldNode

Represents a field within a oneof group.

CommentNode

Represents a comment in the Protobuf file.

ReservedNode

Represents a reserved statement in a message or enum.

OptionNode

Represents an individual option within an option declaration.

Contributing

Contributions are welcome! Please follow these guidelines when contributing to the project:

  1. Fork the repository and create your branch from master.
  2. Ensure that your code follows the PSR-12 coding standard.
  3. If you're modifying the parser grammar:
    • Edit the ebnf.pp2 file to make your changes.
    • Run the unit tests to regenerate the src/grammar.php file.
    • Ensure that all existing tests pass and add new tests to cover your changes.
  4. Update the documentation in the README if you're adding or changing functionality.
  5. Write clear and concise commit messages.
  6. Submit a pull request with a detailed description of your changes.

License

This project is licensed under the MIT License.


All versions of proto-parser with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
phplrt/runtime Version ^3.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package butschster/proto-parser contains the following files

Loading the files please wait ....