Skip to content

Commit

Permalink
Merge pull request #9 from u-mulder/patch-add-type
Browse files Browse the repository at this point in the history
Добавлена опция "type" для аннотации @sandbox
  • Loading branch information
muxx authored Sep 20, 2021
2 parents f6abee2 + fa4e8f6 commit fcd8b08
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Annotation/Sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
*/
class Sandbox
{
/**
* Type of returned value of target to which annotation applied
*
* List of allowed types is defined in `intaro.twig_sandbox.sandbox_annotation.value_types` parameter
*/
public $type = 'string';
}
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ $ composer update intaro/twig-sandbox-bundle

## Usage

Define allowed properties and methods for your entities throw annotation `@Sandbox`.
Define allowed properties and methods for your entities using annotation `@Sandbox`.
Optionally you can add `type` option for annotation.
This option defines type of value that property stores or method returns.

In your application you can use annotation reader to extract value of `type` option and use this value
to perform additional checks or any other actions, for example, use twig filters according to value of the option.

```php
<?php
Expand Down Expand Up @@ -70,7 +75,7 @@ class Product
/**
* @var string $name
*
* @Sandbox
* @Sandbox(type="string")
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
Expand All @@ -86,7 +91,7 @@ class Product
/**
* Get id
*
* @Sandbox
* @Sandbox(type="int")
* @return integer
*/
public function getId()
Expand Down Expand Up @@ -202,7 +207,7 @@ class Page

### Methods and properties

You can defined allowed entities methods and properties throw annotation `Intaro\TwigSandboxBundle\Annotation\Sandbox`. Example above.
You can define allowed methods and properties of entities with annotation `Intaro\TwigSandboxBundle\Annotation\Sandbox`. Example above.

### Tags

Expand Down Expand Up @@ -300,6 +305,31 @@ parameters:
- 'range'
```

### Allowed types

Default list of allowed return types:
```yml
- 'bool'
- 'collection'
- 'date'
- 'float'
- 'int'
- 'object'
- 'string'
```

You can override list in parameter `intaro.twig_sandbox.sandbox_annotation.value_types`:
```yml
# app/config/config.yml
parameters:
intaro.twig_sandbox.sandbox_annotation.value_types:
- 'string'
- 'date'
- 'collection'
- 'stdClass'
```

### Environment

You can set twig environment parameters:
Expand Down
9 changes: 9 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ parameters:
- 'random'
- 'range'

intaro.twig_sandbox.sandbox_annotation.value_types:
- 'bool'
- 'collection'
- 'date'
- 'float'
- 'int'
- 'object'
- 'string'

services:
intaro.twig_sandbox.loader.annot_class:
class: "%intaro.twig_sandbox.loader.annot_class.class%"
Expand Down

0 comments on commit fcd8b08

Please sign in to comment.