Skip to content

Commit

Permalink
report and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oliwierptak committed Aug 9, 2021
1 parent b55a61c commit 3a7cd0c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 194 deletions.
251 changes: 60 additions & 191 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ composer require popo/generator --dev

```sh
vendor/bin/popo generate -s <schema-path> \
[-c <shared-schema-config>] \
[-o <output-path>] \
[-nm <namespace>] \
[-nr <namespace-root>] \
[-p <schema-path-filter>]
-c [schema-config-filename] \
-o [output-path] \
-nm [namespace] \
-nr [namespace-root] \
-p [schema-path-filter]
```

_For example: `bin/popo generate -s tests/fixtures`_
_For example: `bin/popo generate -s tests/fixtures/popo.yml`_

#### `<schema-path>`

This parameter can either be a path to YAML file, or to a directory, under where YAML configuration files are stored.

This parameter is required.

#### `[shared-schema-config]`
#### `[schema-config-filename]`

This parameter is optional, but when set a shared schema configuration will be used for all POPO schemas.

Expand Down Expand Up @@ -163,10 +163,58 @@ For example, each schema folder can contain multiple schema files:
|-- shared.config.yml
```
## Popo Schema
### Report
The `report` command shows list of defined / inherited properties.
```sh
vendor/bin/popo report -s <schema-path> \
-c [schema-config-filename] \
-p [schema-path-filter]
```
#### `<schema-path>`
This parameter can either be a path to YAML file, or to a directory, under where YAML configuration files are stored.
This parameter is required.
#### `[schema-config-filename]`
This parameter is optional, but when set a shared schema configuration will be used for all POPO schemas.
## POPO Schema
POPO Schema can be defined and extended on few levels, and it can be defined in multiple files.
The `popo-config` values override `schema-config` values, and `schema-config` values overwrite `file-config` values.
On top of that, there is a `global-config` that is defined when using `--schemaConfigFilename` parameter.
![](doc/popo_schema.png)
### `file-config`
The configuration was defined as a `SchemaFile` property.
It will be used by all POPO objects in current file.
### `schema-config`
The configuration was defined as a `Schema` property.
It will be used by all POPO objects in current file, under given schema.
### `popo-config`
The configuration was defined as a POPO property.
It will be used by one specific POPO objects in current file, under given schema.
```yaml
$: #shared configuration for all POPO objects defined below
$: # file-config
config:
namespace: string
outputPath: string
Expand All @@ -177,7 +225,7 @@ $: #shared configuration for all POPO objects defined below
default: array # default values
property: array #shared properties
SchemaName: #defines shared configuration and POPO objects under SchemaName
SchemaName: # schema-config
$: # shared configuration for all POPO objects in SchemaName
config:
namespace: string
Expand All @@ -199,7 +247,7 @@ SchemaName: #defines shared configuration and POPO objects under SchemaName
itemName: string|null # collection item singular name
}]
PopoName:
PopoName: # popo-config
config:
namespace: string
outputPath: string
Expand All @@ -221,186 +269,7 @@ SchemaName: #defines shared configuration and POPO objects under SchemaName
}]
```

### Popo Schema Examples

#### tests/fixtures/popo.yml

```yaml
$:
config:
namespace: App\Example\Popo
outputPath: tests/
comment: Popo Example. Auto-generated.
default:
title: Hakuna Matata
idForAll: 10
property: [
{name: idForAll, type: int, comment: This property is used in ALL schemas under CURRENT popo file}
]

Example:
$:
config:
comment: Example lorem ipsum
default:
title: Example Hakuna Matata
idForAll: 20
property: [
{name: idFromExampleSchema, type: int, default: 20, comment: This property is used in ALL schemas under Example schema}
]
Foo:
config:
comment: Foo example lorem ipsum
default:
title: Example Foo Hakuna Matata
bar: Bar::class
idForAll: 30
property: [
{name: fooId, type: int, comment: Foo ID COMMENT}
{name: title}
{name: value, type: int, default: \App\ExampleInterface::TEST_BUZZ}
{name: bar, type: popo}
{name: test, type: mixed}
]}}

Bar:
default:
title: Lorem Ipsum
buzz: \App\Example\Popo\Buzz\Buzz::class
idForAll: 40
property: [
{name: title}
{name: buzz, type: popo}
{name: buzzCollection, type: array, itemType: \App\Example\Popo\Buzz\Buzz::class, itemName: buzz}
]}}

