Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 50 - Add documentation for PHP namespace options #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions content/reference/php/php-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ directory `build/gen/Foo/Bar` if necessary, but it will *not* create `build` or

## Packages {#package}

The package name defined in the `.proto` file is used to generate a module
structure for the generated PHP classes. Given a file like:
The package name defined in the `.proto` file is used by default to generate
a module structure for the generated PHP classes. Given a file like:

```proto
package foo.bar;
Expand All @@ -64,6 +64,34 @@ message MyMessage {}
The protocol compiler generates an output class with the name
`Foo\Bar\MyMessage`.

### Namespace options

The compiler supports additional options to define the PHP and metadata
namespace. When defined these will be used to generate the module structure
and the namespace. Given options like:

```proto
package foo.bar;

option php_namespace = "baz\\qux";

option php_metadata_namespace = "Foo";

message MyMessage {}
```

The protocol compiler generates an output class with the name
`baz\qux\MyMessage`.
The class will have the namespace
`namespace baz\qux;`.

The protocol compiler generates a metadata class with the name
`Foo\Metadata`.
The class will have the namespace
`namespace Foo;`.

_The options are also generated case-sensitive, by default the package is converted to pascal case._

## Messages {#message}

Given a simple message declaration:
Expand Down