Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haehnchen/idea-php-annotation-plugin
Add PHP annotation support for PhpStorm and IntelliJ
https://github.com/haehnchen/idea-php-annotation-plugin
annotation doctrine intellij intellij-plugin java phpstorm phpstorm-plugin symfony
Last synced: 1 day ago
JSON representation
Add PHP annotation support for PhpStorm and IntelliJ
- Host: GitHub
- URL: https://github.com/haehnchen/idea-php-annotation-plugin
- Owner: Haehnchen
- License: mit
- Created: 2013-09-22T09:50:45.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-16T16:08:01.000Z (29 days ago)
- Last Synced: 2024-10-29T11:11:12.587Z (16 days ago)
- Topics: annotation, doctrine, intellij, intellij-plugin, java, phpstorm, phpstorm-plugin, symfony
- Language: Java
- Homepage: https://plugins.jetbrains.com/plugin/7320
- Size: 36.9 MB
- Stars: 251
- Watchers: 15
- Forks: 41
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
IntelliJ IDEA - PhpStorm PHP Annotations / Attributes
==========================
[![Build Status](https://github.com/Haehnchen/idea-php-annotation-plugin/actions/workflows/gradle.yml/badge.svg?branch=master)](https://github.com/Haehnchen/idea-php-annotation-plugin/actions/workflows/gradle.yml)
[![Version](http://phpstorm.espend.de/badge/7320/version)](https://plugins.jetbrains.com/plugin/7320)
[![Downloads](http://phpstorm.espend.de/badge/7320/downloads)](https://plugins.jetbrains.com/plugin/7320)
[![Downloads last month](http://phpstorm.espend.de/badge/7320/last-month)](https://plugins.jetbrains.com/plugin/7320)
[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/DanielEspendiller)Provides PHP annotation extended Attribute support and for PhpStorm / IntelliJ IDEA and references for "Code > Optimize Imports" action.
| Key | Value |
|------------|-------------------------------------------|
| Plugin url | https://plugins.jetbrains.com/plugin/7320 |
| Id | de.espend.idea.php.annotation |
| Changelog | [CHANGELOG](CHANGELOG.md) |### Install
* [Download plugin](https://plugins.jetbrains.com/plugin/7320) or install directly out of PhpStorm
* Force file reindex if necessary with: `File -> Invalidate Cache`### Settings
`PHP > Annotations / Attributes`
#### Round brackets
```php
/**
* @Foo()
* @Foo
*/
class NotBlank extends Constraint {}
```#### Use / Import alias
`PHP -> Annotations / Attributes -> Use Alias`
##### Annotations
```php
use Doctrine\ORM\Mapping as ORM;
/**
* @Id() -> @ORM\Id()
* @NotBlank() -> @Assert\NotBlank()
*/
class Foo {}
```##### Attributes
```php
use Doctrine\ORM\Mapping as ORM;
#[Id] -> #[ORM\Id()]
#[NotBlank] -> #[Assert\NotBlank()]
class Foo {}
```#### Class LineMarker
LineMarker which provide navigation to annotation class usages
```php
namespace Doctrine\ORM\Mapping;/**
* @Annotation
*/
final class Entity implements Annotation
{
}
```Targeting
```php
/**
* @ORM\Entity()
*/
```### Annotation Class Detection
* Every class with `@Annotation` inside class doc block is detected on file indexing
* Annotation Properties on property names
* Property value types
* @ENUM Tags```php
/**
* @Annotation
*/
class NotBlank extends Constraint {
public $message = 'This value should not be blank.';
public $groups = array();/**
* @var bool|boolean
*/
public $option = false;/**
*
* @Enum({"AUTO", "SEQUENCE", "TABLE", "IDENTITY", "NONE", "UUID", "CUSTOM"})
*/
public $strategy = 'AUTO';/**
* @var array
*/
public $cascade;
/**
* @var mixed|foobar|bool
*/
public $mixed;
}
```https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/custom.html#attribute-types
```php
/**
* @Annotation
*
* @Attributes({
* @Attribute("stringProperty", type = "string"),
* @Attribute("annotProperty", type = "bool"),
* })
*/
*
* @Attributes(
* @Attribute("stringProperty", type = "string"),
* @Attribute("annotProperty", type = "bool"),
* )
*/
class Foobar {}
```### Annotation Target Detection
`@Target` is used to attach annotation, if non provided its added to "ALL list"
```php
/**
* @Annotation
* @Target("PROPERTY", "METHOD", "CLASS", "ALL")
*/
class NotBlank extends Constraint {
public $message = 'This value should not be blank.';
}
```### Extension Points
Plugins provides several extension points, which allows external plugins to provide additional. See some examples on [Symfony2 Plugin](https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/master/META-INF/plugin.xml)
Example for extension points.
```xml
```
Usage
```xml
```
### PHP Attributes Bridge
All extensions points providing support to DocBlock and PHP Attributes at the same time.
```php
use Symfony\Component\Validator\Constraints\NotBlank;#[NotBlank(message: 'An empty file is not allowed.')]
/* @NotBlank({message: "An empty file is not allowed."}) */
``````php
#[Template('foo.html.twig')]
/* @Template("foo.html.twig") */
```### Completion confidence
Annoying pressing completion shortcut? Plugin provides a nice completion confidence to open completion popover on several conditions
```php
/**
* @
*
*/
```### Static values
```php
/**
* @DI\Observe(SomethingEvents::PRE_UPDATE)
*/
```### Doctrine
#### ORM: Property generator
```php
class Foo {
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
public $id;
}
``````php
class Foo {
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
public $id;
}
```#### ORM: class entity generator
```php
#[ORM\Entity(repositoryClass: \Foo::class)]
#[ORM\Table(name: 'bike')]
class Foo { }
```#### ORM: repository class generator / intention
```php
/**
* @ORM\Entity(repositoryClass="UnknownClass")
*/
class Foo { }
``````php
/**
* @ORM\Entity
*/
class Foo { }
```#### ORM: repository class completion
```php
/**
* @ORM\Entity(repositoryClass="")
*/
```### PHP Toolbox
Provides integration for [PHP Toolbox](https://github.com/Haehnchen/idea-php-toolbox)
#### Default and property values
```php
use Symfony\Component\Routing\Annotation\Route;/**
* @Route("")
* @Route(condition="")
*/
``````javascript
{
"registrar":[
{
"signatures":[
{
"class": "Symfony\\Component\\Routing\\Annotation\\Route",
"type": "annotation"
},
{
"class": "Symfony\\Component\\Routing\\Annotation\\Route",
"field": "condition",
"type": "annotation"
}
],
"provider":"foo",
"language":"php"
}
],
}
```#### Property array values
```php
use Symfony\Component\Routing\Annotation\Route;/**
* @Route(methods={""})
*/
``````
{
"registrar":[
{
"language":"php",
"provider":"methods",
"signatures":[
{
"class": "Symfony\\Component\\Routing\\Annotation\\Route",
"type": "annotation_array",
"field": "methods"
}
]
}
],
"providers": [
{
"name": "methods",
"items":[
{
"lookup_string": "POST"
}
]
}
]
}
```