Buzz:
config:
namespace: App\Example\Popo\Buzz
property: [
{name: value, default: Buzzzzz}
]}}

AnotherExample:
$:
config:
comment: Another example lorem ipsum
default:
idForAnotherExample: 100
property: [
{name: idForAnotherExample, type: int, comment: This property is used in ALL schemas under AnotherExample schema}
{name: description}
]
AnotherFoo:
default:
idForAnotherExample: 200
property: [
{name: title}
]}}
```

_Run `bin/popo generate-s tests/fixtures/popo.yml` to generate files from this schema._

## Extendable Schema

One schema file can modify other schema file at any point.

In the example below, the property `description` defined in `bar.popo.yml` will be added to
`AnotherFoo` POPO object which is "originally" defined in `foo.popo.yml`.

#### tests/fixtures/bundles/project.config.yml

Shared schema between all POPO objects under `tests/fixtures/bundles/`.

```yaml
$:
config:
namespace: App\Example\Shared
outputPath: tests/
comment: Popo Example. Auto-generated.
default:
title: Hakuna Matata
property: [
{name: idForAll, type: int, default: 0, comment: This id is for all}
]}}

Example:
$:
config:
extend: App\AbstractExample::class
implement: App\ExampleInterface::class
default:
sharedExampleId: 123
property: [
{name: sharedExampleId, type: int}
]}}

AnotherExample:
$:
default:
anotherExampleSharedId: 100
property: [
{name: anotherExampleSharedId, type: int}
]}}
```

#### tests/fixtures/bundles/example-foo/foo.popo.yml

```yaml
Example:
Foo:
config:
comment: Foo example lorem ipsum
default:
bar: Bar::class
property: [
{name: fooId, type: int, comment: Foo ID COMMENT}
{name: title}
{name: value, type: int, default: \App\ExampleInterface::TEST_BUZZ}
{name: bar, type: popo}
{name: test, type: mixed}
]}}

AnotherExample:
$:
config:
comment: Another example lorem ipsum
default:
anotherExampleSharedId: 567
property: [
{name: idForAnotherExample, type: int, default: 999, comment: This id is for AnotherExample}
]
AnotherFoo:
property: [
{name: title}
]}}
```

#### tests/fixtures/bundles/example-bar/bar.popo.yml

```yaml
Example:
Bar:
default:
title: Lorem Ipsum
buzz: \App\Example\Shared\Buzz\Buzz::class
property: [
{name: title}
{name: buzz, type: popo}
{name: buzzCollection, type: array, itemType: \App\Example\Shared\Buzz\Buzz::class, itemName: buzz}
]}}

AnotherExample:
AnotherFoo:
default:
description: Another Lorem Ipsum
property: [
{name: description}
]}}
```

_Run `bin/popo generate -c tests/fixtures/bundles/project.config.yml -s tests/fixtures/bundles/` to generate files from
this example._
See [tests/fixtures](tests/fixtures/) for schema examples.

### Property type list

Expand Down
Binary file added doc/popo_schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Popo/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function configure(): void
's',
InputOption::VALUE_REQUIRED,
'Path to schema file or directory',
'popo.yml'
null
),
new InputOption(
static::OPTION_SCHEMA_CONFIG_FILENAME,
Expand Down
2 changes: 1 addition & 1 deletion src/Popo/Model/Report/ReportResultItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function markAsSchemaConfig(): self

public function markAsPropertyConfig(): self
{
$this->type = PopoDefinesInterface::VALIDATION_TYPE_PROPERTY_CONFIG;
$this->type = PopoDefinesInterface::VALIDATION_TYPE_POPO_CONFIG;

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Popo/PopoDefinesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PopoDefinesInterface

public const VALIDATION_TYPE_SCHEMA_CONFIG = 'schema-config';

public const VALIDATION_TYPE_PROPERTY_CONFIG = 'property-config';
public const VALIDATION_TYPE_POPO_CONFIG = 'popo-config';

public const CONFIGURATION_SCHEMA_OPTION_SYMBOL = '$';

Expand Down

0 comments on commit 3a7cd0c

Please sign in to comment.